Class: TinyTemplate
- Inherits:
-
Object
- Object
- TinyTemplate
- Defined in:
- lib/tiny_template.rb,
lib/tiny_template/version.rb
Defined Under Namespace
Modules: Utils
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .allowed_keys ⇒ Object
-
.parse(str, context) ⇒ Object
This is a facility class method aimed to simplify the construction.
- .secure(allowed_keys, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(str) ⇒ TinyTemplate
constructor
You can construct by your sulf this class, but you wont benefict from the magic of the context being automaticaly calculated with debug_inspector.
-
#parse(context) ⇒ Object
Context can be any object that you expect it will respond to methods on the template passed to the constructor.
Constructor Details
#initialize(str) ⇒ TinyTemplate
You can construct by your sulf this class, but you wont benefict from the magic of the context being automaticaly calculated with debug_inspector
8 9 10 |
# File 'lib/tiny_template.rb', line 8 def initialize(str) self.str = str end |
Class Method Details
.allowed_keys ⇒ Object
33 34 35 |
# File 'lib/tiny_template.rb', line 33 def self.allowed_keys @allowed_keys end |
.parse(str, context) ⇒ Object
This is a facility class method aimed to simplify the construction
21 22 23 |
# File 'lib/tiny_template.rb', line 21 def self.parse(str, context) new(str).parse(context) end |
.secure(allowed_keys, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/tiny_template.rb', line 25 def self.secure(allowed_keys, &block) previous_keys = @allowed_keys @allowed_keys = allowed_keys yield.tap do @allowed_keys = previous_keys end end |
Instance Method Details
#parse(context) ⇒ Object
Context can be any object that you expect it will respond to methods on the template passed to the constructor
14 15 16 17 18 |
# File 'lib/tiny_template.rb', line 14 def parse(context) str.gsub(/\{\{\w+(\.\w+)*\}\}/) do |match| interpolate(match, context) end end |