├── sample_data └── _config.yml ├── README.textile └── haml.rb /sample_data/_config.yml: -------------------------------------------------------------------------------- 1 | haml_folder: **/*.haml 2 | sass_folder: **/*.sass 3 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. HAML Jekyll extension 2 | 3 | Auto-generates html and css files for your layouts in HAML/SASS (you can still have your liquid syntax) 4 | 5 | This extension uses "_jekyll_ext_":http://github.com/rfelix/jekyll_ext, which allows you to extend the Jekyll static blog generator without forking and modifying it's codebase. 6 | With this code, not only do your extensions live in your blog directory, but they can also be shared and reutilized. 7 | 8 | Use this extension with _jekyll_ext_ by just cloning this repo into the _extensions dir of your blog: git clone git://github.com/codegram/haml_jekyll_extension.git _extensions 9 | 10 | More information about _jekyll_ext_ can be found here: "Jekyll Extensions -= Pain":http://rfelix.com/2010/01/19/jekyll-extensions-minus-equal-pain/ 11 | -------------------------------------------------------------------------------- /haml.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'haml' 3 | require 'sass' 4 | 5 | module Jekyll 6 | class Site 7 | 8 | def haml2html 9 | folder = self.config['haml_folder'] || '**/*.haml' 10 | compile( ["*.haml", folder], /\.haml$/, ".html", Haml::Engine ) 11 | end 12 | 13 | def sass2css 14 | folder = self.config['folder'] || '**/*.sass' 15 | compile( ["*.sass", folder], /\.sass$/, ".css", Sass::Engine ) 16 | end 17 | 18 | def scss2css 19 | folder = self.config['scss_folder'] || '**/*.scss' 20 | compile( ["*.scss", folder], /\.scss$/, ".css", Sass::Engine, syntax: :scss ) 21 | end 22 | 23 | private 24 | 25 | def compile( files, input_regex, output_extension, engine, options = {} ) 26 | 27 | Dir.glob(files).each do |f| 28 | origin = File.open(f).read 29 | result = engine.new( origin, options ).render 30 | if !result.empty? 31 | 32 | puts "Rendering #{f}" 33 | output_file_name = f.gsub!( input_regex, output_extension ) 34 | 35 | if file_outdated?( output_file_name, result ) 36 | File.open( output_file_name, 'w' ) do |f| 37 | f.write( result ) 38 | end 39 | end 40 | 41 | end 42 | end 43 | end 44 | 45 | def file_outdated?( file, result ) 46 | !File.exists?(file) or (File.exists?(file) and result != File.read(file)) 47 | end 48 | 49 | end 50 | 51 | AOP.before(Site, :render) do |site_instance, result, args| 52 | site_instance.haml2html 53 | end 54 | 55 | AOP.before(Site, :render) do |site_instance, result, args| 56 | site_instance.sass2css 57 | end 58 | 59 | AOP.before(Site, :render) do |site_instance, result, args| 60 | site_instance.scss2css 61 | end 62 | 63 | AOP.around(Site, :filter_entries) do |site_instance, args, proceed, abort| 64 | result = proceed.call 65 | result.reject do |entry| 66 | entry.match(/\.haml$/) || 67 | entry.match(/\.sass$/) || 68 | entry.match(/\.scss$/) 69 | end 70 | end 71 | end 72 | --------------------------------------------------------------------------------