Class: Silicon::TemplateRegistry
- Inherits:
-
Object
- Object
- Silicon::TemplateRegistry
- Defined in:
- lib/silicon/template_registry.rb
Instance Method Summary collapse
- #get(name, type) ⇒ Object
-
#initialize(template_loader, silicon_config, silicon_env) ⇒ TemplateRegistry
constructor
A new instance of TemplateRegistry.
Constructor Details
#initialize(template_loader, silicon_config, silicon_env) ⇒ TemplateRegistry
Returns a new instance of TemplateRegistry.
3 4 5 6 7 8 |
# File 'lib/silicon/template_registry.rb', line 3 def initialize(template_loader, silicon_config, silicon_env) @template_loader = template_loader @templates = template_loader.load_templates @config = silicon_config @silicon_env = silicon_env end |
Instance Method Details
#get(name, type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/silicon/template_registry.rb', line 10 def get(name, type) if @silicon_env == 'development' # every time reload templates in development mode @templates = @template_loader.load_templates end directory = @config[:path][:views] template_path = File.join(directory, name + ".#{type}") match = @templates.keys.find{|k| k.include? template_path} raise Silicon::SiliconError, "View #{name} of type #{type} not found" if match.nil? @templates[match] end |