Created
October 2, 2012 06:07
-
-
Save tmtk75/3816634 to your computer and use it in GitHub Desktop.
Rakefile to convert READMD.md with kramdown and haml including twitter bootstrap and jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "kramdown" | |
require "haml" | |
task :default => :doc | |
task :doc do | |
bootstrap = "https://raw.github.com/cdnjs/cdnjs/master/ajax/libs/twitter-bootstrap/2.1.1/css/bootstrap.min.css" | |
responsive = "https://github.com/cdnjs/cdnjs/blob/master/ajax/libs/twitter-bootstrap/2.1.1/css/bootstrap-responsive.min.css" | |
jquery = "http://code.jquery.com/jquery-1.8.2.min.js" | |
coffeescript = "http://coffeescript.org/extras/coffee-script.js" | |
jqcode = <<-EOF | |
toc = $("<ul id='table-of-contents'>") | |
$("h1,h2,h3,h4,h5,h6").each (i, _e)-> | |
e = $(_e) | |
li = $("<li>").addClass(_e.nodeName.toLowerCase()) | |
.append $("<a>").attr("href", "#" + e.attr("id")) | |
.text(e.text()) | |
toc.append li | |
$("body h1:eq(0)").before toc | |
EOF | |
style = <<-EOF | |
#table-of-contents li { list-style: none; } | |
#table-of-contents li.h2 { margin-left: 2em; } | |
#table-of-contents li.h3 { margin-left: 4em; } | |
EOF | |
readme = <<-EOF | |
%html | |
%head | |
%link{href:"#{bootstrap}",type:"text/css",rel:"stylesheet"} | |
%link{href:"#{responsive}",type:"text/css",rel:"stylesheet"} | |
%script{src:"#{jquery}",type:"text/javascript"} | |
%script{src:"#{coffeescript}",type:"text/javascript"} | |
%style | |
=style | |
%body | |
%div.container | |
=content | |
%script{type:"text/coffeescript"} | |
=toc | |
EOF | |
locals = {content: Kramdown::Document.new(File.read("README.md")).to_html, toc: jqcode, style: style} | |
open("README.html", "w") {|f| f.puts Haml::Engine.new(readme).to_html Object.new, locals} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment