Split apart index.html into components that Cakefile assembles, so that we can add in logic to include different files for v1 versus v2

This commit is contained in:
Geoffrey Booth
2016-12-10 18:53:58 -08:00
parent 9eb7c63158
commit 6a845aa4f6
6 changed files with 269 additions and 258 deletions

View File

@@ -25,7 +25,7 @@ header = """
"""
# Used in folder names like docs/v1
majorVersion = CoffeeScript.VERSION.split('.')[0]
majorVersion = parseInt CoffeeScript.VERSION.split('.')[0], 10
# Build the CoffeeScript language from source.
build = (cb) ->
@@ -128,12 +128,37 @@ 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
css = fs.readFileSync('documentation/css/docs.css', 'utf-8') + '\n' +
fs.readFileSync('documentation/css/tomorrow.css', 'utf-8')
# Constants
indexFile = 'documentation/index.html'
bodyFile = "documentation/v#{majorVersion}/body.html"
testFile = 'documentation/test.html'
sectionsSourceFolder = 'documentation/sections'
examplesSourceFolder = 'documentation/examples'
testsSourceFolder = 'test'
outputFolder = "docs/v#{majorVersion}"
monthNames = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
jQueryVersion = if majorVersion is 1 then '1.12.4' else '3.1.1'
# Included in index.html
logo = fs.readFileSync 'documentation/images/logo.svg', 'utf-8'
if majorVersion is 1
css = """
<style>
#{fs.readFileSync('documentation/v1/docs.css', 'utf-8')}
#{fs.readFileSync('documentation/v1/tomorrow.css', 'utf-8')}
</style>
"""
else
css = '' # TODO
docsScript = fs.readFileSync "documentation/v#{majorVersion}/docs.coffee", 'utf-8'
# Included in test.html
testHelpers = fs.readFileSync('test/support/helpers.coffee', 'utf-8').replace /exports\./g, '@'
# Helpers
codeFor = ->
counter = 0
hljs = require 'highlight.js'
@@ -160,21 +185,6 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
button = if executable then """<div class="minibutton ok" onclick="javascript: #{js.replace /"/g, '&quot;'};#{append}">#{run}</div>""" else ''
"<div class='code'>#{cshtml}#{jshtml}#{script}#{load}#{button}<br class='clear' /></div>"
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}"
@@ -187,7 +197,6 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
</h2>
"""
sectionsSourceFolder = 'documentation/sections'
htmlFor = ->
marked = require 'marked'
markdownRenderer = new marked.Renderer()
@@ -208,7 +217,15 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
releaseHeader: releaseHeader
"<span class=\"bookmark\" id=\"#{if bookmark? then bookmark else file.replace(/_/g, '-')}\"></span>\n\n#{html}"
testHelpers = fs.readFileSync('test/support/helpers.coffee', 'utf-8').replace /exports\./g, '@'
body = ->
render = _.template fs.readFileSync(bodyFile, 'utf-8')
output = render
logo: logo
releaseHeader: releaseHeader
majorVersion: majorVersion
fullVersion: CoffeeScript.VERSION
htmlFor: htmlFor()
codeFor: codeFor()
testsInScriptBlocks = ->
output = ''
@@ -233,38 +250,33 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
output
# Task
indexFile = 'documentation/index.html'
do renderIndex = ->
render = _.template fs.readFileSync(indexFile, 'utf-8')
output = render
css: css
logo: logo
htmlFor: htmlFor()
codeFor: codeFor()
releaseHeader: releaseHeader
body: body()
script: docsScript
jQueryVersion: jQueryVersion
majorVersion: majorVersion
fullVersion: CoffeeScript.VERSION
fs.writeFileSync "docs/v#{majorVersion}/index.html", output
log 'compiled', green, "#{indexFile} → docs/v#{majorVersion}/index.html"
fs.writeFileSync "#{outputFolder}/index.html", output
log 'compiled', green, "#{indexFile} → #{outputFolder}/index.html"
try
fs.symlinkSync "v#{majorVersion}/index.html", 'docs/index.html'
catch exception
testFile = 'documentation/test.html'
do renderTest = ->
render = _.template fs.readFileSync(testFile, 'utf-8')
output = render
testHelpers: testHelpers
tests: testsInScriptBlocks()
majorVersion: majorVersion
fs.writeFileSync "docs/v#{majorVersion}/test.html", output
log 'compiled', green, "#{testFile} → docs/v#{majorVersion}/test.html"
fs.writeFileSync "#{outputFolder}/test.html", output
log 'compiled', green, "#{testFile} → #{outputFolder}/test.html"
fs.watch 'documentation/examples', interval: 200, renderIndex
fs.watch sectionsSourceFolder, interval: 200, renderIndex
fs.watch indexFile, interval: 200, renderIndex
fs.watch testFile, interval: 200, renderTest
fs.watch 'test', interval: 200, renderTest
for target in [indexFile, examplesSourceFolder, sectionsSourceFolder]
fs.watch target, interval: 200, renderIndex
for target in [testFile, testsSourceFolder]
fs.watch target, interval: 200, renderTest
log 'watching...' , green

View File

@@ -13,231 +13,18 @@
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="theme-color" content="#ffffff">
<style>
<%= css %>
</style>
</head>
<body>
<div id="fadeout"></div>
<%= body %>
<div id="flybar">
<a id="logo" href="#top"><%= logo %></a>
<div class="navigation toc">
<div class="button">
Table of Contents
</div>
<div class="contents menu">
<a href="#overview">Overview</a>
<a href="#installation">Installation</a>
<a href="#usage">Usage</a>
<a href="#literate">Literate CoffeeScript</a>
<a href="#language">Language Reference</a>
<a href="#literals">Literals: Functions, Objects and Arrays</a>
<a href="#lexical-scope">Lexical Scoping and Variable Safety</a>
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
<a href="#splats">Splats…</a>
<a href="#loops">Loops and Comprehensions</a>
<a href="#slices">Array Slicing and Splicing</a>
<a href="#expressions">Everything is an Expression</a>
<a href="#operators">Operators and Aliases</a>
<a href="#existential-operator">Existential Operator</a>
<a href="#classes">Classes, Inheritance, and Super</a>
<a href="#destructuring">Destructuring Assignment</a>
<a href="#fat-arrow">Bound and Generator Functions</a>
<a href="#embedded">Embedded JavaScript</a>
<a href="#switch">Switch and Try/Catch</a>
<a href="#comparisons">Chained Comparisons</a>
<a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
<a href="#tagged-template-literals">Tagged Template Literals</a>
<a href="#regexes">Block Regular Expressions</a>
<a href="#modules">Modules</a>
<a href="#cake">Cake, and Cakefiles</a>
<a href="#source-maps">Source Maps</a>
<a href="#scripts">"text/coffeescript" Script Tags</a>
<a href="#resources">Books, Screencasts, Examples and Resources</a>
<a href="#changelog">Change Log</a>
</div>
</div>
<div class="navigation try">
<div class="button">
Try CoffeeScript
<div class="repl_bridge"></div>
</div>
<div class="contents repl_wrapper">
<div class="code">
<div class="screenshadow tl"></div>
<div class="screenshadow tr"></div>
<div class="screenshadow bl"></div>
<div class="screenshadow br"></div>
<div id="repl_source_wrap">
<textarea id="repl_source" rows="100" spellcheck="false">alert "Hello CoffeeScript!"</textarea>
</div>
<div id="repl_results_wrap"><pre id="repl_results"></pre></div>
<div class="minibutton dark run" title="Ctrl-Enter">Run</div>
<a class="minibutton permalink" id="repl_permalink">Link</a>
<br class="clear" />
</div>
</div>
</div>
<div class="navigation annotated">
<div class="button">
Annotated Source
</div>
<div class="contents menu">
<a href="v<%= majorVersion %>/annotated-source/grammar.html">Grammar Rules — src/grammar</a>
<a href="v<%= majorVersion %>/annotated-source/lexer.html">Lexing Tokens — src/lexer</a>
<a href="v<%= majorVersion %>/annotated-source/rewriter.html">The Rewriter — src/rewriter</a>
<a href="v<%= majorVersion %>/annotated-source/nodes.html">The Syntax Tree — src/nodes</a>
<a href="v<%= majorVersion %>/annotated-source/scope.html">Lexical Scope — src/scope</a>
<a href="v<%= majorVersion %>/annotated-source/helpers.html">Helpers &amp; Utility Functions — src/helpers</a>
<a href="v<%= majorVersion %>/annotated-source/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
<a href="v<%= majorVersion %>/annotated-source/cake.html">Cake &amp; Cakefiles — src/cake</a>
<a href="v<%= majorVersion %>/annotated-source/command.html">“coffee” Command-Line Utility — src/command</a>
<a href="v<%= majorVersion %>/annotated-source/optparse.html">Option Parsing — src/optparse</a>
<a href="v<%= majorVersion %>/annotated-source/repl.html">Interactive REPL — src/repl</a>
<a href="v<%= majorVersion %>/annotated-source/sourcemap.html">Source Maps — src/sourcemap</a>
</div>
</div>
</div>
<script type="text/coffeescript">
<%= script %>
</script>
<div class="container">
<%= htmlFor('introduction', 'top') %>
<%= htmlFor('overview') %>
<%= htmlFor('installation') %>
<%= htmlFor('usage') %>
<%= htmlFor('literate') %>
<%= htmlFor('language') %>
<%= htmlFor('functions', 'literals') %>
<%= htmlFor('objects_and_arrays') %>
<%= htmlFor('lexical_scope') %>
<%= htmlFor('conditionals') %>
<%= htmlFor('splats') %>
<%= htmlFor('loops') %>
<%= htmlFor('slices') %>
<%= htmlFor('expressions') %>
<%= htmlFor('operators') %>
<%= htmlFor('existential_operator') %>
<%= htmlFor('classes') %>
<%= htmlFor('destructuring') %>
<%= htmlFor('fat_arrow') %>
<%= htmlFor('embedded') %>
<%= htmlFor('switch') %>
<%= htmlFor('try') %>
<%= htmlFor('comparisons') %>
<%= htmlFor('strings') %>
<%= htmlFor('tagged_template_literals') %>
<%= htmlFor('heregexes', 'regexes') %>
<%= htmlFor('modules') %>
<%= htmlFor('cake') %>
<%= htmlFor('source_maps') %>
<%= htmlFor('scripts') %>
<%= htmlFor('books', 'resources') %>
<%= htmlFor('screencasts') %>
<%= htmlFor('examples') %>
<%= htmlFor('resources', 'additional-resources') %>
<%= htmlFor('chat') %>
<%= htmlFor('changelog') %>
</div>
<script type="text/coffeescript">
sourceFragment = "try:"
# Set up the compilation function, to run when you stop typing.
compileSource = ->
source = $('#repl_source').val()
results = $('#repl_results')
window.compiledJS = ''
try
window.compiledJS = CoffeeScript.compile source, bare: on
el = results[0]
if el.innerText
el.innerText = window.compiledJS
else
results.text(window.compiledJS)
results.removeClass 'error'
$('.minibutton.run').removeClass 'error'
catch {location, message}
if location?
message = "Error on line #{location.first_line + 1}: #{message}"
results.text(message).addClass 'error'
$('.minibutton.run').addClass 'error'
# Update permalink
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compileSource()
# Use tab key to insert tabs
$('#repl_source').keydown (e) ->
if e.keyCode is 9
e.preventDefault()
textbox = e.target
# Insert tab character at caret or in selection
textbox.value = textbox.value[0...textbox.selectionStart] + "\t" + textbox.value[textbox.selectionEnd...]
# Put caret in correct position
textbox.selectionEnd = ++textbox.selectionStart
# Eval the compiled js.
evalJS = ->
try
eval window.compiledJS
catch error then alert error
# Load the console with a string of CoffeeScript.
window.loadConsole = (coffee) ->
$('#repl_source').val coffee
compileSource()
$('.navigation.try').addClass('active')
false
# Helper to hide the menus.
closeMenus = ->
$('.navigation.active').removeClass 'active'
$('.minibutton.run').click -> evalJS()
# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
return false if $(e.target).closest('.repl_wrapper').length
if $(this).hasClass('active')
closeMenus()
else
closeMenus()
$(this).addClass 'active'
false
# Dismiss console if Escape pressed or click falls outside console
# Trigger Run button on Ctrl-Enter
$(document.body)
.keydown (e) ->
closeMenus() if e.which == 27
evalJS() if e.which == 13 and (e.metaKey or e.ctrlKey) and $('.minibutton.run:visible').length
.click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()
$('#open_webchat').click ->
$(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
$("#repl_permalink").click (e) ->
window.location = $(this).attr("href")
false
# If source code is included in location.hash, display it.
hash = decodeURIComponent location.hash.replace(/^#/, '')
if hash.indexOf(sourceFragment) == 0
src = hash.substr sourceFragment.length
loadConsole src
compileSource()
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="v<%= majorVersion %>/browser-compiler/coffee-script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/<%= jQueryVersion %>/jquery.min.js"></script>
<script src="v<%= majorVersion %>/browser-compiler/coffee-script.js"></script>
</body>
</html>

120
documentation/v1/body.html Normal file
View File

@@ -0,0 +1,120 @@
<div id="fadeout"></div>
<div id="flybar">
<a id="logo" href="#top"><%= logo %></a>
<div class="navigation toc">
<div class="button">
Table of Contents
</div>
<div class="contents menu">
<a href="#overview">Overview</a>
<a href="#installation">Installation</a>
<a href="#usage">Usage</a>
<a href="#literate">Literate CoffeeScript</a>
<a href="#language">Language Reference</a>
<a href="#literals">Literals: Functions, Objects and Arrays</a>
<a href="#lexical-scope">Lexical Scoping and Variable Safety</a>
<a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
<a href="#splats">Splats…</a>
<a href="#loops">Loops and Comprehensions</a>
<a href="#slices">Array Slicing and Splicing</a>
<a href="#expressions">Everything is an Expression</a>
<a href="#operators">Operators and Aliases</a>
<a href="#existential-operator">Existential Operator</a>
<a href="#classes">Classes, Inheritance, and Super</a>
<a href="#destructuring">Destructuring Assignment</a>
<a href="#fat-arrow">Bound and Generator Functions</a>
<a href="#embedded">Embedded JavaScript</a>
<a href="#switch">Switch and Try/Catch</a>
<a href="#comparisons">Chained Comparisons</a>
<a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
<a href="#tagged-template-literals">Tagged Template Literals</a>
<a href="#regexes">Block Regular Expressions</a>
<a href="#modules">Modules</a>
<a href="#cake">Cake, and Cakefiles</a>
<a href="#source-maps">Source Maps</a>
<a href="#scripts">"text/coffeescript" Script Tags</a>
<a href="#resources">Books, Screencasts, Examples and Resources</a>
<a href="#changelog">Change Log</a>
</div>
</div>
<div class="navigation try">
<div class="button">
Try CoffeeScript
<div class="repl_bridge"></div>
</div>
<div class="contents repl_wrapper">
<div class="code">
<div class="screenshadow tl"></div>
<div class="screenshadow tr"></div>
<div class="screenshadow bl"></div>
<div class="screenshadow br"></div>
<div id="repl_source_wrap">
<textarea id="repl_source" rows="100" spellcheck="false">alert "Hello CoffeeScript!"</textarea>
</div>
<div id="repl_results_wrap"><pre id="repl_results"></pre></div>
<div class="minibutton dark run" title="Ctrl-Enter">Run</div>
<a class="minibutton permalink" id="repl_permalink">Link</a>
<br class="clear" />
</div>
</div>
</div>
<div class="navigation annotated">
<div class="button">
Annotated Source
</div>
<div class="contents menu">
<a href="v<%= majorVersion %>/annotated-source/grammar.html">Grammar Rules — src/grammar</a>
<a href="v<%= majorVersion %>/annotated-source/lexer.html">Lexing Tokens — src/lexer</a>
<a href="v<%= majorVersion %>/annotated-source/rewriter.html">The Rewriter — src/rewriter</a>
<a href="v<%= majorVersion %>/annotated-source/nodes.html">The Syntax Tree — src/nodes</a>
<a href="v<%= majorVersion %>/annotated-source/scope.html">Lexical Scope — src/scope</a>
<a href="v<%= majorVersion %>/annotated-source/helpers.html">Helpers &amp; Utility Functions — src/helpers</a>
<a href="v<%= majorVersion %>/annotated-source/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
<a href="v<%= majorVersion %>/annotated-source/cake.html">Cake &amp; Cakefiles — src/cake</a>
<a href="v<%= majorVersion %>/annotated-source/command.html">“coffee” Command-Line Utility — src/command</a>
<a href="v<%= majorVersion %>/annotated-source/optparse.html">Option Parsing — src/optparse</a>
<a href="v<%= majorVersion %>/annotated-source/repl.html">Interactive REPL — src/repl</a>
<a href="v<%= majorVersion %>/annotated-source/sourcemap.html">Source Maps — src/sourcemap</a>
</div>
</div>
</div>
<div class="container">
<%= htmlFor('introduction', 'top') %>
<%= htmlFor('overview') %>
<%= htmlFor('installation') %>
<%= htmlFor('usage') %>
<%= htmlFor('literate') %>
<%= htmlFor('language') %>
<%= htmlFor('functions', 'literals') %>
<%= htmlFor('objects_and_arrays') %>
<%= htmlFor('lexical_scope') %>
<%= htmlFor('conditionals') %>
<%= htmlFor('splats') %>
<%= htmlFor('loops') %>
<%= htmlFor('slices') %>
<%= htmlFor('expressions') %>
<%= htmlFor('operators') %>
<%= htmlFor('existential_operator') %>
<%= htmlFor('classes') %>
<%= htmlFor('destructuring') %>
<%= htmlFor('fat_arrow') %>
<%= htmlFor('embedded') %>
<%= htmlFor('switch') %>
<%= htmlFor('try') %>
<%= htmlFor('comparisons') %>
<%= htmlFor('strings') %>
<%= htmlFor('tagged_template_literals') %>
<%= htmlFor('heregexes', 'regexes') %>
<%= htmlFor('modules') %>
<%= htmlFor('cake') %>
<%= htmlFor('source_maps') %>
<%= htmlFor('scripts') %>
<%= htmlFor('books', 'resources') %>
<%= htmlFor('screencasts') %>
<%= htmlFor('examples') %>
<%= htmlFor('resources', 'additional-resources') %>
<%= htmlFor('chat') %>
<%= htmlFor('changelog') %>
</div>

View File

@@ -0,0 +1,92 @@
sourceFragment = "try:"
# Set up the compilation function, to run when you stop typing.
compileSource = ->
source = $('#repl_source').val()
results = $('#repl_results')
window.compiledJS = ''
try
window.compiledJS = CoffeeScript.compile source, bare: on
el = results[0]
if el.innerText
el.innerText = window.compiledJS
else
results.text(window.compiledJS)
results.removeClass 'error'
$('.minibutton.run').removeClass 'error'
catch {location, message}
if location?
message = "Error on line #{location.first_line + 1}: #{message}"
results.text(message).addClass 'error'
$('.minibutton.run').addClass 'error'
# Update permalink
$('#repl_permalink').attr 'href', "##{sourceFragment}#{encodeURIComponent source}"
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compileSource()
# Use tab key to insert tabs
$('#repl_source').keydown (e) ->
if e.keyCode is 9
e.preventDefault()
textbox = e.target
# Insert tab character at caret or in selection
textbox.value = textbox.value[0...textbox.selectionStart] + "\t" + textbox.value[textbox.selectionEnd...]
# Put caret in correct position
textbox.selectionEnd = ++textbox.selectionStart
# Eval the compiled js.
evalJS = ->
try
eval window.compiledJS
catch error then alert error
# Load the console with a string of CoffeeScript.
window.loadConsole = (coffee) ->
$('#repl_source').val coffee
compileSource()
$('.navigation.try').addClass('active')
false
# Helper to hide the menus.
closeMenus = ->
$('.navigation.active').removeClass 'active'
$('.minibutton.run').click -> evalJS()
# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
return false if $(e.target).closest('.repl_wrapper').length
if $(this).hasClass('active')
closeMenus()
else
closeMenus()
$(this).addClass 'active'
false
# Dismiss console if Escape pressed or click falls outside console
# Trigger Run button on Ctrl-Enter
$(document.body)
.keydown (e) ->
closeMenus() if e.which == 27
evalJS() if e.which == 13 and (e.metaKey or e.ctrlKey) and $('.minibutton.run:visible').length
.click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()
$('#open_webchat').click ->
$(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
$("#repl_permalink").click (e) ->
window.location = $(this).attr("href")
false
# If source code is included in location.hash, display it.
hash = decodeURIComponent location.hash.replace(/^#/, '')
if hash.indexOf(sourceFragment) == 0
src = hash.substr sourceFragment.length
loadConsole src
compileSource()

View File

@@ -1,6 +1,6 @@
/* Highlight.js syntax highlighting */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original code:; http://softwaremaniacs.org/media/soft/highlight/styles/tomorrow.css */
/* But forked for CoffeeScript */
/* Forked from http://softwaremaniacs.org/media/soft/highlight/styles/tomorrow.css */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}