Class: Tilt::StaticTemplate
Overview
Static templates are templates that return the same output for every render
Instead of inheriting from the StaticTemplate class, you will use the .subclass method with a block which processes @data and returns the transformed value.
Basic example which transforms the template to uppercase:
UppercaseTemplate = Tilt::StaticTemplate.subclass do
@data.upcase
end
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Template
#compiled_path, #data, #file, #line, #options
For template implementations collapse
- .subclass(mime_type: 'text/html', &block) ⇒ Object
-
#allows_script? ⇒ Boolean
Static templates never allow script.
-
#compiled_method(locals_keys, scope_class = nil) ⇒ Object
Raise NotImplementedError, since static templates do not support compiled methods.
-
#render(scope = nil, locals = nil) ⇒ Object
Static templates always return the prepared output.
Methods inherited from Template
#basename, default_mime_type, default_mime_type=, #eval_file, #fixed_locals?, #initialize, metadata, #metadata, #name
Constructor Details
This class inherits a constructor from Tilt::Template
Class Method Details
.subclass(mime_type: 'text/html', &block) ⇒ Object
564 565 566 567 568 569 570 571 572 |
# File 'lib/tilt/template.rb', line 564 def self.subclass(mime_type: 'text/html', &block) Class.new(self) do self.default_mime_type = mime_type private define_method(:_prepare_output, &block) end end |
Instance Method Details
#allows_script? ⇒ Boolean
Static templates never allow script.
586 587 588 |
# File 'lib/tilt/template.rb', line 586 def allows_script? false end |
#compiled_method(locals_keys, scope_class = nil) ⇒ Object
Raise NotImplementedError, since static templates do not support compiled methods.
581 582 583 |
# File 'lib/tilt/template.rb', line 581 def compiled_method(locals_keys, scope_class=nil) raise NotImplementedError end |
#render(scope = nil, locals = nil) ⇒ Object
Static templates always return the prepared output.
575 576 577 |
# File 'lib/tilt/template.rb', line 575 def render(scope=nil, locals=nil) @output end |