Class: WLang::Template
- Inherits:
-
Object
- Object
- WLang::Template
- Defined in:
- lib/wlang/template.rb
Instance Attribute Summary collapse
-
#compiled ⇒ Object
readonly
Returns the value of attribute compiled.
-
#compiler ⇒ Object
readonly
The underlying template compiler.
-
#dialect ⇒ Object
readonly
The dialect class to use.
-
#dialect_instance ⇒ Object
readonly
Returns the value of attribute dialect_instance.
-
#options ⇒ Object
readonly
Compilation options for the template, as initially passed to ‘new`.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #call(*args) ⇒ Object (also: #render)
-
#initialize(source, options = {}) ⇒ Template
constructor
Creates a template instance.
- #locals ⇒ Object
- #path ⇒ Object
- #template_content ⇒ Object
- #to_ast ⇒ Object
- #to_ruby_code ⇒ Object
- #to_ruby_proc ⇒ Object
Constructor Details
#initialize(source, options = {}) ⇒ Template
Creates a template instance
14 15 16 17 18 19 20 21 |
# File 'lib/wlang/template.rb', line 14 def initialize(source, = {}) @options = @dialect = @options.delete(:dialect) || WLang::Html @dialect_instance = @dialect.new(, self) @compiler = Compiler.new(dialect_instance) @source = Source.new(source, self).with_front_matter(yaml_front_matter?) @compiled = to_ruby_proc end |
Instance Attribute Details
#compiled ⇒ Object (readonly)
Returns the value of attribute compiled.
54 55 56 |
# File 'lib/wlang/template.rb', line 54 def compiled @compiled end |
#compiler ⇒ Object (readonly)
The underlying template compiler
11 12 13 |
# File 'lib/wlang/template.rb', line 11 def compiler @compiler end |
#dialect ⇒ Object (readonly)
The dialect class to use
8 9 10 |
# File 'lib/wlang/template.rb', line 8 def dialect @dialect end |
#dialect_instance ⇒ Object (readonly)
Returns the value of attribute dialect_instance.
54 55 56 |
# File 'lib/wlang/template.rb', line 54 def dialect_instance @dialect_instance end |
#options ⇒ Object (readonly)
Compilation options for the template, as initially passed to ‘new`
5 6 7 |
# File 'lib/wlang/template.rb', line 5 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
54 55 56 |
# File 'lib/wlang/template.rb', line 54 def source @source end |
Instance Method Details
#call(*args) ⇒ Object Also known as: render
47 48 49 50 |
# File 'lib/wlang/template.rb', line 47 def call(*args) scope, buffer = call_args_conventions(args) dialect_instance.dup.render compiled, scope, buffer end |
#locals ⇒ Object
27 28 29 |
# File 'lib/wlang/template.rb', line 27 def locals @source.locals end |
#path ⇒ Object
23 24 25 |
# File 'lib/wlang/template.rb', line 23 def path @options[:path] || @source.path end |
#template_content ⇒ Object
31 32 33 |
# File 'lib/wlang/template.rb', line 31 def template_content @source.template_content end |
#to_ast ⇒ Object
43 44 45 |
# File 'lib/wlang/template.rb', line 43 def to_ast compiler.to_ast(template_content) end |
#to_ruby_code ⇒ Object
39 40 41 |
# File 'lib/wlang/template.rb', line 39 def to_ruby_code compiler.to_ruby_code(template_content) end |
#to_ruby_proc ⇒ Object
35 36 37 |
# File 'lib/wlang/template.rb', line 35 def to_ruby_proc compiler.to_ruby_proc(template_content) end |