-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
91 lines (80 loc) · 2.26 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
require 'rake'
require 'rake/testtask'
task :default => [:test]
desc "Run basic tests"
Rake::TestTask.new("test") { |t|
t.pattern = 'test/*_test.rb'
t.verbose = true
t.warning = false # currently treetop's metagrammer.rb:10 warns
}
module ReadmeTemplates
# output some style. the only parts that are really required are the hr and
# div.indent styles, the rest just look nice.
def style( format, positional_args, hash_args, options )
# colors, from tango icon theme guidelines
grey = '#BABDB6'
light_grey = '#EEEEEC'
red = '#CC0000'
case format
when :html
return <<-END_STYLE
<style>
a {
color: #{red};
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1, h2, hr {
border: 0;
border-bottom: 1px solid #{grey};
}
div.indent, ol, ul, dl {
padding-left: 2.5em;
margin: 0em;
}
ol.footnotes {
margin-left: 1em;
border-left: 1px solid #{grey};
}
pre {
margin: 0.5em;
padding: 0.5em;
border: 1px dashed #{grey};
background-color: #{light_grey};
-moz-border-radius: 3px;
}
</style>
END_STYLE
end
end
# wraps the first positional arg in <tt> and </tt>
# this should eventually have markup, since it's really handy.
def tt( format, positional_args, hash_args, options )
case format
when :html
"<tt>#{positional_args.first}</tt>"
when :text
positional_args.first
end
end
# display a template name, with {{ and }}
def template( format, positional_args, hash_args, options )
tt( format, ['{{' + positional_args[0] + '}}'], hash_args, options )
end
end
desc "Compile README.marker to README.html"
task :readme do
$: << 'lib'
require 'marker'
Marker.templates = ReadmeTemplates
File.open( 'README.html', 'w' ) do |html|
# read in the markup. don't use Marker.parse_file so we can escape HTML chars.
markup = File.read( 'README.marker' )
# escape < and >, then parse
parse_tree = Marker.parse( markup.gsub!('<', '<').gsub('>', '>') )
# generate and write the HTML output
html.write( parse_tree.to_html )
end
end