Class: Sourcerer::Templating::TemplatedField
- Inherits:
-
Object
- Object
- Sourcerer::Templating::TemplatedField
- Defined in:
- lib/sourcerer/templating.rb
Overview
Represents a field that will be rendered by a template engine.
Instance Attribute Summary collapse
-
#compiled ⇒ Object
readonly
The compiled template object.
-
#engine ⇒ String
readonly
The name of the template engine.
-
#inferred ⇒ Boolean
readonly
Whether the template engine was inferred.
-
#raw ⇒ String
readonly
The raw, un-rendered template string.
-
#tagged ⇒ Boolean
readonly
Whether the template was explicitly tagged.
Instance Method Summary collapse
-
#deferred? ⇒ Boolean
True if the field is deferred (not yet compiled).
-
#initialize(raw, compiled, engine, tagged, inferred) ⇒ TemplatedField
constructor
A new instance of TemplatedField.
-
#render(context = {}) ⇒ String
Renders the template with the given context.
-
#templated? ⇒ true
Always returns true to indicate this is a templated field.
-
#to_liquid ⇒ self
Returns self for Liquid compatibility.
-
#to_s ⇒ String
Renders the template with an empty context.
Constructor Details
#initialize(raw, compiled, engine, tagged, inferred) ⇒ TemplatedField
74 75 76 77 78 79 80 |
# File 'lib/sourcerer/templating.rb', line 74 def initialize raw, compiled, engine, tagged, inferred @raw = raw @compiled = compiled @engine = engine @tagged = tagged @inferred = inferred end |
Instance Attribute Details
#compiled ⇒ Object (readonly)
61 62 63 |
# File 'lib/sourcerer/templating.rb', line 61 def compiled @compiled end |
#engine ⇒ String (readonly)
63 64 65 |
# File 'lib/sourcerer/templating.rb', line 63 def engine @engine end |
#inferred ⇒ Boolean (readonly)
67 68 69 |
# File 'lib/sourcerer/templating.rb', line 67 def inferred @inferred end |
#raw ⇒ String (readonly)
59 60 61 |
# File 'lib/sourcerer/templating.rb', line 59 def raw @raw end |
#tagged ⇒ Boolean (readonly)
65 66 67 |
# File 'lib/sourcerer/templating.rb', line 65 def tagged @tagged end |
Instance Method Details
#deferred? ⇒ Boolean
88 89 90 |
# File 'lib/sourcerer/templating.rb', line 88 def deferred? compiled.nil? end |
#render(context = {}) ⇒ String
Renders the template with the given context.
100 101 102 103 |
# File 'lib/sourcerer/templating.rb', line 100 def render context = {} scope = context.respond_to?(:environments) ? context.environments.first : context Engines.render(compiled, engine, scope) end |
#templated? ⇒ true
83 84 85 |
# File 'lib/sourcerer/templating.rb', line 83 def templated? true end |
#to_liquid ⇒ self
93 94 95 |
# File 'lib/sourcerer/templating.rb', line 93 def to_liquid self end |
#to_s ⇒ String
Renders the template with an empty context.
107 108 109 |
# File 'lib/sourcerer/templating.rb', line 107 def to_s render({}) end |