Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Reset memoized hash keys when new ActionView::Template handler is registered #5101

Merged
merged 1 commit into from

2 participants

@ckdake

When any code in an initializer or gem load accesses the list of view handlers (ActionView::Template::Handlers.extensions), this gets memoized which prevents new handlers (in my case, adding in Mustache via an initializer using ActionView::Template.register_template_handler) from being made available for use.

This patch resets the memoization so that the next time '.extensions' is called, it includes all extensions that have been registered.

@josevalim josevalim merged commit 8c870f1 into from
@delynn delynn referenced this pull request from a commit in delynn/rails
@delynn delynn Merge branch 'master' into prepend-content-for
* master: (45 commits)
  use Hash#delete with a default block
  refactor options_for_select
  refactor grouped_options_for_select
  Fix a failing test
  Use the right format when a partial is missing.
  Merge pull request #5101 from ckdake/ckdake_actionview_handler_reset
  search private / protected methods in trunk ruby
  removed commented line. 3434 tests, 10531 assertions, 0 failures, 0 errors, 31 skips
  Restored ability to identify ID and Sequence from tables relying on a nonmatching sequence default value for PK.
  AM::Errors: allow :full_messages parameter for #as_json
  Remove fixture files with Windows incompatible filenames
  Integration tests support the OPTIONS http method
  Update activerecord/CHANGELOG.md
  fix some typos [ci skip]
  Documenting the :inverse_of option for associations
  add selected and disabled option to grouped select
  assigns(:foo) should not convert @foo's keys to strings if it happens to be a hash
  Fix actionpack readme weblog example
  Fix AbstractController::Base#hidden_actions comment
  Do get it right this time. Fixing the documentation around :dependent => :restrict option
  ...
e6ff135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2012
  1. @ckdake
This page is out of date. Refresh to see the latest.
View
1  actionpack/lib/action_view/template/handlers.rb
@@ -26,6 +26,7 @@ def self.extensions
# return the rendered template as a string.
def register_template_handler(extension, klass)
@@template_handlers[extension.to_sym] = klass
+ @@template_extensions = nil
end
def template_handler_extensions
View
6 actionpack/test/template/render_test.rb
@@ -329,6 +329,12 @@ def test_render_inline_with_locals_and_compilable_custom_type
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
+
+ def test_render_knows_about_types_registered_when_extensions_are_checked_earlier_in_initialization
+ ActionView::Template::Handlers.extensions
+ ActionView::Template.register_template_handler :foo, CustomHandler
+ assert ActionView::Template::Handlers.extensions.include?(:foo)
+ end
def test_render_ignores_templates_with_malformed_template_handlers
ActiveSupport::Deprecation.silence do
Something went wrong with that request. Please try again.