Class: Hanami::View::Template
- Inherits:
-
Object
- Object
- Hanami::View::Template
- Defined in:
- lib/hanami/view/template.rb
Overview
A logic-less template.
Direct Known Subclasses
Instance Method Summary collapse
-
#format ⇒ Symbol
Returns the format that the template handles.
-
#initialize(template, encoding = Encoding::UTF_8) ⇒ Template
constructor
A new instance of Template.
-
#render(scope, &blk) ⇒ String
private
Render the template within the context of the given scope.
Constructor Details
#initialize(template, encoding = Encoding::UTF_8) ⇒ Template
Returns a new instance of Template.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hanami/view/template.rb', line 9 def initialize(template, encoding = Encoding::UTF_8) = { default_encoding: encoding } if slim?(template) # NOTE disable_escape: true is for Slim compatibility # See https://github.com/hanami/assets/issues/36 [:disable_escape] = true end @_template = Tilt.new(template, nil, ) end |
Instance Method Details
#format ⇒ Symbol
Returns the format that the template handles.
32 33 34 |
# File 'lib/hanami/view/template.rb', line 32 def format @_template.basename.match(/\.([^.]+)/).captures.first.to_sym end |
#render(scope, &blk) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render the template within the context of the given scope.
46 47 48 |
# File 'lib/hanami/view/template.rb', line 46 def render(scope, &blk) @_template.render(scope, {}, &blk) end |