forked from emberjs/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assetfile
80 lines (66 loc) · 1.91 KB
/
Assetfile
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
require 'yaml'
require 'json'
require 'erb'
require 'rake-pipeline-web-filters/ordering_concat_filter'
require 'rake-pipeline-web-filters/markdown_compiler'
WebFilters = Rake::Pipeline::Web::Filters
input "assets"
output "output"
class StepFilter < Filter
def generate_output(inputs, output)
inputs.each do |input|
yaml = YAML.load(input.read)
code = "Tutorial.tutorialController.addStep({\n"
code << yaml.map do |key,value|
value = value.sub(/\n+$/,'')
value = (key == "validator") ? "function(context){\n#{value}\n}" : value.to_json
" #{key}: #{value}"
end.join(",\n")
code << "\n});"
output.write(code)
end
end
end
class HTMLWrapperFilter < Filter
def initialize(options={})
@options = options
super()
end
def generate_output(inputs, output)
template = @template || create_template
inputs.each do |input|
output.write render_template {
input.read
}
end
end
def create_template
template = File.read(@options[:template])
@template = ERB.new(template)
end
def render_template
@template.result(binding)
end
end
match "tutorial/steps/*.yml" do
filter StepFilter do |path|
path.sub(/\.yml$/, '.js')
end
end
match "tutorial/**/*.js" do
filter WebFilters::OrderingConcatFilter, ['tutorial/tutorial.js'], 'tutorial.js'
end
match "docs/**/*.md" do
sections = [ 'introduction', 'application', 'object_model', 'handlebars', 'views' ]
sections.map! { |file| "docs/#{file}.html" }
filter WebFilters::MarkdownCompiler
filter HTMLWrapperFilter, :template => 'assets/docs/_section.erb'
filter WebFilters::OrderingConcatFilter, sections, "documention.html"
filter HTMLWrapperFilter, :template => 'assets/docs/_documentation.erb'
filter ConcatFilter, "index.html" #"documentation/index.html"
end
# Hide for now
match "tutorial.html" do
filter ConcatFilter, ".hidden"
end
# vim: filetype=ruby