Class: ActionView::LookupContext
- Inherits:
-
Object
- Object
- ActionView::LookupContext
- Includes:
- Accessors, DetailsCache, ViewPaths
- Defined in:
- lib/action_view/lookup_context.rb
Overview
Action View Lookup Context
LookupContext
is the object responsible for holding all information required for looking up templates, i.e. view paths and details. LookupContext
is also responsible for generating a key, given to view paths, used in the resolver cache lookup. Since this key is generated only once during the request, it speeds up all cache accesses.
Defined Under Namespace
Modules: Accessors, DetailsCache, ViewPaths Classes: DetailsKey
Constant Summary
Constants included from Accessors
Instance Attribute Summary collapse
-
#prefixes ⇒ Object
:nodoc:.
-
#rendered_format ⇒ Object
:nodoc:.
Attributes included from ViewPaths
#html_fallback_for_js, #view_paths
Attributes included from DetailsCache
Class Method Summary collapse
Instance Method Summary collapse
- #digest_cache ⇒ Object
-
#formats=(values) ⇒ Object
Override formats= to expand [“/”] values and automatically add :html as fallback to :js.
-
#initialize(view_paths, details = {}, prefixes = []) ⇒ LookupContext
constructor
A new instance of LookupContext.
-
#locale ⇒ Object
Override locale to return a symbol instead of array.
-
#locale=(value) ⇒ Object
Overload locale= to also set the I18n.locale.
Methods included from ViewPaths
#any?, #exists?, #find, #find_all, #find_file, #with_fallbacks
Methods included from DetailsCache
Constructor Details
#initialize(view_paths, details = {}, prefixes = []) ⇒ LookupContext
Returns a new instance of LookupContext.
222 223 224 225 226 227 228 229 230 |
# File 'lib/action_view/lookup_context.rb', line 222 def initialize(view_paths, details = {}, prefixes = []) @details_key = nil @cache = true @prefixes = prefixes @rendered_format = nil @details = initialize_details({}, details) self.view_paths = view_paths end |
Instance Attribute Details
#prefixes ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/action_view/lookup_context.rb', line 17 def prefixes @prefixes end |
#rendered_format ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/action_view/lookup_context.rb', line 17 def rendered_format @rendered_format end |
Class Method Details
.register_detail(name, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_view/lookup_context.rb', line 23 def self.register_detail(name, &block) registered_details << name Accessors::DEFAULT_PROCS[name] = block 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 METHOD end |
Instance Method Details
#digest_cache ⇒ Object
232 233 234 |
# File 'lib/action_view/lookup_context.rb', line 232 def digest_cache details_key end |
#formats=(values) ⇒ Object
Override formats= to expand [“/”] values and automatically add :html as fallback to :js.
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/action_view/lookup_context.rb', line 246 def formats=(values) if values values.concat(default_formats) if values.delete "*/*".freeze if values == [:js] values << :html @html_fallback_for_js = true end end super(values) end |
#locale ⇒ Object
Override locale to return a symbol instead of array.
258 259 260 |
# File 'lib/action_view/lookup_context.rb', line 258 def locale @details[:locale].first end |
#locale=(value) ⇒ Object
Overload locale= to also set the I18n.locale. If the current I18n.config object responds to original_config, it means that it has a copy of the original I18n configuration and it's acting as proxy, which we need to skip.
265 266 267 268 269 270 271 272 |
# File 'lib/action_view/lookup_context.rb', line 265 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 |