class ActionView::LookupContext
:nodoc:
this key is generated just once during the request, it speeds up all cache accesses.
generate a key, given to view paths, used in the resolver cache lookup. Since
templates, i.e. view paths and details. The LookupContext is also responsible to
LookupContext is the object responsible to hold all information required to lookup
= Action View Lookup Context
def self.register_detail(name, options = {}, &block)
def self.register_detail(name, options = {}, &block) self.registered_details << name initialize = registered_details.map { |n| "@details[:#{n}] = details[:#{n}] || default_#{n}" } Accessors.send :define_method, :"default_#{name}", &block Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} @details.fetch(:#{name}, []) end def #{name}=(value) value = value.present? ? Array(value) : default_#{name} _set_detail(:#{name}, value) if value != @details[:#{name}] end remove_possible_method :initialize_details def initialize_details(details) #{initialize.join("\n")} end METHOD end
def formats=(values)
Override formats= to expand ["*/*"] values and automatically
def formats=(values) if values values.concat(default_formats) if values.delete "*/*" if values == [: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, @details_key = {}, nil @skip_default_locale = false @cache = true @prefixes = prefixes @rendered_format = nil self.view_paths = view_paths initialize_details(details) 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(@skip_default_locale ? I18n.locale : default_locale) end
def skip_default_locale!
def skip_default_locale! @skip_default_locale = true self.locale = nil end
def with_layout_format
def with_layout_format if formats.size == 1 yield else old_formats = formats _set_detail(:formats, formats[0,1]) begin yield ensure _set_detail(:formats, old_formats) end end end