Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created October 10, 2014 10:55
Show Gist options
  • Save mikebaldry/556c21579f48076b3b1e to your computer and use it in GitHub Desktop.
Save mikebaldry/556c21579f48076b3b1e to your computer and use it in GitHub Desktop.
class Template
def initialize(content)
@content = content
end
def render(context)
context = Hashie::Mash.new(context)
@content.gsub(/(%{([^}]+)})/) do
context[Regexp.last_match[2]]
end
end
end
@mikebaldry
Copy link
Author

Talking of the regex stuff, you can visualise regular expressions with rubular

http://www.rubular.com/r/YLwi7xPkZP

so you see each match matches 2 things, the whole text (%{blah}) and the just key (blah) which is what I wanted.

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