Class: Roger::Template
- Inherits:
-
BlankTemplate
- Object
- BlankTemplate
- Roger::Template
- Defined in:
- lib/roger/template.rb,
lib/roger/template/helpers/capture.rb,
lib/roger/template/helpers/partial.rb,
lib/roger/template/template_context.rb,
lib/roger/template/helpers/rendering.rb
Overview
Roger template processing class
Defined Under Namespace
Modules: Helpers Classes: TemplateContext
Instance Attribute Summary collapse
-
#current_tilt_template ⇒ Object
readonly
The current tilt template being used.
-
#data ⇒ Object
Store the frontmatter.
-
#source ⇒ Object
The source.
-
#source_path ⇒ Object
The path to the source file for this template.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, context = nil, options = {}) ⇒ Template
constructor
A new instance of Template.
-
#real_source_path ⇒ Object
Actual path on disk, nil if it doesn’t exist The nil case is mostly used with inline rendering.
- #render(locals = {}, &block) ⇒ Object
Constructor Details
#initialize(source, context = nil, options = {}) ⇒ Template
Returns a new instance of Template.
41 42 43 44 45 46 47 48 |
# File 'lib/roger/template.rb', line 41 def initialize(source, context = nil, = {}) @context = context self.source_path = [:source_path] self.data, self.source = extract_front_matter(source) @templates = Tilt.templates_for(source_path) end |
Instance Attribute Details
#current_tilt_template ⇒ Object (readonly)
The current tilt template being used
31 32 33 |
# File 'lib/roger/template.rb', line 31 def current_tilt_template @current_tilt_template end |
#data ⇒ Object
Store the frontmatter
25 26 27 |
# File 'lib/roger/template.rb', line 25 def data @data end |
#source ⇒ Object
The source
22 23 24 |
# File 'lib/roger/template.rb', line 22 def source @source end |
#source_path ⇒ Object
The path to the source file for this template
28 29 30 |
# File 'lib/roger/template.rb', line 28 def source_path @source_path end |
Class Method Details
.open(path, context = nil, options = {}) ⇒ Object
34 35 36 |
# File 'lib/roger/template.rb', line 34 def open(path, context = nil, = {}) new(File.read(path), context, .update(source_path: path)) end |
Instance Method Details
#real_source_path ⇒ Object
Actual path on disk, nil if it doesn’t exist The nil case is mostly used with inline rendering.
58 59 60 61 62 63 64 65 |
# File 'lib/roger/template.rb', line 58 def real_source_path return @_real_source_path if @_real_source_path_cached @_real_source_path_cached = true @_real_source_path = if File.exist?(source_path) Pathname.new(source_path).realpath end end |
#render(locals = {}, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/roger/template.rb', line 50 def render(locals = {}, &block) @templates.inject(source) do |src, template| render_with_tilt_template(template, src, locals, &block) end end |