Skip to content

Instantly share code, notes, and snippets.

@jeromeetienne
Created May 16, 2010 08:42
Show Gist options
  • Save jeromeetienne/402770 to your computer and use it in GitHub Desktop.
Save jeromeetienne/402770 to your computer and use it in GitHub Desktop.
template based on mustache
#!/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