Skip to content

Instantly share code, notes, and snippets.

@mcasimir
Created May 10, 2013 00:33
Show Gist options
  • Select an option

  • Save mcasimir/5551653 to your computer and use it in GitHub Desktop.

Select an option

Save mcasimir/5551653 to your computer and use it in GitHub Desktop.
Coffeebuild static site builder Cakefile example
Coffeebuild = require("../Coffeebuild/src/coffeebuild")
PegSH = require("../PegSH/src/pegsh")
###
Build the site
###
task 'build', 'Build site', ->
htmlBuilder = new Coffeebuild.Builder()
.onFailure (reason) ->
console.log reason.message
.with("markdown", "dom")
.load("site/src/index.markdown")
.markdown()
.dom()
.jqueryfy()
# Syntax Highlighting
.do (task, win) ->
$ = win.$
$("code").each ->
txt = $(this).html()
match = txt.match(/^\!([a-z]+)[ \t]*\n/)
if match
lang = match[1]
$(this).parent().addClass(lang)
src = txt.replace(/^\!([a-z]+)[ \t]*\n/, "")
sh = new PegSH.Highlighter()
try
$(this).html(sh.highlight(src, lang))
catch error
task.fail(error.message)
task.done(win)
# Populating TOC
.do (task, win) ->
$ = win.$
toc = $("<ul id=\"toc\"></ul>")
$("h2").each (i,e)->
h2 = $(this)
toc.append($("<li><a href='#chapter-#{i}'>#{h2.text()}</a></li>"))
h2.attr("id", "chapter-#{i}")
$("body").prepend(toc)
task.done(win)
.unjquerify()
.body()
.log()
.prepend("site/src/header.html")
.append("site/src/footer.html")
.store("site/deploy/index.html")
cssBuilder = new Coffeebuild.Builder().with("css")
.load("site/src/style.css")
.minifyCss()
.store("site/deploy/style.css")
jsBuilder = new Coffeebuild.Builder().with("coffee", "minify")
.source("site/src/site.coffee")
.coffee()
.minify()
.prepend("site/src/jquery.localscroll-1.2.7-min.js", {newline: true})
.prepend("site/src/jquery.scrollTo-1.4.2-min.js", {newline: true})
.prepend("site/src/jquery.min.js", {newline: true})
.store("site/deploy/site.js")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment