Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Created July 10, 2012 03:03
Show Gist options
  • Select an option

  • Save flaneur2020/3080709 to your computer and use it in GitHub Desktop.

Select an option

Save flaneur2020/3080709 to your computer and use it in GitHub Desktop.
Rakefile for book generator
# author: arcturo
# from https://github.com/arcturo/library/blob/master/coffeescript/Rakefile
require "rdiscount"
require "mustache"
require "active_support/core_ext/string"
require "fileutils"
def generate(page, template = "site/page.ms")
Mustache.render(
File.read(template),
page.merge(:content => RDiscount.new(File.read(page[:src])).to_html),
)
end
task :generate do
pages = Dir["chapters/*.md"].inject([]) do |array, src|
array << ({
:src => src,
:static => File.basename(src, ".md") + ".html",
:name => File.basename(src, ".md").gsub(/\d+_/, "").titleize,
:href => File.basename(src, ".md") + ".html"
})
array
end
pages.each do |page|
File.open(page[:static], "w+") do |f|
f.write generate(page)
end
end
File.open("index.html", "w+") do |f|
f.write(Mustache.render(
File.read("site/index.ms"),
:pages => pages
))
end
File.open("all.html", "w+") do |f|
pages.each do |page|
f.write generate(page)
end
end
end
task :default => :generate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment