class ActionView::Resolver
Action View Resolver
¶ ↑
Public Class Methods
new()
click to toggle source
# File lib/action_view/template/resolver.rb, line 136 def initialize @cache = Cache.new end
Public Instance Methods
clear_cache()
click to toggle source
# File lib/action_view/template/resolver.rb, line 140 def clear_cache @cache.clear end
find_all(name, prefix = nil, partial = false, details = {}, key = nil, locals = [])
click to toggle source
Normalizes the arguments and passes it on to find_templates.
# File lib/action_view/template/resolver.rb, line 145 def find_all(name, prefix = nil, partial = false, details = {}, key = nil, locals = []) cached(key, [name, prefix, partial], details, locals) do find_templates(name, prefix, partial, details) end end
find_all_anywhere(name, prefix, partial = false, details = {}, key = nil, locals = [])
click to toggle source
# File lib/action_view/template/resolver.rb, line 151 def find_all_anywhere(name, prefix, partial = false, details = {}, key = nil, locals = []) cached(key, [name, prefix, partial], details, locals) do find_templates(name, prefix, partial, details, true) end end
Private Instance Methods
build_path(name, prefix, partial)
click to toggle source
Helpers
that builds a path. Useful for building virtual paths.
# File lib/action_view/template/resolver.rb, line 173 def build_path(name, prefix, partial) Path.build(name, prefix, partial) end
cached(key, path_info, details, locals) { || ... }
click to toggle source
Handles templates caching. If a key is given and caching is on always check the cache before hitting the resolver. Otherwise, it always hits the resolver but if the key is present, check if the resolver is fresher before returning it.
# File lib/action_view/template/resolver.rb, line 181 def cached(key, path_info, details, locals) name, prefix, partial = path_info locals = locals.map(&:to_s).sort! if key @cache.cache(key, name, prefix, partial, locals) do decorate(yield, path_info, details, locals) end else decorate(yield, path_info, details, locals) end end
decorate(templates, path_info, details, locals)
click to toggle source
Ensures all the resolver information is set in the template.
# File lib/action_view/template/resolver.rb, line 195 def decorate(templates, path_info, details, locals) cached = nil templates.each do |t| t.locals = locals t.formats = details[:formats] || [:html] if t.formats.empty? t.variants = details[:variants] || [] if t.variants.empty? t.virtual_path ||= (cached ||= build_path(*path_info)) end end
find_templates(name, prefix, partial, details, outside_app_allowed = false)
click to toggle source
This is what child classes implement. No defaults are needed because Resolver
guarantees that the arguments are present and normalized.
# File lib/action_view/template/resolver.rb, line 168 def find_templates(name, prefix, partial, details, outside_app_allowed = false) raise NotImplementedError, "Subclasses must implement a find_templates(name, prefix, partial, details, outside_app_allowed = false) method" end