Class: Dandy::TemplateRegistry
- Inherits:
-
Object
- Object
- Dandy::TemplateRegistry
- Defined in:
- lib/dandy/template_registry.rb
Instance Method Summary collapse
- #get(name, type) ⇒ Object
-
#initialize(template_loader, dandy_config, dandy_env) ⇒ TemplateRegistry
constructor
A new instance of TemplateRegistry.
Constructor Details
#initialize(template_loader, dandy_config, dandy_env) ⇒ TemplateRegistry
Returns a new instance of TemplateRegistry.
5 6 7 8 9 10 |
# File 'lib/dandy/template_registry.rb', line 5 def initialize(template_loader, dandy_config, dandy_env) @template_loader = template_loader @templates = template_loader.load_templates @config = dandy_config @dandy_env = dandy_env end |
Instance Method Details
#get(name, type) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dandy/template_registry.rb', line 12 def get(name, type) if @dandy_env == 'development' # every time reload templates in development mode @templates = @template_loader.load_templates end directory = @config[:path][:views] .sub(/^\//, '').sub(/(\/)+$/,'') # remove slash from start and end of the path regex = /#{Regexp.escape(directory)}\/.*#{Regexp.escape(name)}\.#{Regexp.escape(type)}/ match = @templates.keys.find{|k| k.match(regex)} raise Dandy::DandyError, "View \"#{name}\" of type \"#{type}\" not found" if match.nil? @templates[match] end |