diff --git a/Cakefile b/Cakefile index bc20a894..e92bbea1 100644 --- a/Cakefile +++ b/Cakefile @@ -159,31 +159,7 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit """ - codeFor = -> - counter = 0 - hljs = require 'highlight.js' - hljs.configure classPrefix: '' - (file, executable = false, showLoad = true) -> - counter++ - cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' - js = CoffeeScript.compile cs, bare: yes - 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});".replace /"/g, '"' - 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}
" + codeFor = require "./documentation/v#{majorVersion}/code.coffee" htmlFor = -> marked = require 'marked' diff --git a/documentation/v1/code.coffee b/documentation/v1/code.coffee new file mode 100644 index 00000000..63225c91 --- /dev/null +++ b/documentation/v1/code.coffee @@ -0,0 +1,29 @@ +fs = require 'fs' +CoffeeScript = require '../../lib/coffee-script' + + +module.exports = -> + counter = 0 + hljs = require 'highlight.js' + hljs.configure classPrefix: '' + (file, executable = no, showLoad = yes) -> + counter++ + cs = fs.readFileSync "documentation/examples/#{file}.coffee", 'utf-8' + js = CoffeeScript.compile cs, bare: yes + 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});".replace /"/g, '"' + if executable and executable isnt yes + cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}" + run = if executable is yes 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}
"