public
Last active — forked from radamant/haml_converter.rb

Haml and Sass plugin for Jekyll 0.6.2

  • Download Gist
haml_converter.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
module Jekyll
require 'haml'
class HamlConverter < Converter
safe true
priority :low
 
def matches(ext)
ext =~ /haml/i
end
 
def output_ext(ext)
".html"
end
 
def convert(content)
begin
engine = Haml::Engine.new(content)
engine.render
rescue StandardError => e
puts "!!! HAML Error: " + e.message
end
end
end
 
require 'sass'
class SassConverter < Converter
safe true
priority :low
 
def matches(ext)
ext =~ /sass/i
end
 
def output_ext(ext)
".css"
end
 
def convert(content)
begin
engine = Sass::Engine.new(content)
engine.render
rescue StandardError => e
puts "!!! SASS Error: " + e.message
end
end
end
end

Today I was bit by a Jekyll / HAML problem using a similar converter, so just a comment..

HAML raises SyntaxError on parse problems. In Ruby 1.9, SyntaxError is not a child of StandardError, so rescue will miss it and probably lead to a frustrating debugging session; or, you could rescue Exception, but that seems blunt. Of course, HAML might raise other errors you're catching with StandardError.

Also, rescue expects StandardError by default, so rescue => e would be sufficient.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.