Skip to content

Commit 49c4aa3

Browse files
author
David Brady
committed
Added output hashrocket style guide and 'no stealing copyrighted stuff' to the author's guide
1 parent 702ce6f commit 49c4aa3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

authors-guide.textile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ h2. tl;dr: Look at Other Recipes, and Blend In
99

1010
Look at the source of other recipe pages and follow that page structure. Start with the <a href="/developers-guide">Developer's Guide</a> to get a test version of the cookbook up and running on your machine, and get to work!
1111

12+
1213
h2. General Guidelines
1314

1415
* Feel free to add new pages, or even chapters. Just keep them organized. _(See "How to Add a Chapter" below)_
@@ -25,6 +26,14 @@ A typical cookbook page will have three sections (four if you count the title):
2526
* +Solution+ State the solution as briefly as possible, ideally as a single sentence that identifies the strategy you would use, and give example code. It's tempting to explain the solution, but don't do it yet. Remember that the reader will look this solution up many times after the first time, and that they will be looking for a quick reference each time. You're going to explain the solution in the +Discussion+, and the first time reader will read your solution, think about it, and then proceed to the discussion if necessary. For example, for "accessing parts of a string", a good Solution sentence might be "Use CoffeeScript's array range subscripts, or JavaScript's slice function."
2627
* +Discussion+ Here you should explain why your solution works, or give further examples such as edge cases. If your solution can break on some edge cases, be sure to note them here. For example, if a percentage function crashes when given a zero, you could note this in the discussion and give a workaround. NOTE: If your solution has really dangerous edge cases, so dangerous that you would include them in the solution, please consider whether your recipe should be included at all. Remember, this Cookbook is for good code!
2728

29+
30+
h2. Copyright Issues
31+
32+
Do not post code that is copyrighted by another user, unless you have permission to use that code AND to relicense that code under the <a href="/license">CC BY 3.0</a> license. If you DO have permission and the author would like credit, please add them to the <a href="/authors">authors</a> page.
33+
34+
Also, just a stylistic note, please do not yank code directly from http://coffeescript.org and post it with little or no discussion. The CoffeeScript Cookbook is not affiliated with them. We think they're awesome and want them to like us, too! Make sure that anything taken from coffeescript.org is permissible use and that it stands alone as a valid recipe. If the recipe is too terse, consider adding more examples and discussion.
35+
36+
2837
h2. Tag the page with Jekyll frontmatter
2938

3039
...that's a lot of fancy words that mean "don't forget to put the layout, chapter and page title at the top of the file in a YAML block". For example, the string interpolation page begins with
@@ -35,6 +44,7 @@ title: String Interpolation
3544
chapter: Strings
3645
---</tt>
3746

47+
3848
h2. Use Liquid highlighting templates
3949

4050
Turn on syntax highlighting for CoffeeScript with <tt>highlight coffeescript</tt>.
@@ -58,6 +68,36 @@ square(16)
5868
{% endhighlight %}
5969

6070

71+
h2. Include Output
72+
73+
After writing an important expression, show the reader what the output would be by adding it with a <tt># =></tt> on the following line. Once we get automated script testing working up in this joint, we'll actually load up your recipe snippets and evaluate its expressions against the output comment you wrote. (In other words, <tt># =></tt> tells the reader what the output will be, but it tells automated checker what the assertEquals should be)
74+
75+
{% highlight coffeescript %}
76+
# right
77+
[1,2,3].map (x) -> x * 2
78+
# => [ 2, 4, 6 ]
79+
80+
# very wrong!
81+
[1,2,3].map (x) -> x * 2
82+
83+
# right; only add for important/results statements
84+
evens = x for x in [0..10] by 2
85+
evens.some (x) -> x == 6
86+
# => true
87+
88+
# less wrong; may require tweaking the automatic checker
89+
[1,2,3].map (x) -> x * 2 # => [ 2, 4, 6 ]
90+
91+
# less wrong (possibly not wrong at all--the output merely does not match what the coffee interpreter renders)
92+
[1,2,3].map (x) -> x * 2
93+
# => [2,4,6]
94+
{% endhighlight %}
95+
96+
Not all snippets evaluate to something useful. For example, array.forEach has side effects but does not return anything. Also, the console.log() and alert() commands are also side-effect-only commands that return nothing. When possible, try to have your snippets evaluate to something inspectable, and leave displaying to the console or browser out of it. (Unless your snippet is _about_ displaying to the console or browser.)
97+
98+
When in doubt about what output to show, try evaluating your snippet in the coffee interpreter and see what IT thinks. Ideally your output should match, or at least be machine-comparable.
99+
100+
61101
h1. Grindy HOWTOs
62102

63103
h2. How to Add a Recipe
@@ -86,6 +126,7 @@ Here's why.
86126

87127
One fussy little bit, the chapter name should match the directory the chapter is in, otherwise the page won't render correctly. For example, if you're writing a recipe for arrays, make sure the chapter is "Arrays", not "arrays" or "aray" ...or especially not "Chapter Name".
88128

129+
89130
h2. How to Add a Chapter
90131

91132
* Open chapters/index.textile and your chapter's name to the yaml list of chapters.
@@ -111,8 +152,10 @@ mkdir dates_and_times
111152

112153
Now create a new page in that chapter (remember to add its YAML front matter) and once jekyll regenerates the chapter index, your new page should appear.
113154

155+
114156
h1. FAQ
115157

158+
116159
h2. I Have a Weird Recipe. Should I Share It?
117160

118161
Maybe! The real question is, is it really useful, or is it just clever? If you have a formatter for a weird Albanian GIS format, that's a real problem that almost nobody would ever have&mdash;but when somebody DOES have that problem, they REALLY need a solution. If you have a bit shifting trick that can swap two numbers using three xor-equals operations, that's a really clever solution but it's not very good CoffeeScript. (For one thing, <tt>x ^= y ^= x ^= y</tt> is not idiomatic, while <tt>[x,y]=[y,x]</tt> is. For another, there's a bug in that code. And once you fix it, there's another bug caused by extrapolating this register trick to a reference-based language where&mdash;look, it's just a bad idea, okay?)
@@ -134,10 +177,12 @@ h2. Can I Edit An Existing Recipe?
134177

135178
Yes. Please improve anything and everything! Be sure to test your changes and make sure that your solution really is better.
136179

180+
137181
h2. I Have a Really Efficient Solution, But It's Not As Readable As the Existing Recipe. Should I Add It?
138182

139183
See the "Weird Recipe" note above. Do real people in the real world ever hit the performance constraint? If so, then by all means, add your strategy to the existing solution, and be sure to explain why your solution is not idiomatic. If a reader really has that problem, they'll be glad for the extra options.
140184

185+
141186
h2. I Have A Problem/Solution, But It's Basically Just JavaScript. Should I Add It?
142187

143188
Yes! CoffeeScript compiles to JavaScript, and that means that some of its functionality comes straight from JavaScript. (For example, see <a href="/chapters/arrays/reversing-arrays">Reversing Arrays</a>.) But if you're programming in CoffeeScript and you need to reverse an array, this Cookbook should stand ready to tell you it's available to you in CoffeeScript&mdash;even if it's just a straight call into a JavaScript library.

0 commit comments

Comments
 (0)