Class: Cutaneous::Engine
- Inherits:
-
Object
- Object
- Cutaneous::Engine
- Defined in:
- lib/cutaneous/engine.rb
Overview
Manages a set of Loaders that render templates
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_format ⇒ Object
Returns the value of attribute default_format.
-
#loader_class ⇒ Object
Returns the value of attribute loader_class.
-
#roots ⇒ Object
readonly
Returns the value of attribute roots.
Instance Method Summary collapse
- #convert(template, to_syntax, format = default_format) ⇒ Object
- #convert_string(template_string, to_syntax, format = default_format) ⇒ Object
- #dynamic_template?(template_string) ⇒ Boolean
-
#file_loader(format) ⇒ Object
Create and cache a file loader on a per-format basis.
-
#initialize(template_roots, syntax = Cutaneous::FirstPassSyntax, default_format = "html") ⇒ Engine
constructor
A new instance of Engine.
- #proc_template(template_string) ⇒ Object
- #render_file(path, context, format = default_format) ⇒ Object (also: #render)
-
#render_string(template_string, context, format = default_format) ⇒ Object
need an explicit #render_string method so it’s possible to distinguish between a String which is a path to a template & a String which is a template itself.
- #template_exists?(relative_path, format) ⇒ Boolean
- #template_location(relative_path, format) ⇒ Object
Constructor Details
#initialize(template_roots, syntax = Cutaneous::FirstPassSyntax, default_format = "html") ⇒ Engine
Returns a new instance of Engine.
8 9 10 11 12 13 |
# File 'lib/cutaneous/engine.rb', line 8 def initialize(template_roots, syntax = Cutaneous::FirstPassSyntax, default_format = "html") @roots = Array(template_roots) @syntax = syntax @loader_class = FileLoader @default_format = default_format end |
Instance Attribute Details
#default_format ⇒ Object
Returns the value of attribute default_format.
6 7 8 |
# File 'lib/cutaneous/engine.rb', line 6 def default_format @default_format end |
#loader_class ⇒ Object
Returns the value of attribute loader_class.
6 7 8 |
# File 'lib/cutaneous/engine.rb', line 6 def loader_class @loader_class end |
#roots ⇒ Object (readonly)
Returns the value of attribute roots.
5 6 7 |
# File 'lib/cutaneous/engine.rb', line 5 def roots @roots end |
Instance Method Details
#convert(template, to_syntax, format = default_format) ⇒ Object
55 56 57 |
# File 'lib/cutaneous/engine.rb', line 55 def convert(template, to_syntax, format = default_format) file_loader(format).convert(template, to_syntax) end |
#convert_string(template_string, to_syntax, format = default_format) ⇒ Object
59 60 61 |
# File 'lib/cutaneous/engine.rb', line 59 def convert_string(template_string, to_syntax, format = default_format) convert(proc_template(template_string), to_syntax, format) end |
#dynamic_template?(template_string) ⇒ Boolean
51 52 53 |
# File 'lib/cutaneous/engine.rb', line 51 def dynamic_template?(template_string) @syntax.is_dynamic?(template_string) end |
#file_loader(format) ⇒ Object
Create and cache a file loader on a per-format basis
29 30 31 32 33 |
# File 'lib/cutaneous/engine.rb', line 29 def file_loader(format) file_loader_instance(format.to_sym).tap do |loader| loader.syntax = @syntax end end |
#proc_template(template_string) ⇒ Object
63 64 65 |
# File 'lib/cutaneous/engine.rb', line 63 def proc_template(template_string) Proc.new { template_string } end |
#render_file(path, context, format = default_format) ⇒ Object Also known as: render
15 16 17 |
# File 'lib/cutaneous/engine.rb', line 15 def render_file(path, context, format = default_format) file_loader(format).render(path, context) end |
#render_string(template_string, context, format = default_format) ⇒ Object
need an explicit #render_string method so it’s possible to distinguish between a String which is a path to a template & a String which is a template itself.
24 25 26 |
# File 'lib/cutaneous/engine.rb', line 24 def render_string(template_string, context, format = default_format) render_file(proc_template(template_string), context, format) end |