class ActionView::LookupContext
:nodoc:
only once during the request, it speeds up all cache accesses.
view paths, used in the resolver cache lookup. Since this key is generatedLookupContext
is also responsible for generating a key, given to
required for looking up templates, i.e. view paths and details.LookupContext
is the object responsible for holding all information
= Action View Lookup Context
def self.register_detail(name, &block)
def self.register_detail(name, &block) registered_details << name Accessors::DEFAULT_PROCS[name] = block Accessors.define_method(:"default_#{name}", &block) Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} @details[:#{name}] || [] end def #{name}=(value) value = value.present? ? Array(value) : default_#{name} _set_detail(:#{name}, value) if value != @details[:#{name}] end METHOD end
def digest_cache
def digest_cache @digest_cache ||= DetailsKey.digest_cache(@details) end
def formats=(values)
Override formats= to expand ["*/*"] values and automatically
def formats=(values) if values values = values.dup values.concat(default_formats) if values.delete "*/*" values.uniq! unless Template::Types.valid_symbols?(values) invalid_values = values - Template::Types.symbols raise ArgumentError, "Invalid formats: #{invalid_values.map(&:inspect).join(", ")}" end if (values.length == 1) && (values[0] == :js) values << :html @html_fallback_for_js = true end end super(values) end
def initialize(view_paths, details = {}, prefixes = [])
def initialize(view_paths, details = {}, prefixes = []) @details_key = nil @digest_cache = nil @cache = true @prefixes = prefixes @details = initialize_details({}, details) @view_paths = build_view_paths(view_paths) end
def initialize_details(target, details)
def initialize_details(target, details) LookupContext.registered_details.each do |k| target[k] = details[k] || Accessors::DEFAULT_PROCS[k].call end target end
def locale
def locale @details[:locale].first end
def locale=(value)
to original_config, it means that it has a copy of the original I18n configuration and it's
Overload locale= to also set the I18n.locale. If the current I18n.config object responds
def locale=(value) if value config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config config.locale = value end super(default_locale) end
def with_prepended_formats(formats)
def with_prepended_formats(formats) details = @details.dup details[:formats] = formats self.class.new(@view_paths, details, @prefixes) end