Class: Coradoc::Html::TemplateConfig
- Inherits:
-
Object
- Object
- Coradoc::Html::TemplateConfig
- Defined in:
- lib/coradoc/html/template_config.rb
Overview
Configuration for the Liquid template system.
Delegates template lookup to TemplateLocator for consistent behavior across global configuration and per-renderer usage.
Constant Summary collapse
- DEFAULT_TEMPLATE_DIR =
TemplateLocator::DEFAULT_TEMPLATE_DIR
Instance Attribute Summary collapse
-
#template_dirs ⇒ Object
Returns the value of attribute template_dirs.
Class Method Summary collapse
Instance Method Summary collapse
- #all_template_dirs ⇒ Object
- #find_template(name) ⇒ Object
-
#initialize(template_dirs: []) ⇒ TemplateConfig
constructor
A new instance of TemplateConfig.
- #locator ⇒ Object
- #reset! ⇒ Object
- #template_exists?(name) ⇒ Boolean
- #with_dirs(additional_dirs) ⇒ Object
Constructor Details
#initialize(template_dirs: []) ⇒ TemplateConfig
Returns a new instance of TemplateConfig.
21 22 23 |
# File 'lib/coradoc/html/template_config.rb', line 21 def initialize(template_dirs: []) @template_dirs = Array(template_dirs).map { |dir| Pathname.new(dir) } end |
Instance Attribute Details
#template_dirs ⇒ Object
Returns the value of attribute template_dirs.
19 20 21 |
# File 'lib/coradoc/html/template_config.rb', line 19 def template_dirs @template_dirs end |
Class Method Details
.available_templates ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/coradoc/html/template_config.rb', line 33 def self.available_templates @available_templates ||= begin return [] unless DEFAULT_TEMPLATE_DIR.exist? DEFAULT_TEMPLATE_DIR .glob('*.liquid') .map { |f| f.basename('.liquid').to_s.to_sym } .sort end end |
.template_path_for(name) ⇒ Object
44 45 46 47 |
# File 'lib/coradoc/html/template_config.rb', line 44 def self.template_path_for(name) path = DEFAULT_TEMPLATE_DIR.join("#{name}.liquid") path.exist? ? path : nil end |
Instance Method Details
#all_template_dirs ⇒ Object
29 30 31 |
# File 'lib/coradoc/html/template_config.rb', line 29 def all_template_dirs @template_dirs + [DEFAULT_TEMPLATE_DIR] end |
#find_template(name) ⇒ Object
53 54 55 |
# File 'lib/coradoc/html/template_config.rb', line 53 def find_template(name) locator.find(name.to_s) end |
#locator ⇒ Object
25 26 27 |
# File 'lib/coradoc/html/template_config.rb', line 25 def locator @locator ||= TemplateLocator.new(user_dirs: @template_dirs) end |
#reset! ⇒ Object
57 58 59 60 |
# File 'lib/coradoc/html/template_config.rb', line 57 def reset! @template_dirs = [] @locator = nil end |
#template_exists?(name) ⇒ Boolean
49 50 51 |
# File 'lib/coradoc/html/template_config.rb', line 49 def template_exists?(name) locator.exists?(name.to_s) end |
#with_dirs(additional_dirs) ⇒ Object
62 63 64 65 66 |
# File 'lib/coradoc/html/template_config.rb', line 62 def with_dirs(additional_dirs) self.class.new( template_dirs: @template_dirs + Array(additional_dirs).map { |d| Pathname.new(d) } ) end |