-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
executable file
·94 lines (75 loc) · 2.42 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
# Rake tasks to parse haml layouts, includes and index files and sass files for jekyll
# Assumes that the haml files are in (_layouts|_includes)/_haml
# and the less files are in css/_less
namespace :haml do
require 'haml'
def convert file, destination
base_name = File.basename(file, '.haml') + '.html'
convert_full file, File.join(destination, base_name)
end
def convert_full from, to
html = Haml::Engine.new(File.read(from)).render
File.open(to, 'w') { |f| f.write html }
end
desc 'Parse haml layout files'
task :layouts do
Dir.glob('_layouts/_haml/*.haml') do |path|
convert path, '_layouts'
end
puts 'Parsed haml layout files'
end
desc 'Parse haml include files'
task :includes do
Dir.glob('_includes/_haml/*.haml') do |path|
convert path, '_includes'
end
puts 'Parsed haml include files'
end
desc 'Parse haml index files'
task :indexes do
convert './index.haml', File.dirname('./index.haml')
convert_full './sponsors.haml', './sponsors/index.html'
puts 'Parsed haml index files'
end
end
desc 'Parse less files'
task :less do
require 'less'
parser = Less::Parser.new filename: "stylesheet.css", paths: "stylesheets/_sass"
css = parser.parse(File.read("stylesheets/_sass/stylesheet.less")).to_css
File.open('stylesheets/stylesheet.css', 'w') { |f| f.write css }
puts 'Parsed main.sass'
end
def tidy_docs
Dir.glob('docs/**/*.html') do |path|
diff = `git diff --numstat #{path}`
if diff.start_with?("1\t1\t")
line_change = `git diff -U0 #{path} | tail -n 1`
if line_change =~ /<div class="book" data-level="[^\"]+" data-basepath="[^\"]+" data-revision="[^\"]+">/
`git checkout #{path}`
end
end
end
end
desc 'Build docs'
task :docs do
`which gitbook`
unless $?.success?
abort "ERROR: can't find gitbook on your PATH, please install gitbook-cli:\n\n" \
"gem install bundler # if you don't have bundler already\n" \
"bundle\n" \
"npm install -g gitbook-cli"
end
system "gitbook build ./_gitbook --gitbook=2.3.2"
system "rm -rf ./docs"
system "mv ./_gitbook/_book ./docs"
tidy_docs
end
desc 'Tidy up generated gitbook files to avoid superfluous changes'
task :'docs:tidy' do
tidy_docs
end
desc 'Parse all haml items'
task haml: ['haml:layouts', 'haml:includes', 'haml:indexes']
desc 'Build all haml and sass files for deployment'
task build: [:haml, :less, :docs]