Created
February 13, 2012 19:35
-
-
Save rbarazi/1819400 to your computer and use it in GitHub Desktop.
Converts haml to handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "haml" | |
class MethodMissingString < String | |
def method_missing(m, *args, &block) | |
args = args.collect do |arg| | |
arg.is_a?(MethodMissingString) ? arg : "\"#{arg}\"" | |
end | |
if args.any? | |
arguments = "(#{args.join(', ')})" | |
arguments.gsub!("{{ ", "") | |
arguments.gsub!(" }}", "") | |
end | |
MethodMissingString.new("{{ #{self[3..(self.size - 4)]}.#{m}#{arguments} }}") | |
end | |
end | |
def self.method_missing(m, *args, &block) | |
args = args.collect do |arg| | |
arg.is_a?(MethodMissingString) ? arg : "\"#{arg}\"" | |
end | |
if args.any? | |
arguments = "(#{args.join(', ')})" | |
arguments.gsub!("{{ ", "") | |
arguments.gsub!(" }}", "") | |
end | |
MethodMissingString.new("{{ #{m}#{arguments} }}") | |
end | |
result = Haml::Engine.new(IO.read(ENV["TM_FILEPATH"])).render(self, {}) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment