Created
December 4, 2014 04:59
-
-
Save epitron/0701603bbe76a0f3acd5 to your computer and use it in GitHub Desktop.
Crazy Ruby Templating System, using Regular Ruby Strings!
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
require 'binding_of_caller' | |
class Tmpl | |
def initialize(&block) | |
@tmpl = block | |
end | |
def render | |
@thebinding = binding.of_caller(1) | |
instance_eval &@tmpl | |
end | |
def method_missing(name, *args) | |
@thebinding.eval("#{name}") | |
end | |
end | |
t = Tmpl.new do | |
%{ #{var} is my favorite! } | |
end | |
var = 5 | |
p t.render | |
var = 10 | |
p t.render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment