From ff5f155f8dc1d2ba363718c3e17f99719399eab5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Jun 2008 20:05:39 -0700 Subject: Use output_buffer reader and writer methods exclusively instead of hitting the instance variable so others can override the methods. --- actionpack/lib/action_view/helpers/capture_helper.rb | 6 +++--- actionpack/lib/action_view/helpers/javascript_helper.rb | 5 ----- actionpack/lib/action_view/helpers/tag_helper.rb | 4 ---- actionpack/lib/action_view/helpers/text_helper.rb | 4 ++-- actionpack/lib/action_view/template_handlers/compilable.rb | 2 +- actionpack/lib/action_view/test_case.rb | 5 +++++ 6 files changed, 11 insertions(+), 15 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 25e62f78fb..ab453fadf2 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -31,7 +31,7 @@ module ActionView # # def capture(*args, &block) - if @output_buffer + if output_buffer with_output_buffer { block.call(*args) } else block.call(*args) @@ -121,10 +121,10 @@ module ActionView private def with_output_buffer(buf = '') - @output_buffer, old_buffer = buf, @output_buffer + self.output_buffer, old_buffer = buf, output_buffer yield ensure - @output_buffer = old_buffer + self.output_buffer = old_buffer end end end diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 85b205c264..7404a251e4 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -202,11 +202,6 @@ module ActionView end js_option end - - private - def block_is_within_action_view?(block) - !@output_buffer.nil? - end end JavascriptHelper = JavaScriptHelper unless const_defined? :JavascriptHelper diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index a8a5987b1f..e1abec1847 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -122,10 +122,6 @@ module ActionView " #{attrs.sort * ' '}" unless attrs.empty? end end - - def block_is_within_action_view?(block) - !@output_buffer.nil? - end end end end diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index f81f7eded6..85a3672678 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -26,8 +26,8 @@ module ActionView # # will either display "Logged in!" or a login link # %> def concat(string) - if @output_buffer && string - @output_buffer << string + if output_buffer && string + output_buffer << string else string end diff --git a/actionpack/lib/action_view/template_handlers/compilable.rb b/actionpack/lib/action_view/template_handlers/compilable.rb index 28c72172a0..1aef81ba1a 100644 --- a/actionpack/lib/action_view/template_handlers/compilable.rb +++ b/actionpack/lib/action_view/template_handlers/compilable.rb @@ -106,7 +106,7 @@ module ActionView locals_code << "#{key} = local_assigns[:#{key}]\n" end - "def #{render_symbol}(local_assigns)\nold_output_buffer = @output_buffer;#{locals_code}#{body}\nensure\n@output_buffer = old_output_buffer\nend" + "def #{render_symbol}(local_assigns)\nold_output_buffer = output_buffer;#{locals_code}#{body}\nensure\nself.output_buffer = old_output_buffer\nend" end # Return true if the given template was compiled for a superset of the keys in local_assigns diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 16fedd9732..1a3c93c283 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -37,6 +37,8 @@ module ActionView if helper_class && !self.class.ancestors.include?(helper_class) self.class.send(:include, helper_class) end + + self.output_buffer = '' end class TestController < ActionController::Base @@ -48,6 +50,9 @@ module ActionView end end + protected + attr_accessor :output_buffer + private def method_missing(selector, *args) controller = TestController.new -- cgit v1.2.3 From 0c9281e82140f3a69e4473b3bcefd5ccebd79e2d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 8 Jun 2008 22:11:08 -0500 Subject: Drop ActionController::Base.allow_concurrency flag --- actionpack/lib/action_controller/base.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a036600c2b..44269fc735 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -283,13 +283,6 @@ module ActionController #:nodoc: @@debug_routes = true cattr_accessor :debug_routes - # Indicates to Mongrel or Webrick whether to allow concurrent action - # processing. Your controller actions and any other code they call must - # also behave well when called from concurrent threads. Turned off by - # default. - @@allow_concurrency = false - cattr_accessor :allow_concurrency - # Modern REST web services often need to submit complex data to the web application. # The @@param_parsers hash lets you register handlers which will process the HTTP body and add parameters to the # params hash. These handlers are invoked for POST and PUT requests. -- cgit v1.2.3 From df44df945d6315238e7d94d9bdef82e435dc9b24 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 8 Jun 2008 22:31:54 -0500 Subject: Ensure ActionView::TemplateFinder view cache is rebuilt on initialize. --- actionpack/lib/action_controller/dispatcher.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index fe4f6b4a7e..64553fb25d 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -10,6 +10,10 @@ module ActionController # Development mode callbacks before_dispatch :reload_application after_dispatch :cleanup_application + + to_prepare :reload_view_path_cache do + ActionView::TemplateFinder.reload! unless ActionView::Base.cache_template_loading + end end # Common callbacks @@ -134,7 +138,6 @@ module ActionController run_callbacks :prepare_dispatch Routing::Routes.reload - ActionView::TemplateFinder.reload! unless ActionView::Base.cache_template_loading end # Cleanup the application by clearing out loaded classes so they can -- cgit v1.2.3 From c88f2b5e23b0cb6c1a3b3687958f45d518414041 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Jun 2008 20:35:14 -0700 Subject: with_output_buffer returns the temporary buffer instead of the result of the block --- actionpack/lib/action_view/helpers/capture_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index ab453fadf2..9cd9d3d06a 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -123,6 +123,7 @@ module ActionView def with_output_buffer(buf = '') self.output_buffer, old_buffer = buf, output_buffer yield + output_buffer ensure self.output_buffer = old_buffer end -- cgit v1.2.3 From 057768cd2c8541f9c466131cb6c77f13ce12204d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Jun 2008 21:21:54 -0700 Subject: Process view paths passed to AV::Base#initialize instead of raising. --- actionpack/lib/action_view/template_finder.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb index 83b7e27c09..fc2a07b30c 100644 --- a/actionpack/lib/action_view/template_finder.rb +++ b/actionpack/lib/action_view/template_finder.rb @@ -1,14 +1,5 @@ module ActionView #:nodoc: class TemplateFinder #:nodoc: - - class InvalidViewPath < StandardError #:nodoc: - attr_reader :unprocessed_path - def initialize(path) - @unprocessed_path = path - super("Unprocessed view path found: #{@unprocessed_path.inspect}. Set your view paths with #append_view_path, #prepend_view_path, or #view_paths=.") - end - end - cattr_reader :processed_view_paths @@processed_view_paths = Hash.new {|hash, key| hash[key] = []} @@ -76,7 +67,7 @@ module ActionView #:nodoc: @view_paths = args.flatten @view_paths = @view_paths.respond_to?(:find) ? @view_paths.dup : [*@view_paths].compact - check_view_paths(@view_paths) + self.class.process_view_paths(@view_paths) end def prepend_view_path(path) -- cgit v1.2.3 From 55791c6c0012d0daea2a75b6a5927f459be25c54 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Jun 2008 10:05:02 -0500 Subject: Removed used check_view_paths after 057768c --- actionpack/lib/action_view/template_finder.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb index fc2a07b30c..cd5e290644 100644 --- a/actionpack/lib/action_view/template_finder.rb +++ b/actionpack/lib/action_view/template_finder.rb @@ -157,12 +157,5 @@ module ActionView #:nodoc: def find_template_extension_from_first_render File.basename(@template.first_render.to_s)[/^[^.]+\.(.+)$/, 1] end - - private - def check_view_paths(view_paths) - view_paths.each do |path| - raise InvalidViewPath.new(path) unless @@processed_view_paths.has_key?(path) - end - end end end -- cgit v1.2.3 From 233643047104131565467787d0bbc0841bbc77cb Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Jun 2008 10:21:30 -0500 Subject: Removed TemplateFinder.update_extension_cache_for since view path cache will be updated on boot. --- actionpack/lib/action_view/template.rb | 1 - actionpack/lib/action_view/template_finder.rb | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 369526188f..a878ac66d9 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -99,7 +99,6 @@ module ActionView #:nodoc: # return the rendered template as a string. def self.register_template_handler(extension, klass) @@template_handlers[extension.to_sym] = klass - TemplateFinder.update_extension_cache_for(extension.to_s) end def self.template_handler_extensions diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb index cd5e290644..7e9a310810 100644 --- a/actionpack/lib/action_view/template_finder.rb +++ b/actionpack/lib/action_view/template_finder.rb @@ -9,7 +9,6 @@ module ActionView #:nodoc: } class << self #:nodoc: - # This method is not thread safe. Mutex should be used whenever this is accessed from an instance method def process_view_paths(*view_paths) view_paths.flatten.compact.each do |dir| @@ -26,7 +25,7 @@ module ActionView #:nodoc: # Build extension cache extension = file.split(".").last - if template_handler_extensions.include?(extension) + if ActionView::Template.template_handler_extensions.include?(extension) key = file.split(dir).last.sub(/^\//, '').sub(/\.(\w+)$/, '') @@file_extension_cache[dir][key] << extension end @@ -35,19 +34,6 @@ module ActionView #:nodoc: end end - def update_extension_cache_for(extension) - @@processed_view_paths.keys.each do |dir| - Dir.glob("#{dir}/**/*.#{extension}").each do |file| - key = file.split(dir).last.sub(/^\//, '').sub(/\.(\w+)$/, '') - @@file_extension_cache[dir][key] << extension - end - end - end - - def template_handler_extensions - ActionView::Template.template_handler_extensions - end - def reload! view_paths = @@processed_view_paths.keys -- cgit v1.2.3 From f545e19692c84eeaa8de38319766b5ceed1768c1 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 9 Jun 2008 12:06:23 -0400 Subject: add deprecation for the #concat helper's 2nd argument, which is no longer needed --- actionpack/lib/action_view/helpers/text_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 85a3672678..a1a91f6b3d 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -25,7 +25,11 @@ module ActionView # end # # will either display "Logged in!" or a login link # %> - def concat(string) + def concat(string, unused_binding = nil) + if unused_binding + ActiveSupport::Deprecation.warn("The binding argument of #concat is no longer needed. Please remove it from your views and helpers.") + end + if output_buffer && string output_buffer << string else -- cgit v1.2.3 From 19895f087c338d8385dff9d272d30fb87cb10330 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 10 Jun 2008 10:29:25 +0100 Subject: Lazy load cache and session stores --- actionpack/lib/action_controller/session_management.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/session_management.rb b/actionpack/lib/action_controller/session_management.rb index 80a3ddd2c5..ad1013b379 100644 --- a/actionpack/lib/action_controller/session_management.rb +++ b/actionpack/lib/action_controller/session_management.rb @@ -1,10 +1,3 @@ -require 'action_controller/session/cookie_store' -require 'action_controller/session/drb_store' -require 'action_controller/session/mem_cache_store' -if Object.const_defined?(:ActiveRecord) - require 'action_controller/session/active_record_store' -end - module ActionController #:nodoc: module SessionManagement #:nodoc: def self.included(base) @@ -22,6 +15,8 @@ module ActionController #:nodoc: # :p_store, :drb_store, :mem_cache_store, or # :memory_store) or your own custom class. def session_store=(store) + require "action_controller/session/#{store.to_s}" if [:active_record_store, :drb_store, :mem_cache_store].include?(store) + ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] = store.is_a?(Symbol) ? CGI::Session.const_get(store == :drb_store ? "DRbStore" : store.to_s.camelize) : store end -- cgit v1.2.3 From 0ad0bdc01c4fe2d66dd2b405433186824e7ce136 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 10 Jun 2008 23:53:30 +0100 Subject: Delegate ActionView::Base#controller_name to controller --- actionpack/lib/action_view/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index eeebf335dc..c417cc07ac 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -184,7 +184,7 @@ module ActionView #:nodoc: attr_internal :request delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers, - :flash, :logger, :action_name, :to => :controller + :flash, :logger, :action_name, :controller_name, :to => :controller module CompiledTemplates #:nodoc: # holds compiled template code -- cgit v1.2.3 From e8a0ba4c93e2f0f811675bc6a6720725c866d1a5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 10 Jun 2008 20:38:18 -0500 Subject: Ensure view path cache is rebuilt in production mode which was broke by df44df9. --- actionpack/lib/action_controller/dispatcher.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index 64553fb25d..f20d9cc40f 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -10,10 +10,6 @@ module ActionController # Development mode callbacks before_dispatch :reload_application after_dispatch :cleanup_application - - to_prepare :reload_view_path_cache do - ActionView::TemplateFinder.reload! unless ActionView::Base.cache_template_loading - end end # Common callbacks @@ -25,6 +21,10 @@ module ActionController end end + to_prepare :reload_view_path_cache do + ActionView::TemplateFinder.reload! + end + if defined?(ActiveRecord) before_dispatch { ActiveRecord::Base.verify_active_connections! } to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers } -- cgit v1.2.3 From 3f594299c85ef111ac479b845fa8c7e37563ff66 Mon Sep 17 00:00:00 2001 From: Ruy Asan Date: Tue, 10 Jun 2008 21:13:27 -0700 Subject: TimeZone -> ActiveSupport::TimeZone. [#387 state:resolved] --- actionpack/lib/action_view/helpers/form_options_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index e0a097e367..b3f8e63c1b 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -304,7 +304,7 @@ module ActionView # # NOTE: Only the option tags are returned, you have to wrap this call in # a regular HTML select tag. - def time_zone_options_for_select(selected = nil, priority_zones = nil, model = TimeZone) + def time_zone_options_for_select(selected = nil, priority_zones = nil, model = ::ActiveSupport::TimeZone) zone_options = "" zones = model.all @@ -417,7 +417,7 @@ module ActionView value = value(object) content_tag("select", add_options( - time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || TimeZone), + time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || ActiveSupport::TimeZone), options, value ), html_options ) -- cgit v1.2.3 From f728e57d2204a429f5282856ec89d4e047e72957 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 11 Jun 2008 09:11:08 +0100 Subject: Make sure cache_template_loading works and don't use to_prepare callback --- actionpack/lib/action_controller/dispatcher.rb | 5 +---- actionpack/lib/action_view/template.rb | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index f20d9cc40f..fe4f6b4a7e 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -21,10 +21,6 @@ module ActionController end end - to_prepare :reload_view_path_cache do - ActionView::TemplateFinder.reload! - end - if defined?(ActiveRecord) before_dispatch { ActiveRecord::Base.verify_active_connections! } to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers } @@ -138,6 +134,7 @@ module ActionController run_callbacks :prepare_dispatch Routing::Routes.reload + ActionView::TemplateFinder.reload! unless ActionView::Base.cache_template_loading end # Cleanup the application by clearing out loaded classes so they can diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index a878ac66d9..25d5819af9 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -99,6 +99,7 @@ module ActionView #:nodoc: # return the rendered template as a string. def self.register_template_handler(extension, klass) @@template_handlers[extension.to_sym] = klass + ActionView::TemplateFinder.reload! end def self.template_handler_extensions -- cgit v1.2.3 From 3e07f320c10b53ec21b947d949d0063e724c5fd8 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Thu, 6 Mar 2008 11:50:44 +0000 Subject: Improve ActionCaching's format-handling Make ActionCaching more aware of different mimetype formats. It will now use request.format to look up the cache type, in addition to the path extension. When expiring caches, the request format no longer affects which cache is expired. Signed-off-by: Pratik Naik --- .../lib/action_controller/caching/actions.rb | 41 +++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index c4b0a97a33..65a36f7f98 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -67,10 +67,10 @@ module ActionController #:nodoc: if options[:action].is_a?(Array) options[:action].dup.each do |action| - expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action }))) + expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action }), false)) end else - expire_fragment(ActionCachePath.path_for(self, options)) + expire_fragment(ActionCachePath.path_for(self, options, false)) end end @@ -125,16 +125,24 @@ module ActionController #:nodoc: attr_reader :path, :extension class << self - def path_for(controller, options) - new(controller, options).path + def path_for(controller, options, infer_extension=true) + new(controller, options, infer_extension).path end end - - def initialize(controller, options = {}) - @extension = extract_extension(controller.request.path) + + # When true, infer_extension will look up the cache path extension from the request's path & format. + # This is desirable when reading and writing the cache, but not when expiring the cache - expire_action should expire the same files regardless of the request format. + def initialize(controller, options = {}, infer_extension=true) + if infer_extension and options.is_a? Hash + request_extension = extract_extension(controller.request) + options = options.reverse_merge(:format => request_extension) + end path = controller.url_for(options).split('://').last normalize!(path) - add_extension!(path, @extension) + if infer_extension + @extension = request_extension + add_extension!(path, @extension) + end @path = URI.unescape(path) end @@ -144,13 +152,22 @@ module ActionController #:nodoc: end def add_extension!(path, extension) - path << ".#{extension}" if extension + path << ".#{extension}" if extension and !path.ends_with?(extension) end - - def extract_extension(file_path) + + def extract_extension(request) # Don't want just what comes after the last '.' to accommodate multi part extensions # such as tar.gz. - file_path[/^[^.]+\.(.+)$/, 1] + extension = request.path[/^[^.]+\.(.+)$/, 1] + + # If there's no extension in the path, check request.format + if extension.nil? + extension = request.format.to_sym.to_s + if extension=='all' + extension = nil + end + end + extension end end end -- cgit v1.2.3 From 5ed162d7c1fc2cd6495249fbaf8692fc1ab5a1eb Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 11 Jun 2008 22:05:36 -0500 Subject: Moved template handler registration into a mix-in module. --- actionpack/lib/action_view.rb | 7 +- actionpack/lib/action_view/template.rb | 91 ++++++++------------------ actionpack/lib/action_view/template_handler.rb | 1 - 3 files changed, 27 insertions(+), 72 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index 5f4126e4e9..2f6894a8f9 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -21,12 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -require 'action_view/template_handler' -require 'action_view/template_handlers/compilable' -require 'action_view/template_handlers/builder' -require 'action_view/template_handlers/erb' -require 'action_view/template_handlers/rjs' - +require 'action_view/template_handlers' require 'action_view/template_finder' require 'action_view/template' require 'action_view/partial_template' diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 25d5819af9..500ff713bb 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -1,5 +1,6 @@ module ActionView #:nodoc: class Template #:nodoc: + extend TemplateHandlers attr_accessor :locals attr_reader :handler, :path, :extension, :filename, :path_without_extension, :method @@ -13,7 +14,7 @@ module ActionView #:nodoc: @view.first_render ||= @path @source = nil # Don't read the source until we know that it is required set_extension_and_file_name(use_full_path) - + @locals = locals || {} @handler = self.class.handler_class_for_extension(@extension).new(@view) end @@ -29,7 +30,7 @@ module ActionView #:nodoc: raise TemplateError.new(self, @view.assigns, e) end end - + def render prepare! @handler.render(self) @@ -46,11 +47,11 @@ module ActionView #:nodoc: def base_path_for_exception @finder.find_base_path_for("#{@path_without_extension}.#{@extension}") || @finder.view_paths.first end - + def prepare! @view.send :evaluate_assigns @view.current_render_extension = @extension - + if @handler.compilable? @handler.compile_template(self) # compile the given template, if necessary @method = @view.method_names[method_key] # Set the method name for this template and run it @@ -58,70 +59,30 @@ module ActionView #:nodoc: end private - - def set_extension_and_file_name(use_full_path) - @path_without_extension, @extension = @finder.path_and_extension(@path) - if use_full_path - if @extension - @filename = @finder.pick_template(@path_without_extension, @extension) + def set_extension_and_file_name(use_full_path) + @path_without_extension, @extension = @finder.path_and_extension(@path) + if use_full_path + if @extension + @filename = @finder.pick_template(@path_without_extension, @extension) + else + @extension = @finder.pick_template_extension(@path).to_s + raise_missing_template_exception unless @extension + + @filename = @finder.pick_template(@path, @extension) + @extension = @extension.gsub(/^.+\./, '') # strip off any formats + end else - @extension = @finder.pick_template_extension(@path).to_s - raise_missing_template_exception unless @extension - - @filename = @finder.pick_template(@path, @extension) - @extension = @extension.gsub(/^.+\./, '') # strip off any formats + @filename = @path end - else - @filename = @path - end - - raise_missing_template_exception if @filename.blank? - end - - def raise_missing_template_exception - full_template_path = @path.include?('.') ? @path : "#{@path}.#{@view.template_format}.erb" - display_paths = @finder.view_paths.join(':') - template_type = (@path =~ /layouts/i) ? 'layout' : 'template' - raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}") - end - # Template Handlers - - @@template_handlers = HashWithIndifferentAccess.new - @@default_template_handlers = nil - - # Register a class that knows how to handle template files with the given - # extension. This can be used to implement new template types. - # The constructor for the class must take the ActiveView::Base instance - # as a parameter, and the class must implement a +render+ method that - # takes the contents of the template to render as well as the Hash of - # local assigns available to the template. The +render+ method ought to - # return the rendered template as a string. - def self.register_template_handler(extension, klass) - @@template_handlers[extension.to_sym] = klass - ActionView::TemplateFinder.reload! - end - - def self.template_handler_extensions - @@template_handlers.keys.map(&:to_s).sort - end - - def self.register_default_template_handler(extension, klass) - register_template_handler(extension, klass) - @@default_template_handlers = klass - end - - def self.handler_class_for_extension(extension) - (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers - end - - register_default_template_handler :erb, TemplateHandlers::ERB - register_template_handler :rjs, TemplateHandlers::RJS - register_template_handler :builder, TemplateHandlers::Builder + raise_missing_template_exception if @filename.blank? + end - # TODO: Depreciate old template extensions - register_template_handler :rhtml, TemplateHandlers::ERB - register_template_handler :rxml, TemplateHandlers::Builder - + def raise_missing_template_exception + full_template_path = @path.include?('.') ? @path : "#{@path}.#{@view.template_format}.erb" + display_paths = @finder.view_paths.join(':') + template_type = (@path =~ /layouts/i) ? 'layout' : 'template' + raise(MissingTemplate, "Missing #{template_type} #{full_template_path} in view path #{display_paths}") + end end end diff --git a/actionpack/lib/action_view/template_handler.rb b/actionpack/lib/action_view/template_handler.rb index ec407e3fb3..39e578e586 100644 --- a/actionpack/lib/action_view/template_handler.rb +++ b/actionpack/lib/action_view/template_handler.rb @@ -1,6 +1,5 @@ module ActionView class TemplateHandler - def self.line_offset 0 end -- cgit v1.2.3 From d4c58c7928374c1deb533d69252fecd4068a8c11 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 11 Jun 2008 22:22:05 -0500 Subject: Opps, I forgot to add template_handlers.rb to my index. --- actionpack/lib/action_view/template_handlers.rb | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 actionpack/lib/action_view/template_handlers.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb new file mode 100644 index 0000000000..1471e99e01 --- /dev/null +++ b/actionpack/lib/action_view/template_handlers.rb @@ -0,0 +1,46 @@ +require 'action_view/template_handler' +require 'action_view/template_handlers/compilable' +require 'action_view/template_handlers/builder' +require 'action_view/template_handlers/erb' +require 'action_view/template_handlers/rjs' + +module ActionView #:nodoc: + module TemplateHandlers #:nodoc: + def self.extended(base) + base.register_default_template_handler :erb, TemplateHandlers::ERB + base.register_template_handler :rjs, TemplateHandlers::RJS + base.register_template_handler :builder, TemplateHandlers::Builder + + # TODO: Depreciate old template extensions + base.register_template_handler :rhtml, TemplateHandlers::ERB + base.register_template_handler :rxml, TemplateHandlers::Builder + end + + @@template_handlers = {} + @@default_template_handlers = nil + + # Register a class that knows how to handle template files with the given + # extension. This can be used to implement new template types. + # The constructor for the class must take the ActiveView::Base instance + # as a parameter, and the class must implement a +render+ method that + # takes the contents of the template to render as well as the Hash of + # local assigns available to the template. The +render+ method ought to + # return the rendered template as a string. + def register_template_handler(extension, klass) + @@template_handlers[extension.to_sym] = klass + end + + def template_handler_extensions + @@template_handlers.keys.map(&:to_s).sort + end + + def register_default_template_handler(extension, klass) + register_template_handler(extension, klass) + @@default_template_handlers = klass + end + + def handler_class_for_extension(extension) + (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers + end + end +end -- cgit v1.2.3 From 6573f6a4bc1c2ebd26e0b4b3ef9fe1cde3219354 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 12 Jun 2008 19:52:33 -0500 Subject: Revert "Lazy load cache and session stores" This reverts commit 19895f087c338d8385dff9d272d30fb87cb10330. --- actionpack/lib/action_controller/session_management.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/session_management.rb b/actionpack/lib/action_controller/session_management.rb index ad1013b379..80a3ddd2c5 100644 --- a/actionpack/lib/action_controller/session_management.rb +++ b/actionpack/lib/action_controller/session_management.rb @@ -1,3 +1,10 @@ +require 'action_controller/session/cookie_store' +require 'action_controller/session/drb_store' +require 'action_controller/session/mem_cache_store' +if Object.const_defined?(:ActiveRecord) + require 'action_controller/session/active_record_store' +end + module ActionController #:nodoc: module SessionManagement #:nodoc: def self.included(base) @@ -15,8 +22,6 @@ module ActionController #:nodoc: # :p_store, :drb_store, :mem_cache_store, or # :memory_store) or your own custom class. def session_store=(store) - require "action_controller/session/#{store.to_s}" if [:active_record_store, :drb_store, :mem_cache_store].include?(store) - ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] = store.is_a?(Symbol) ? CGI::Session.const_get(store == :drb_store ? "DRbStore" : store.to_s.camelize) : store end -- cgit v1.2.3 From eea4fe4c902e71249d77b3103eade3dec905f98a Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 13 Jun 2008 23:23:44 +0100 Subject: Make rescue template xhtml compatible [Sam Ruby] [#415 status:resolved] --- actionpack/lib/action_controller/templates/rescues/layout.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/templates/rescues/layout.erb b/actionpack/lib/action_controller/templates/rescues/layout.erb index d38f3e67f9..4a04742e40 100644 --- a/actionpack/lib/action_controller/templates/rescues/layout.erb +++ b/actionpack/lib/action_controller/templates/rescues/layout.erb @@ -1,4 +1,4 @@ - + Action Controller: Exception caught