Class: DNote::Format::ErbScope
- Inherits:
-
Object
- Object
- DNote::Format::ErbScope
show all
- Defined in:
- lib/dnote/format.rb
Overview
Evaluation scope for ERB templates
Instance Method Summary
collapse
Constructor Details
#initialize(data = {}) ⇒ ErbScope
Returns a new instance of ErbScope.
132
133
134
|
# File 'lib/dnote/format.rb', line 132
def initialize(data = {})
@data = data
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/dnote/format.rb', line 145
def method_missing(method, *_args)
sym = method.to_sym
return @data.fetch(sym) if @data.key? sym
super
end
|
Instance Method Details
#h(string) ⇒ Object
141
142
143
|
# File 'lib/dnote/format.rb', line 141
def h(string)
REXML::Text.normalize(string)
end
|
#render(file) ⇒ Object
136
137
138
139
|
# File 'lib/dnote/format.rb', line 136
def render(file)
erb = ERB.new(File.read(file), nil, '<>')
erb.result(binding)
end
|
#respond_to_missing?(method) ⇒ Boolean
152
153
154
|
# File 'lib/dnote/format.rb', line 152
def respond_to_missing?(method)
@data.key? method.to_sym
end
|