Class: Hx::Output::LiquidTemplate
- Inherits:
-
Object
- Object
- Hx::Output::LiquidTemplate
- Includes:
- Filter
- Defined in:
- lib/hx/output/liquidtemplate.rb
Defined Under Namespace
Modules: TextFilters Classes: TemplateSource
Instance Method Summary collapse
- #each_entry_path(selector) ⇒ Object
- #get_entry(path) ⇒ Object
-
#initialize(input, options) ⇒ LiquidTemplate
constructor
A new instance of LiquidTemplate.
Methods included from Filter
Methods included from View
Constructor Details
#initialize(input, options) ⇒ LiquidTemplate
Returns a new instance of LiquidTemplate.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hx/output/liquidtemplate.rb', line 85 def initialize(input, ) @input = input @options = {} for key, value in @options[key.to_s] = value end begin LiquidTemplate.const_get(:TEMPLATE_SOURCE) rescue NameError # use filter cache to avoid template re-parse # (doesn't help with partials yet) template_source = Cache.new(TemplateSource.new()) LiquidTemplate.const_set(:TEMPLATE_SOURCE, template_source) end @template_name = [:template] # force early failure in case of a missing template TEMPLATE_SOURCE.get_entry(@template_name) @extension = [:extension] @content_type = [:content_type] @strip_extension_re = nil @strip_extension_re = /\.#{Regexp.quote(@extension)}$/ if @extension end |
Instance Method Details
#each_entry_path(selector) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/hx/output/liquidtemplate.rb', line 108 def each_entry_path(selector) @input.each_entry_path(Path::ALL) do |path| path = "#{path}.#{@extension}" unless @extension.nil? yield path if selector.accept_path? path end self end |
#get_entry(path) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/hx/output/liquidtemplate.rb', line 116 def get_entry(path) path = path.sub(@strip_extension_re, '') if @strip_extension_re entry = @input.get_entry(path) output_entry = {} template = TEMPLATE_SOURCE.get_entry(@template_name)["template"] output_entry['content'] = Hx::LazyContent.new do template.render( 'now' => Time.now, 'options' => @options, 'path' => path, 'entry' => entry ) end output_entry['content_type'] = @content_type if @content_type if entry.has_key? 'updated' output_entry['created'] = output_entry['updated'] = entry['updated'] end output_entry end |