Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SASS support and filter HAML and SASS files

  • Loading branch information...
commit 23ae4ffb1ae8ab6b5306356c8d3ff046e09e1846 1 parent c9f4ec5
Oriol Gual oriolgual authored
Showing with 30 additions and 5 deletions.
  1. +27 −5 haml.rb
  2. +3 −0  sample_data/_config.yml
32 haml.rb
View
@@ -1,17 +1,31 @@
module Jekyll
class Site
def haml2html
- haml_path = self.config['haml'] || 'haml'
- (Dir["*.haml", File.join("_layouts", "*.haml")]).each do |f|
+ path = self.config['haml_path'] || 'haml'
+ haml_folder = self.config['haml_folder'] || '**/*.haml'
+ compile_haml(path, ["*.haml", haml_folder], /\.haml$/,'.html')
+ end
+
+ def sass2css
+ path = self.config['sass_path'] || 'sass'
+ sass_folder = self.config['sass_folder'] || '**/*.sass'
+ compile_haml(path, ["*.sass", sass_folder], /\.sass$/,'.css')
+ end
+
+ private
+
+ def compile_haml(exec_path, files, input_regex, output_extension)
+ Dir.glob(files).each do |f|
begin
- result = `#{haml_path} #{f}`
+ result = `#{exec_path} #{f}`
raise HamlErrorException.new if result.empty?
- output_file_name = f.gsub!(/\.haml$/,'.html')
+ puts "Rendering #{f}"
+ output_file_name = f.gsub!(input_regex,output_extension)
File.open(output_file_name,'w') {|f| f.write(result)} if !File.exists?(output_file_name) or (File.exists?(output_file_name) and result != File.read(output_file_name))
rescue HamlErrorException => e
end
end
- end
+ end
end
class HamlErrorException < Exception
@@ -20,4 +34,12 @@ class HamlErrorException < Exception
AOP.before(Site, :render) do |site_instance, result, args|
site_instance.haml2html
end
+
+ AOP.before(Site, :render) do |site_instance, result, args|
+ site_instance.sass2css
+ end
+
+ AOP.after(Site, :filter_entries) do |site_instance, result, args|
+ result.reject{ |entry| entry.match(/\.haml$/) || entry.match(/\.sass$/) }
+ end
end
3  sample_data/_config.yml
View
@@ -1 +1,4 @@
haml_path: haml
+haml_folder: **/*.haml
+sass_path: sass
+sass_folder: **/*.sass
Please sign in to comment.
Something went wrong with that request. Please try again.