From 63d3b699d7f28ba10e097e9dc3e8b57aca84b77a Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 7 Sep 2017 08:01:12 -0700 Subject: [PATCH] [CS2] Fix CS2 docs mobile issues, improve performance (#4688) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Get rid of offcanvas slide-in; fix sidebar * We need to transpile docs.coffee, since Safari 9 throws an error on it and that’s too new a browser not to support; but this should also speed things up * Fix some tabs * Fix scrollbar * Use Highlight.js to format placeholder code (during compilation, not rendering) before CodeMirror loads; match Highlight.js styles to CodeMirror styles as best we can * Improve hash management * Initialize CodeMirror on demand, on mouseover a particular code example, rather than all examples on startup * Replace highlight.js with Prism for placeholder syntax highlighting * Scratch Prism, use CodeMirror itself to do Node-based syntax highlighting, so that on CodeMirror initialization there’s no flash from mismatched highlighting * Update packages; there’s a new version of Jison! (doesn’t change much) * Fix mobile issues: use SVG play button icon, to avoid iOS blue square play button; make the code editor text 16px size explicit, to avoid unwanted mobile zoom; make the ‘code play’ buttons work even if the code examples are in placeholder (non-editable) mode, in case a user hasn’t moused over/tapped them * Update docs output * Whoops, CodeMirror is only a devDependency --- Cakefile | 51 +- docs/v2/index.html | 2031 ++++++++++++++++--- documentation/examples/comment.coffee | 2 +- documentation/examples/static.coffee | 16 +- documentation/images/logo.svg | 8 +- documentation/sections/changelog.md | 22 +- documentation/v2/body.html | 7 +- documentation/v2/code.coffee | 40 +- documentation/v2/{twilight.css => code.css} | 49 +- documentation/v2/code.html | 4 +- documentation/v2/docs.coffee | 41 +- documentation/v2/docs.css | 107 +- documentation/v2/play.svg | 3 + documentation/v2/scripts.html | 4 +- documentation/v2/sidebar.html | 2 +- documentation/v2/styles.html | 2 +- documentation/v2/try.html | 2 +- lib/coffeescript/parser.js | 12 +- package-lock.json | 51 +- package.json | 5 +- 20 files changed, 2000 insertions(+), 459 deletions(-) rename documentation/v2/{twilight.css => code.css} (57%) create mode 100644 documentation/v2/play.svg diff --git a/Cakefile b/Cakefile index a43239a5..f7145f21 100644 --- a/Cakefile +++ b/Cakefile @@ -66,6 +66,27 @@ build = (callback) -> buildParser() buildExceptParser callback +transpile = (code) -> + babel = require 'babel-core' + presets = [] + # Exclude the `modules` plugin in order to not break the `}(this));` + # at the end of the above code block. + presets.push ['env', {modules: no}] unless process.env.TRANSFORM is 'false' + babelOptions = + presets: presets + sourceType: 'script' + { code } = babel.transform code, babelOptions unless presets.length is 0 + # Running Babel twice due to https://github.com/babel/babili/issues/614. + # Once that issue is fixed, move the `babili` preset back up into the + # `presets` array and run Babel once with both presets together. + presets = if process.env.MINIFY is 'false' then [] else ['babili'] + babelOptions = + compact: process.env.MINIFY isnt 'false' + presets: presets + sourceType: 'script' + { code } = babel.transform code, babelOptions unless presets.length is 0 + code + testBuiltCode = (watch = no) -> csPath = './lib/coffeescript' csDir = path.dirname require.resolve csPath @@ -141,24 +162,7 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b } }(this)); """ - babel = require 'babel-core' - presets = [] - # Exclude the `modules` plugin in order to not break the `}(this));` - # at the end of the above code block. - presets.push ['env', {modules: no}] unless process.env.TRANSFORM is 'false' - babelOptions = - presets: presets - sourceType: 'script' - { code } = babel.transform code, babelOptions unless presets.length is 0 - # Running Babel twice due to https://github.com/babel/babili/issues/614. - # Once that issue is fixed, move the `babili` preset back up into the - # `presets` array and run Babel once with both presets together. - presets = if process.env.MINIFY is 'false' then [] else ['babili'] - babelOptions = - compact: process.env.MINIFY isnt 'false' - presets: presets - sourceType: 'script' - { code } = babel.transform code, babelOptions unless presets.length is 0 + code = transpile code outputFolder = "docs/v#{majorVersion}/browser-compiler" fs.mkdirSync outputFolder unless fs.existsSync outputFolder fs.writeFileSync "#{outputFolder}/coffeescript.js", header + '\n' + code @@ -236,9 +240,17 @@ buildDocs = (watch = no) -> codeFor: codeFor() releaseHeader: releaseHeader + includeScript = -> + (file) -> + file = "#{versionedSourceFolder}/#{file}" unless '/' in file + code = fs.readFileSync file, 'utf-8' + code = CoffeeScript.compile code + code = transpile code + code + include = -> (file) -> - file = "#{versionedSourceFolder}/#{file}" if file.indexOf('/') is -1 + file = "#{versionedSourceFolder}/#{file}" unless '/' in file output = fs.readFileSync file, 'utf-8' if /\.html$/.test(file) render = _.template output @@ -249,6 +261,7 @@ buildDocs = (watch = no) -> htmlFor: htmlFor() codeFor: codeFor() include: include() + includeScript: includeScript() output # Task diff --git a/docs/v2/index.html b/docs/v2/index.html index 397a7e15..c4ed852c 100644 --- a/docs/v2/index.html +++ b/docs/v2/index.html @@ -18,8 +18,6 @@ diff --git a/documentation/v2/try.html b/documentation/v2/try.html index aaa33d56..25eef132 100644 --- a/documentation/v2/try.html +++ b/documentation/v2/try.html @@ -9,7 +9,7 @@
-   +
diff --git a/lib/coffeescript/parser.js b/lib/coffeescript/parser.js index 20688b4d..4c5a4d68 100644 --- a/lib/coffeescript/parser.js +++ b/lib/coffeescript/parser.js @@ -1,4 +1,4 @@ -/* parser generated by jison 0.4.17 */ +/* parser generated by jison 0.4.18 */ /* Returns a Parser object of the following structure: @@ -906,13 +906,9 @@ parseError: function parseError(str, hash) { if (hash.recoverable) { this.trace(str); } else { - function _parseError (msg, hash) { - this.message = msg; - this.hash = hash; - } - _parseError.prototype = Error; - - throw new _parseError(str, hash); + var error = new Error(str); + error.hash = hash; + throw error; } }, parse: function parse(input) { diff --git a/package-lock.json b/package-lock.json index dc1acd15..7fad923d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,9 +17,9 @@ "dev": true }, "acorn": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.1.1.tgz", - "integrity": "sha512-vOk6uEMctu0vQrvuSqFdJyqj1Q0S5VTDL79qtjo+DhRr+1mmaD+tluFSCZqhvi/JUhXSzoZN2BhtstaPEeE8cw==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.1.2.tgz", + "integrity": "sha512-o96FZLJBPY1lvTuJylGA9Bk3t/GKPPJG8H0ydQQl01crzwJgspa4AEIq/pVTXigmK0PHVQhiAtn8WMBLL9D2WA==", "dev": true }, "acorn-dynamic-import": { @@ -1247,16 +1247,17 @@ "dev": true }, "browserify-aes": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.0.6.tgz", - "integrity": "sha1-Xncl297x/Vkw1OurSFZ85FHEigo=", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.0.8.tgz", + "integrity": "sha512-WYCMOT/PtGTlpOKFht0YJFYcPy6pLCR98CtWfzK13zoynLlBMvAdEMSRGmgnJCw2M2j/5qxBkinZQFobieM8dQ==", "dev": true, "requires": { "buffer-xor": "1.0.3", "cipher-base": "1.0.4", "create-hash": "1.1.3", - "evp_bytestokey": "1.0.2", - "inherits": "2.0.3" + "evp_bytestokey": "1.0.3", + "inherits": "2.0.3", + "safe-buffer": "5.1.1" } }, "browserify-cipher": { @@ -1265,9 +1266,9 @@ "integrity": "sha1-mYgkSHS/XtTijalWZtzWasj8Njo=", "dev": true, "requires": { - "browserify-aes": "1.0.6", + "browserify-aes": "1.0.8", "browserify-des": "1.0.0", - "evp_bytestokey": "1.0.2" + "evp_bytestokey": "1.0.3" } }, "browserify-des": { @@ -1448,6 +1449,12 @@ "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, + "codemirror": { + "version": "5.29.0", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.29.0.tgz", + "integrity": "sha512-nlG9m0YQ0gFhdEdnKDG+XJRB/bW+K6M9Axs01+LScjVamWtd4dEwgyohf/r4voW1efnGi6U6hHHvDQ9tt9BtoA==", + "dev": true + }, "colors": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/colors/-/colors-0.5.1.tgz", @@ -1891,9 +1898,9 @@ "dev": true }, "evp_bytestokey": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.2.tgz", - "integrity": "sha512-ni0r0lrm7AOzsh2qC5mi9sj8S0gmj5fLNjfFpxN05FB4tAVZEKotbkjOtLPqTCX/CXT7NsUr6juZb4IFJeNNdA==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", + "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", "dev": true, "requires": { "md5.js": "1.3.4", @@ -3338,9 +3345,9 @@ } }, "jison": { - "version": "0.4.17", - "resolved": "https://registry.npmjs.org/jison/-/jison-0.4.17.tgz", - "integrity": "sha1-vBLUbFhF5v7onM81vSqMxz66F/M=", + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/jison/-/jison-0.4.18.tgz", + "integrity": "sha512-FKkCiJvozgC7VTHhMJ00a0/IApSxhlGsFIshLW6trWJ8ONX2TQJBBz6DlcO1Gffy4w9LT+uL+PA+CVnUSJMF7w==", "dev": true, "requires": { "JSONSelect": "0.4.0", @@ -3892,9 +3899,9 @@ "dev": true, "requires": { "asn1.js": "4.9.1", - "browserify-aes": "1.0.6", + "browserify-aes": "1.0.8", "create-hash": "1.1.3", - "evp_bytestokey": "1.0.2", + "evp_bytestokey": "1.0.3", "pbkdf2": "3.0.13" } }, @@ -4654,12 +4661,12 @@ } }, "webpack": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-3.5.5.tgz", - "integrity": "sha512-qeUx4nIbeLL53qqNTs3kObPBMkUVDrOjEfp/hTvMlx21qL2MsGNr8/tXCoX/lS12dLl9qtZaXv2qfBEctPScDg==", + "version": "3.5.6", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-3.5.6.tgz", + "integrity": "sha512-sXnxfx6KoZVrFAGLjdhCCwDtDwkYMfwm8mJjkQv3thr5pjTlbxopVlr/kJwc9Bz317gL+gNjvz++ir9TgG1MDg==", "dev": true, "requires": { - "acorn": "5.1.1", + "acorn": "5.1.2", "acorn-dynamic-import": "2.0.2", "ajv": "5.2.2", "ajv-keywords": "2.1.0", diff --git a/package.json b/package.json index bad79dfd..70a1ab42 100644 --- a/package.json +++ b/package.json @@ -43,12 +43,13 @@ "babel-preset-babili": "~0.1.4", "babel-preset-env": "~1.6.0", "babili": "^0.1.4", + "codemirror": "^5.29.0", "docco": "~0.7.0", "highlight.js": "~9.12.0", - "jison": ">=0.4.17", + "jison": ">=0.4.18", "markdown-it": "~8.4.0", "underscore": "~1.8.3", - "webpack": "~3.5.5" + "webpack": "~3.5.6" }, "dependencies": {} }