Rakefile in uniform-ui-0.6 vs Rakefile in uniform-ui-1.0
- old
+ new
@@ -10,18 +10,10 @@
environment = Sprockets::Environment.new
environment.append_path 'vendor/assets/stylesheets'
environment.append_path 'preview'
environment.css_compressor = :scss
-module Sass::Script::Functions
- def global_variable(name)
- assert_type name, :String, :name
- environment.global_env.var(name.value)
- end
- declare :global_variable, [:string]
-end
-
desc "Compile page"
task :compile do
File.open('./site/uniform.css', "w") do |file|
file << environment['uniform.scss']
@@ -31,30 +23,48 @@
file << environment['preview.scss']
end
# Render the test html file
File.open('./index.html', 'w') do |file|
- file.write(ERB.new(File.read('preview/index.html.erb')).result(binding))
+ file.write(
+ render_with_layout("preview/index.html.erb")
+ )
end
+
+ Dir.foreach(File.join('preview')).select{|file| file =~ /\.erb$/}.each do |file_name|
+ File.open("./site/#{file_name.gsub('.erb', '')}", 'w') do |file|
+ file.write(
+ render_with_layout("preview/#{file_name}")
+ )
+ end
+ end
end
-desc "Compile preview"
-task :preview do
-
- File.open('./site/site/uniform.css', "w") do |file|
- file << environment['uniform.scss']
+def capture
+ old_output = @output
+ @output = ""
+ yield
+ensure
+ @output = old_output
+end
+
+def html_block(**options, &block)
+ @output << "<pre class='#{options[:class]}'>"
+ @output << CGI::escapeHTML(capture(&block).strip)
+ @output << "</pre>"
+end
+
+def render_with_layout(template_path, context = self)
+ template = File.read(template_path)
+ layout = File.read('preview/layout.html.erb')
+ [template, layout].inject(nil) do |prev, temp|
+ render(temp){prev}
end
-
- File.open('./site/site/preview.css', "w") do |file|
- file << environment['preview.scss']
- end
-
- # Render the test html file
- File.open('./site/index.html', 'w') do |file|
- file.write(ERB.new(File.read('preview/index.html.erb')).result(binding))
- end
-
+end
+
+def render(template)
+ ERB.new(template, nil, nil, "@output").result( binding )
end
class UrlGenerator < Sprockets::DirectiveProcessor
protected
def process_source