Skip to content

Instantly share code, notes, and snippets.

@dtjm
Forked from radamant/haml_converter.rb
Created August 17, 2010 06:07
Show Gist options
  • Save dtjm/528642 to your computer and use it in GitHub Desktop.
Save dtjm/528642 to your computer and use it in GitHub Desktop.
Haml and Sass plugin for Jekyll 0.6.2
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
@richardkmichael
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment