From a401f587c3c798236ee60477148604c122c7d97b Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Tue, 29 Nov 2016 08:39:00 -0800 Subject: [PATCH 01/10] Organize Cakefile: move helper functions that are only used by `doc:site` into the `doc:site` task --- Cakefile | 110 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/Cakefile b/Cakefile index 8f763d0c7d..dd2a6174a7 100644 --- a/Cakefile +++ b/Cakefile @@ -45,60 +45,6 @@ run = (args, cb) -> log = (message, color, explanation) -> console.log color + message + reset + ' ' + (explanation or '') -codeFor = -> - counter = 0 - hljs = require 'highlight.js' - hljs.configure classPrefix: '' - (file, executable = false, showLoad = true) -> - counter++ - return unless fs.existsSync "docs/v#{majorVersion}/examples/#{file}.js" - cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' - js = fs.readFileSync "docs/v#{majorVersion}/examples/#{file}.js", 'utf-8' - js = js.replace /^\/\/ generated.*?\n/i, '' - - cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" - # Temporary fix until highlight.js adds support for newer CoffeeScript keywords - # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release - if file in ['generator_iteration', 'generators', 'modules'] - cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 ' - jshtml = "
#{hljs.highlight('javascript', js).value}
" - append = if executable is yes then '' else "alert(#{executable});" - if executable and executable isnt yes - cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" - run = if executable is true then 'run' else "run: #{executable}" - name = "example#{counter}" - script = "" - load = if showLoad then "
load
" else '' - button = if executable then "
#{run}
" else '' - "
#{cshtml}#{jshtml}#{script}#{load}#{button}
" - -monthNames = [ - 'January' - 'February' - 'March' - 'April' - 'May' - 'June' - 'July' - 'August' - 'September' - 'October' - 'November' - 'December' -] - -formatDate = (date) -> - date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) -> - "#{monthNames[$2 - 1]} #{+$3}, #{$1}" - -releaseHeader = (date, version, prevVersion) -> """ -
- - #{prevVersion and "#{version}" or version} - - -""" - option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`' task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) -> @@ -182,6 +128,62 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser', task 'doc:site', 'watch and continually rebuild the documentation for the website', -> + # Helpers + codeFor = -> + counter = 0 + hljs = require 'highlight.js' + hljs.configure classPrefix: '' + (file, executable = false, showLoad = true) -> + counter++ + return unless fs.existsSync "docs/v#{majorVersion}/examples/#{file}.js" + cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' + js = fs.readFileSync "docs/v#{majorVersion}/examples/#{file}.js", 'utf-8' + js = js.replace /^\/\/ generated.*?\n/i, '' + + cshtml = "
#{hljs.highlight('coffeescript', cs).value}
" + # Temporary fix until highlight.js adds support for newer CoffeeScript keywords + # Added in https://github.com/isagalaev/highlight.js/pull/1357, awaiting release + if file in ['generator_iteration', 'generators', 'modules'] + cshtml = cshtml.replace /(yield|import|export|from|as|default) /g, '$1 ' + jshtml = "
#{hljs.highlight('javascript', js).value}
" + append = if executable is yes then '' else "alert(#{executable});" + if executable and executable isnt yes + cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" + run = if executable is true then 'run' else "run: #{executable}" + name = "example#{counter}" + script = "" + load = if showLoad then "
load
" else '' + button = if executable then "
#{run}
" else '' + "
#{cshtml}#{jshtml}#{script}#{load}#{button}
" + + monthNames = [ + 'January' + 'February' + 'March' + 'April' + 'May' + 'June' + 'July' + 'August' + 'September' + 'October' + 'November' + 'December' + ] + + formatDate = (date) -> + date.replace /^(\d\d\d\d)-(\d\d)-(\d\d)$/, (match, $1, $2, $3) -> + "#{monthNames[$2 - 1]} #{+$3}, #{$1}" + + releaseHeader = (date, version, prevVersion) -> """ +
+ + #{prevVersion and "#{version}" or version} + + + """ + + # Task examplesSourceFolder = 'documentation/examples' examplesOutputFolder = "docs/v#{majorVersion}/examples" fs.mkdirSync examplesOutputFolder unless fs.existsSync examplesOutputFolder From 6d290865194a2dc467b96a5ba23bfefd233b528d Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Tue, 29 Nov 2016 08:45:46 -0800 Subject: [PATCH 02/10] Standardize on .html file extension; move test.html into its new home --- Cakefile | 2 +- documentation/{index.html.js => index.html} | 0 {test => documentation}/test.html | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename documentation/{index.html.js => index.html} (100%) rename {test => documentation}/test.html (100%) diff --git a/Cakefile b/Cakefile index dd2a6174a7..42aedb392f 100644 --- a/Cakefile +++ b/Cakefile @@ -190,7 +190,7 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit do renderExamples = -> execSync "bin/coffee -bc -o #{examplesOutputFolder} #{examplesSourceFolder}/*.coffee" - indexFile = 'documentation/index.html.js' + indexFile = 'documentation/index.html' do renderIndex = -> render = _.template fs.readFileSync(indexFile, 'utf-8') output = render diff --git a/documentation/index.html.js b/documentation/index.html similarity index 100% rename from documentation/index.html.js rename to documentation/index.html diff --git a/test/test.html b/documentation/test.html similarity index 100% rename from test/test.html rename to documentation/test.html From 06b3180223d2184910f24f4de7726e85a9ecc732 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Tue, 29 Nov 2016 18:13:12 -0800 Subject: [PATCH 03/10] Refactor test.html to be part of the docs output, with the tests embedded inside it; update test.html styles; move UTF-8 comment test out of test.html and into test/comments.coffee where it belongs --- Cakefile | 29 +++++++ docs/current | 1 - documentation/test.html | 174 ++++++++++++++++++---------------------- test/comments.coffee | 56 +++++++------ 4 files changed, 138 insertions(+), 122 deletions(-) delete mode 120000 docs/current diff --git a/Cakefile b/Cakefile index 42aedb392f..9a644c13b2 100644 --- a/Cakefile +++ b/Cakefile @@ -183,6 +183,25 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit """ + testsInScriptBlocks = -> + output = '' + for filename in fs.readdirSync 'test' + if filename.indexOf('.coffee') isnt -1 + type = 'coffeescript' + else if filename.indexOf('.litcoffee') isnt -1 + type = 'literate-coffeescript' + else + continue + + # Set the type to text/x-coffeescript or text/x-literate-coffeescript + # to prevent the browser compiler from automatically running the script + output += """ + \n + """ + output + # Task examplesSourceFolder = 'documentation/examples' examplesOutputFolder = "docs/v#{majorVersion}/examples" @@ -200,10 +219,20 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit fs.writeFileSync "docs/v#{majorVersion}/index.html", output log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html" + testFile = 'documentation/test.html' + do renderTest = -> + render = _.template fs.readFileSync(testFile, 'utf-8') + output = render + tests: testsInScriptBlocks() + majorVersion: majorVersion + fs.writeFileSync "docs/v#{majorVersion}/test.html", output + log 'compiled', green, "#{testFile} → docs/v#{majorVersion}/test.html" + fs.watch examplesSourceFolder, interval: 200, -> renderExamples() renderIndex() fs.watch indexFile, interval: 200, renderIndex + fs.watch testFile, interval: 200, renderTest log 'watching...' , green diff --git a/docs/current b/docs/current deleted file mode 120000 index 28c218c44b..0000000000 --- a/docs/current +++ /dev/null @@ -1 +0,0 @@ -v1 \ No newline at end of file diff --git a/documentation/test.html b/documentation/test.html index 17b51cfa3e..e20dd3716c 100644 --- a/documentation/test.html +++ b/documentation/test.html @@ -3,119 +3,103 @@ CoffeeScript Test Suite - + -

CoffeeScript Test Suite

-

+

CoffeeScript Test Suite

+ +

+
+
+      ok yes
+    return
+  ok no
+
+
+# Run the tests
+for test in document.getElementsByClassName 'test'
+  say '\u2714 ' + test.id
+  try
+    CoffeeScript.run test.innerHTML
+  catch exception
+    console.error exception
+
+# Finish up
+yay = success is total and not failed
+sec = (new Date - start) / 1000
+msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
+msg = "failed #{ total - success } tests and #{msg}" unless yay
+say msg, yay
+
+
+<%= tests %>
 
 
 
diff --git a/test/comments.coffee b/test/comments.coffee
index 83b41774d6..563cd47524 100644
--- a/test/comments.coffee
+++ b/test/comments.coffee
@@ -293,25 +293,25 @@ test "#3132: Format jsdoc-style block-comment nicely", ->
   input = """
   ###*
   # Multiline for jsdoc-"@doctags"
-  # 
+  #
   # @type {Function}
   ###
   fn = () -> 1
   """
 
   result = """
-  
+
   /**
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
    */
   var fn;
-  
+
   fn = function() {
     return 1;
   };
-  
+
   """
   eq CoffeeScript.compile(input, bare: on), result
 
@@ -321,25 +321,25 @@ test "#3132: Format hand-made (raw) jsdoc-style block-comment nicely", ->
   input = """
   ###*
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
   ###
   fn = () -> 1
   """
 
   result = """
-  
+
   /**
    * Multiline for jsdoc-"@doctags"
-   * 
+   *
    * @type {Function}
    */
   var fn;
-  
+
   fn = function() {
     return 1;
   };
-  
+
   """
   eq CoffeeScript.compile(input, bare: on), result
 
@@ -349,54 +349,54 @@ test "#3132: Place block-comments nicely", ->
   input = """
   ###*
   # A dummy class definition
-  # 
+  #
   # @class
   ###
   class DummyClass
-    
+
     ###*
     # @constructor
     ###
     constructor: ->
-  
+
     ###*
     # Singleton reference
-    # 
+    #
     # @type {DummyClass}
     ###
     @instance = new DummyClass()
-  
+
   """
 
   result = """
-  
+
   /**
    * A dummy class definition
-   * 
+   *
    * @class
    */
   var DummyClass;
-  
+
   DummyClass = (function() {
-  
+
     /**
      * @constructor
      */
     function DummyClass() {}
-  
-  
+
+
     /**
      * Singleton reference
-     * 
+     *
      * @type {DummyClass}
      */
-  
+
     DummyClass.instance = new DummyClass();
-  
+
     return DummyClass;
-  
+
   })();
-  
+
   """
   eq CoffeeScript.compile(input, bare: on), result
 
@@ -427,3 +427,7 @@ test "#3761: Multiline comment at end of an object", ->
     ###
 
   ok anObject.x is 3
+
+test "#4375: UTF-8 characters in comments", ->
+  # 智に働けば角が立つ、情に掉させば流される。
+  ok yes

From 8c8ebf874a5f67dd18d48120eedc2b1cd2c1e0db Mon Sep 17 00:00:00 2001
From: Geoffrey Booth 
Date: Tue, 29 Nov 2016 18:27:34 -0800
Subject: [PATCH 04/10] Add test description to error message

---
 documentation/test.html | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/documentation/test.html b/documentation/test.html
index e20dd3716c..cbd9e62698 100644
--- a/documentation/test.html
+++ b/documentation/test.html
@@ -33,6 +33,7 @@ 

CoffeeScript Test Suite

<%= tests %> From 1ea753d19f0f3fefe8b48022f172ba8a85c58d80 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Tue, 29 Nov 2016 22:20:38 -0800 Subject: [PATCH 08/10] =?UTF-8?q?Polyfill=20missing=20helper=20functions?= =?UTF-8?q?=20from=20Node=E2=80=99s=20assert,=20one=20with=20CDN-hosted=20?= =?UTF-8?q?Underscore;=20handle=20.litcoffee=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- documentation/test.html | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/documentation/test.html b/documentation/test.html index b6cf07df64..f1f3d5e672 100644 --- a/documentation/test.html +++ b/documentation/test.html @@ -4,6 +4,7 @@ CoffeeScript Test Suite +