@@ -45,60 +45,6 @@ run = (args, cb) ->
45
45
log = (message , color , explanation ) ->
46
46
console .log color + message + reset + ' ' + (explanation or ' ' )
47
47
48
- codeFor = ->
49
- counter = 0
50
- hljs = require ' highlight.js'
51
- hljs .configure classPrefix : ' '
52
- (file , executable = false , showLoad = true ) ->
53
- counter++
54
- return unless fs .existsSync " docs/v#{ majorVersion} /examples/#{ file} .js"
55
- cs = fs .readFileSync " documentation/examples/#{ file} .coffee" , ' utf-8'
56
- js = fs .readFileSync " docs/v#{ majorVersion} /examples/#{ file} .js" , ' utf-8'
57
- js = js .replace / ^ \/\/ generated. *? \n / i , ' '
58
-
59
- cshtml = " <pre><code>#{ hljs .highlight (' coffeescript' , cs).value } </code></pre>"
60
- # Temporary fix until highlight.js adds support for newer CoffeeScript keywords
61
- # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release
62
- if file in [' generator_iteration' , ' generators' , ' modules' ]
63
- cshtml = cshtml .replace / (yield| import| export| from| as| default) / g , ' <span class="keyword">$1</span> '
64
- jshtml = " <pre><code>#{ hljs .highlight (' javascript' , js).value } </code></pre>"
65
- append = if executable is yes then ' ' else " alert(#{ executable} );"
66
- if executable and executable isnt yes
67
- cs .replace / (\S )\s * \Z / m , " $1\n\n alert #{ executable} "
68
- run = if executable is true then ' run' else " run: #{ executable} "
69
- name = " example#{ counter} "
70
- script = " <script>window.#{ name} = #{ JSON .stringify cs} </script>"
71
- load = if showLoad then " <div class='minibutton load' onclick='javascript: loadConsole(#{ name} );'>load</div>" else ' '
72
- button = if executable then " <div class='minibutton ok' onclick='javascript: #{ js} ;#{ append} '>#{ run} </div>" else ' '
73
- " <div class='code'>#{ cshtml}#{ jshtml}#{ script}#{ load}#{ button} <br class='clear' /></div>"
74
-
75
- monthNames = [
76
- ' January'
77
- ' February'
78
- ' March'
79
- ' April'
80
- ' May'
81
- ' June'
82
- ' July'
83
- ' August'
84
- ' September'
85
- ' October'
86
- ' November'
87
- ' December'
88
- ]
89
-
90
- formatDate = (date ) ->
91
- date .replace / ^ (\d\d\d\d )-(\d\d )-(\d\d )$ / , (match , $1 , $2 , $3 ) ->
92
- " #{ monthNames[$2 - 1 ]} #{ + $3} , #{ $1} "
93
-
94
- releaseHeader = (date , version , prevVersion ) -> """
95
- <div class="anchor" id="#{ version} "></div>
96
- <b class="header">
97
- #{ prevVersion and " <a href=\" https://github.com/jashkenas/coffeescript/compare/#{ prevVersion} ...#{ version} \" >#{ version} </a>" or version}
98
- <span class="timestamp"> — <time datetime="#{ date} ">#{ formatDate date} </time></span>
99
- </b>
100
- """
101
-
102
48
option ' -p' , ' --prefix [DIR]' , ' set the installation prefix for `cake install`'
103
49
104
50
task ' install' , ' install CoffeeScript into /usr/local (or --prefix)' , (options ) ->
@@ -137,7 +83,7 @@ task 'build:full', 'rebuild the source twice, and run the tests', ->
137
83
138
84
139
85
task ' build:parser' , ' rebuild the Jison parser (run build first)' , ->
140
- helpers .extend global , require ( ' util' )
86
+ helpers .extend global , require ' util'
141
87
require ' jison'
142
88
parser = require (' ./lib/coffee-script/grammar' ).parser
143
89
fs .writeFileSync ' lib/coffee-script/parser.js' , parser .generate ()
@@ -182,13 +128,93 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
182
128
183
129
184
130
task ' doc:site' , ' watch and continually rebuild the documentation for the website' , ->
131
+ # Helpers
132
+ codeFor = ->
133
+ counter = 0
134
+ hljs = require ' highlight.js'
135
+ hljs .configure classPrefix : ' '
136
+ (file , executable = false , showLoad = true ) ->
137
+ counter++
138
+ return unless fs .existsSync " docs/v#{ majorVersion} /examples/#{ file} .js"
139
+ cs = fs .readFileSync " documentation/examples/#{ file} .coffee" , ' utf-8'
140
+ js = fs .readFileSync " docs/v#{ majorVersion} /examples/#{ file} .js" , ' utf-8'
141
+ js = js .replace / ^ \/\/ generated. *? \n / i , ' '
142
+
143
+ cshtml = " <pre><code>#{ hljs .highlight (' coffeescript' , cs).value } </code></pre>"
144
+ # Temporary fix until highlight.js adds support for newer CoffeeScript keywords
145
+ # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release
146
+ if file in [' generator_iteration' , ' generators' , ' modules' ]
147
+ cshtml = cshtml .replace / (yield| import| export| from| as| default) / g , ' <span class="keyword">$1</span> '
148
+ jshtml = " <pre><code>#{ hljs .highlight (' javascript' , js).value } </code></pre>"
149
+ append = if executable is yes then ' ' else " alert(#{ executable} );"
150
+ if executable and executable isnt yes
151
+ cs .replace / (\S )\s * \Z / m , " $1\n\n alert #{ executable} "
152
+ run = if executable is true then ' run' else " run: #{ executable} "
153
+ name = " example#{ counter} "
154
+ script = " <script>window.#{ name} = #{ JSON .stringify cs} </script>"
155
+ load = if showLoad then " <div class='minibutton load' onclick='javascript: loadConsole(#{ name} );'>load</div>" else ' '
156
+ button = if executable then " <div class='minibutton ok' onclick='javascript: #{ js} ;#{ append} '>#{ run} </div>" else ' '
157
+ " <div class='code'>#{ cshtml}#{ jshtml}#{ script}#{ load}#{ button} <br class='clear' /></div>"
158
+
159
+ monthNames = [
160
+ ' January'
161
+ ' February'
162
+ ' March'
163
+ ' April'
164
+ ' May'
165
+ ' June'
166
+ ' July'
167
+ ' August'
168
+ ' September'
169
+ ' October'
170
+ ' November'
171
+ ' December'
172
+ ]
173
+
174
+ formatDate = (date ) ->
175
+ date .replace / ^ (\d\d\d\d )-(\d\d )-(\d\d )$ / , (match , $1 , $2 , $3 ) ->
176
+ " #{ monthNames[$2 - 1 ]} #{ + $3} , #{ $1} "
177
+
178
+ releaseHeader = (date , version , prevVersion ) -> """
179
+ <div class="anchor" id="#{ version} "></div>
180
+ <b class="header">
181
+ #{ prevVersion and " <a href=\" https://github.com/jashkenas/coffeescript/compare/#{ prevVersion} ...#{ version} \" >#{ version} </a>" or version}
182
+ <span class="timestamp"> — <time datetime="#{ date} ">#{ formatDate date} </time></span>
183
+ </b>
184
+ """
185
+
186
+ testHelpers = fs .readFileSync (' test/support/helpers.coffee' , ' utf-8' ).replace / exports\. / g , ' @'
187
+
188
+ testsInScriptBlocks = ->
189
+ output = ' '
190
+ excludedTestFiles = [' error_messages.coffee' ]
191
+ for filename in fs .readdirSync ' test'
192
+ continue if filename in excludedTestFiles
193
+
194
+ if filename .indexOf (' .coffee' ) isnt - 1
195
+ type = ' coffeescript'
196
+ else if filename .indexOf (' .litcoffee' ) isnt - 1
197
+ type = ' literate-coffeescript'
198
+ else
199
+ continue
200
+
201
+ # Set the type to text/x-coffeescript or text/x-literate-coffeescript
202
+ # to prevent the browser compiler from automatically running the script
203
+ output += """
204
+ <script type="text/x-#{ type} " class="test" id="#{ filename .split (' .' )[0 ]} ">
205
+ #{ fs .readFileSync " test/#{ filename} " , ' utf-8' }
206
+ </script>\n
207
+ """
208
+ output
209
+
210
+ # Task
185
211
examplesSourceFolder = ' documentation/examples'
186
212
examplesOutputFolder = " docs/v#{ majorVersion} /examples"
187
213
fs .mkdirSync examplesOutputFolder unless fs .existsSync examplesOutputFolder
188
214
do renderExamples = ->
189
215
execSync " bin/coffee -bc -o #{ examplesOutputFolder} #{ examplesSourceFolder} /*.coffee"
190
216
191
- indexFile = ' documentation/index.html.js '
217
+ indexFile = ' documentation/index.html'
192
218
do renderIndex = ->
193
219
render = _ .template fs .readFileSync (indexFile, ' utf-8' )
194
220
output = render
@@ -198,10 +224,22 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
198
224
fs .writeFileSync " docs/v#{ majorVersion} /index.html" , output
199
225
log ' compiled' , green, " #{ indexFile} → docs/v#{ majorVersion} /index.html"
200
226
227
+ testFile = ' documentation/test.html'
228
+ do renderTest = ->
229
+ render = _ .template fs .readFileSync (testFile, ' utf-8' )
230
+ output = render
231
+ testHelpers : testHelpers
232
+ tests : testsInScriptBlocks ()
233
+ majorVersion : majorVersion
234
+ fs .writeFileSync " docs/v#{ majorVersion} /test.html" , output
235
+ log ' compiled' , green, " #{ testFile} → docs/v#{ majorVersion} /test.html"
236
+
201
237
fs .watch examplesSourceFolder, interval : 200 , ->
202
238
renderExamples ()
203
239
renderIndex ()
204
240
fs .watch indexFile, interval : 200 , renderIndex
241
+ fs .watch testFile, interval : 200 , renderTest
242
+ fs .watch ' test' , interval : 200 , renderTest
205
243
log ' watching...' , green
206
244
207
245
@@ -258,23 +296,7 @@ runTests = (CoffeeScript) ->
258
296
description : description if description?
259
297
source : fn .toString () if fn .toString ?
260
298
261
- # See http://wiki.ecmascript.org/doku.php?id=harmony:egal
262
- egal = (a , b ) ->
263
- if a is b
264
- a isnt 0 or 1 / a is 1 / b
265
- else
266
- a isnt a and b isnt b
267
-
268
- # A recursive functional equivalence helper; uses egal for testing equivalence.
269
- arrayEgal = (a , b ) ->
270
- if egal a, b then yes
271
- else if a instanceof Array and b instanceof Array
272
- return no unless a .length is b .length
273
- return no for el, idx in a when not arrayEgal el, b[idx]
274
- yes
275
-
276
- global .eq = (a , b , msg ) -> ok egal (a, b), msg ? " Expected #{ a} to equal #{ b} "
277
- global .arrayEq = (a , b , msg ) -> ok arrayEgal (a,b), msg ? " Expected #{ a} to deep equal #{ b} "
299
+ helpers .extend global , require ' ./test/support/helpers'
278
300
279
301
# When all the tests have run, collect and print errors.
280
302
# If a stacktrace is available, output the compiled function source.
0 commit comments