Module: Charming::Presentation::Templates
- Defined in:
- lib/charming/presentation/templates.rb,
lib/charming/presentation/templates/erb_handler.rb
Defined Under Namespace
Classes: ErbHandler, ResolvedTemplate
Constant Summary
collapse
- MissingTemplateError =
Class.new(Error)
Class Method Summary
collapse
Class Method Details
.handlers ⇒ Object
32
33
34
|
# File 'lib/charming/presentation/templates.rb', line 32
def handlers
@handlers ||= {}
end
|
.register(extension, handler) ⇒ Object
15
16
17
|
# File 'lib/charming/presentation/templates.rb', line 15
def register(extension, handler)
handlers[extension] = handler
end
|
.resolve(name, root: nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/charming/presentation/templates.rb', line 19
def resolve(name, root: nil)
views_root = File.join(root || Dir.pwd, "app", "views")
searched_paths = candidate_paths(views_root, name.to_s)
searched_paths.each do |path|
next unless File.file?(path)
return ResolvedTemplate.new(path: path, handler: handler_for(path))
end
raise MissingTemplateError, "Missing template #{name.inspect}. Searched: #{searched_paths.join(", ")}"
end
|