diff options
author | wycats <wycats@gmail.com> | 2010-06-04 17:28:04 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-06-04 20:11:06 -0700 |
commit | a6b39428431abeaa0251bbf4b6582e578f81783f (patch) | |
tree | a85e09146a4e046cc69485df35c6b5bcea0bef8e /actionpack/lib/action_view | |
parent | 16ee4b4d1b125bd3edb5c191d58c7afdf6d3232e (diff) | |
download | rails-a6b39428431abeaa0251bbf4b6582e578f81783f.tar.gz rails-a6b39428431abeaa0251bbf4b6582e578f81783f.tar.bz2 rails-a6b39428431abeaa0251bbf4b6582e578f81783f.zip |
Optimize LookupContext
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/lookup_context.rb | 35 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/handlers.rb | 2 |
3 files changed, 27 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index f4af763afe..16d7d25279 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -201,6 +201,7 @@ module ActionView #:nodoc: end def self.process_view_paths(value) + return value.dup if value.is_a?(PathSet) ActionView::PathSet.new(Array.wrap(value)) end diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 7021342b4a..801b08b19d 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -13,8 +13,12 @@ module ActionView mattr_accessor :registered_details self.registered_details = [] + mattr_accessor :registered_detail_setters + self.registered_detail_setters = [] + def self.register_detail(name, options = {}, &block) self.registered_details << name + self.registered_detail_setters << [name, "#{name}="] Accessors.send :define_method, :"_#{name}_defaults", &block Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} @@ -60,7 +64,7 @@ module ActionView @details, @details_key = { :handlers => default_handlers }, nil @frozen_formats, @skip_default_locale = false, false self.view_paths = view_paths - self.update_details(details, true) + self.initialize_details(details) end module ViewPaths @@ -116,11 +120,11 @@ module ActionView end def default_handlers #:nodoc: - @default_handlers ||= Template::Handlers.extensions + @@default_handlers ||= Template::Handlers.extensions end def handlers_regexp #:nodoc: - @handlers_regexp ||= /\.(?:#{default_handlers.join('|')})$/ + @@handlers_regexp ||= /\.(?:#{default_handlers.join('|')})$/ end end @@ -141,10 +145,13 @@ module ActionView end # Overload formats= to reject [:"*/*"] values. - def formats=(value) - value = nil if value == [:"*/*"] - value << :html if value == [:js] - super(value) + def formats=(values) + if values && values.size == 1 + value = values.first + values = nil if value == :"*/*" + values << :html if value == :js + end + super(values) end # Do not use the default locale on template lookup. @@ -170,14 +177,22 @@ module ActionView super(@skip_default_locale ? I18n.locale : _locale_defaults) end + def initialize_details(details) + details = details.dup + + registered_detail_setters.each do |key, setter| + send(setter, details[key]) + end + end + # Update the details keys by merging the given hash into the current # details hash. If a block is given, the details are modified just during # the execution of the block and reverted to the previous value after. - def update_details(new_details, force=false) + def update_details(new_details) old_details = @details.dup - registered_details.each do |key| - send(:"#{key}=", new_details[key]) if force || new_details.key?(key) + registered_detail_setters.each do |key, setter| + send(setter, new_details[key]) if new_details.key?(key) end if block_given? diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index 35488c0391..6228d7ac39 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -19,7 +19,7 @@ module ActionView #:nodoc: @@default_template_handlers = nil def self.extensions - @@template_handlers.keys + @@template_extensions ||= @@template_handlers.keys end # Register a class that knows how to handle template files with the given |