Created
May 16, 2010 08:42
-
-
Save jeromeetienne/402770 to your computer and use it in GitHub Desktop.
template based on mustache
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 | |
# system of template which are based on mustache | |
# - http://mustache.github.com/ | |
# - it seems serious work. Just i dont like to have more dependancies | |
module TemplateEzmustache | |
def self.patch(template, variables) | |
variables.each { |key, val| | |
template.gsub!("{{#{key}}}", val) | |
} | |
return template | |
end | |
def self.patch_file(filename, variables) | |
file_content = File.read(filename) | |
return self.patch(file_content, variables) | |
end | |
end | |
if $PROGRAM_NAME == __FILE__ | |
template = "hello {{destination}}! how {{verb}} you" | |
variables = { | |
:destination => "world", | |
:verb => "are" | |
} | |
result = TemplateEzmustache.patch(template, variables) | |
puts result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment