Skip to content

Instantly share code, notes, and snippets.

@assafgelber
Last active December 19, 2015 15:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assafgelber/5977827 to your computer and use it in GitHub Desktop.
Save assafgelber/5977827 to your computer and use it in GitHub Desktop.
Rakefile for building haml layouts, includes and indexes for jekyll for use in github pages.
# Rake tasks to parse haml layouts, includes and index files for jekyll
# Assumes that the haml files are in (_layouts|_includes|_posts)/_haml
namespace :haml do
require 'haml'
def convert file, destination
base_name = File.basename(file, '.haml') + '.html'
html = File.open(file, 'r') { |f| Haml::Engine.new(f.read).render }
File.open(File.join(destination, base_name), '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 static files'
task :statics do
Dir.glob('*.haml') do |path|
convert path, File.dirname(path)
end
puts 'Parsed haml index files'
end
desc 'Parse haml static files'
task :indexes do
Dir.glob('**/index.haml') do |path|
convert path, File.dirname(path)
end
puts 'Parsed haml index files'
end
desc 'Parse haml posts'
task :posts do
Dir.glob('_posts/_haml/*.haml') do |path|
convert path, '_posts'
end
puts 'Parsed haml posts'
end
end
desc 'Parse all haml items'
task haml: ['haml:layouts', 'haml:includes', 'haml:statics', 'haml:indexes', 'haml:posts']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment