-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
103 lines (87 loc) · 3.09 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "yaml"
require "haml"
require "sass"
require "nokogiri"
require "redcarpet"
require "pygments"
require "yui/compressor"
HERE = File.dirname(__FILE__)
CSS_FILES = %w{pygments}.map { |f| "#{f}.css" }
SASS_FILES = %w{hightables}.map { |f| "#{f}.sass" }
JAVASCRIPT_FILES = %w{init parse base table chart linechart barchart piechart}.map { |f| "#{f}.js" }
SECTIONS = YAML.load_file(File.join(HERE, "doc", "sections.yml"))
README_SECTIONS = SECTIONS.reject { |s| s["exclude-from-readme"] }
def read_file(dir, filename)
File.read(File.join(HERE, dir, filename))
end
def write_file(*args)
filename, content = args[-2, 2]
dirs = args.take(args.length - 2)
File.open(File.join(HERE, *dirs, filename), "w") do |stream|
stream.write(content)
end
end
def renderer
@renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true)
end
def content_exists?(section_id)
return File.exist?(File.join(HERE, "doc", "#{section_id}.md"))
end
def render_content(section_id)
if content_exists?(section_id)
markdown = read_file("doc", "#{section_id}.md")
return renderer.render(markdown)
end
""
end
def example_exists?(section_id)
return File.exist?(File.join(HERE, "doc", "#{section_id}.haml"))
end
def render_example(section_id)
if example_exists?(section_id)
haml = read_file("doc", "#{section_id}.haml")
return Haml::Engine.new(haml).render
end
""
end
namespace :build do
desc "Build all assets"
task :all => [:readme, :html, :css, :js]
desc "Compile README file from docs (without examples)"
task :readme do
docs = read_file("doc", "intro.md") + "\n" +
README_SECTIONS.map { |section| read_file("doc", "#{section['id']}.md") }.join("\n")
write_file("README.md", docs)
end
desc "Compile HAML to HTML"
task :html do
haml = read_file("src", "index.haml")
html = Haml::Engine.new(haml).render(self, :sections => SECTIONS)
hdoc = Nokogiri::HTML.parse(html)
hdoc.css("pre").each do |node|
lang = node.css("code").attribute("class")
node.replace(Pygments.highlight(node.content, :lexer => lang))
end
write_file("dist", "index.html", hdoc.to_html)
end
desc "Compile SASS, then concatenate and minify into a single CSS file"
task :css do
sass = SASS_FILES.map { |filename| read_file("src", filename) }.join("\n")
css = [
Sass.compile(sass, :syntax => :sass),
CSS_FILES.map { |filename| read_file("src", filename) }.join("\n")
].join("\n")
write_file("dist", "hightables.css", css)
write_file("dist", "hightables.min.css", YUI::CssCompressor.new.compress(css))
end
desc "Concatenate and minify JavaScript assets into a single file"
task :js do
javascript = JAVASCRIPT_FILES.map { |filename| read_file("src", filename) }.join("\n")
write_file("dist", "hightables.js", javascript)
write_file("dist", "hightables.min.js", YUI::JavaScriptCompressor.new(:munge => true).compress(javascript))
end
end
desc "A convenience task to open the documentation in your default browser"
task :open do
`open #{File.join(HERE, "dist", "index.html")}`
end