Created
October 10, 2014 10:55
-
-
Save mikebaldry/556c21579f48076b3b1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.