Created
February 8, 2016 11:45
-
-
Save sonota88/4317a521d02cf594c341 to your computer and use it in GitHub Desktop.
erb context
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 ErbContext | |
def initialize params | |
@params = params | |
end | |
def method_missing name, *args | |
if @params.has_key? name | |
@params[name] | |
else | |
raise "unknown key (#{name})" | |
end | |
end | |
def get_binding | |
binding | |
end | |
def self.hash_to_binding params | |
ErbContext.new(params).get_binding | |
end | |
end | |
def render template, params | |
erb = ERB.new(template) | |
erb.result ErbContext.hash_to_binding(params) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment