Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adapted to use haml and sass libraries instead of binaries.

Hundrers of times faster!
  • Loading branch information...
commit 9ade812d8e313b1875b5ab8e12c904c4fa646ca3 1 parent 05fedaf
@josepjaume josepjaume authored
Showing with 25 additions and 8 deletions.
  1. +25 −6 haml.rb
  2. +0 −2  sample_data/_config.yml
View
31 haml.rb
@@ -1,30 +1,49 @@
+require 'rubygems'
+require 'haml'
+require 'sass'
+
module Jekyll
class Site
def haml2html
- path = self.config['haml_path'] || 'haml'
haml_folder = self.config['haml_folder'] || '**/*.haml'
- compile_haml(path, ["*.haml", haml_folder], /\.haml$/,'.html')
+ compile_haml(["*.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')
+ compile_sass(["*.sass", sass_folder], /\.sass$/,'.css')
end
private
- def compile_haml(exec_path, files, input_regex, output_extension)
+ def compile_haml(files, input_regex, output_extension)
+ Dir.glob(files).each do |f|
+ begin
+ origin = File.open(f).read
+ result = Haml::Engine.new(origin).render
+ raise HamlErrorException.new if result.empty?
+ 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
+
+ def compile_sass(files, input_regex, output_extension)
Dir.glob(files).each do |f|
begin
- result = `#{exec_path} #{f}`
+ origin = File.open(f).read
+ result = Sass::Engine.new(origin).render
raise HamlErrorException.new if result.empty?
+ 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
class HamlErrorException < Exception
View
2  sample_data/_config.yml
@@ -1,4 +1,2 @@
-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.