From 59001f2fe3f2dfbae0e91f1c038ebe4587b7b0a4 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 12 Dec 2016 22:50:30 -0800 Subject: [PATCH] Move the `codeFor` function into versioned folders, so that v1 and v2 docs can have different example code blocks/editors --- Cakefile | 26 +------------------------- documentation/v1/code.coffee | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 documentation/v1/code.coffee diff --git a/Cakefile b/Cakefile index 88fc6748..a1bb0025 100644 --- a/Cakefile +++ b/Cakefile @@ -151,31 +151,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}
"