Created
November 6, 2012 19:17
-
-
Save zhangyuan/4026842 to your computer and use it in GitHub Desktop.
Generate html pages from Slim templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
task :default => [:generate] | |
# put Slim templates under templates/ directory. run `rake generate` to generate html pages into public/ directory. | |
desc 'Generate html pages from Slim templates' | |
task :generate do | |
base_path = File.dirname(__FILE__) | |
templates_path = File.join(base_path, 'templates') | |
public_dir = File.join(base_path, 'public') | |
Dir.glob("#{templates_path}/**/*.slim").each do |path| | |
output_path = File.join(public_dir, path[templates_path.length..-6]) | |
FileUtils.mkdir_p(File.dirname(output_path)) | |
File.open(output_path, 'w') do |file| | |
file.puts(Slim::Template.new(path, | |
:pretty => true, | |
:sections => true) { File.open(path, 'r').read }.render) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment