Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allowing pass couple extension to one register_template_handler call #7644

Merged
merged 1 commit into from

5 participants

@timsly

To make possible add synonyms extension by one function call

ActionView::Template.register_template_handler :md, :markdown, markdown_handler
actionpack/test/template/render_test.rb
@@ -451,6 +451,20 @@ def test_render_layout_with_object
assert_equal %(<title>David</title>),
@view.render(:file => "test/layout_render_object")
end
+
+ def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call
+ ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler
+ assert_equal @view.render(:inline => "Hello, World!", :type => :foo1), @view.render(:inline => "Hello, World!", :type => :foo2)
+ end
+
+ def test_render_with_passing_couple_extensions_as_array_to_one_register_template_handler_function_call
@rafaelfranca Owner

I would not make possible this case. This would avoid the flatten call.

@timsly
timsly added a note

I just try to make it as much flexible
But i think you are right, i will remove that case to make it work faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca

We need a changelog entry and docs updated.

@rafaelfranca

@josevalim could you review this one to see if make sense add it?

@carlosantoniodasilva

Perhaps we could have a register_template_handlers method instead? Not sure.

@timsly

Not agree, because we register only one handler but associate it with couple extension

@guilleiguaran

@carlosantoniodasilva please no, we will be breaking a lot of gems without much benefit

@rafaelfranca

@guilleiguaran I don't think adding a new methods would break, but I agree that it is not necessary.

@guilleiguaran

@rafaelfranca ok, I was thinking in renaming of the current existing method to register_template_handlers, I agree also, I think we don't need it really

@carlosantoniodasilva

It was not about renaming, but allowing extra arguments. Anyway, both would work, no no need for new methods at the end.

@rafaelfranca

@insside could you squash your commits?

@timsly

@rafaelfranca, i have squashed my commits

@steveklabnik
Collaborator

It still says they can't be merged, I think you need to rebase as well.

@timsly

Is it possible merge now, or i need run to rebase one more time?

@rafaelfranca

We need another rebase.

@timsly

@rafaelfranca, i did rebase. Please check

@steveklabnik
Collaborator

It can merge cleanly right now. Let's hope @rafaelfranca gets to it quickly! :p

@rafaelfranca rafaelfranca merged commit d9f936e into from
@rafaelfranca

I'm here.

Thanks.

@steveklabnik
Collaborator

:heart: :heart: :heart:

@timsly

wooohoooo!!!!! My first commit, thank you guys )))

@steveklabnik
Collaborator

http://contributors.rubyonrails.org/contributors/tima-maslyuchenko/commits ;) keep submitting pulls and hitting f5! It's what I do.

@rafaelfranca

Welcome to the Rails contributors

@timsly

:-)
thanks for the tip
Doing this right now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Allow pass couple extensions to ActionView::Template.register_template_handler call. *Tima Maslyuchenko*
+
* Sprockets integration has been extracted from Action Pack and the `sprockets-rails`
gem should be added to Gemfile (under the assets group) in order to use Rails asset
pipeline in future versions of Rails.
View
9 actionpack/lib/action_view/template/handlers.rb
@@ -21,11 +21,14 @@ def self.extensions
end
# Register an object that knows how to handle template files with the given
- # extension. This can be used to implement new template types.
+ # extensions. This can be used to implement new template types.
# The handler must respond to `:call`, which will be passed the template
# and should return the rendered template as a String.
- def register_template_handler(extension, handler)
- @@template_handlers[extension.to_sym] = handler
+ def register_template_handler(*extensions, handler)
+ raise(ArgumentError, "Extension is required") if extensions.empty?
+ extensions.each do |extension|
+ @@template_handlers[extension.to_sym] = handler
+ end
@@template_extensions = nil
end
View
9 actionpack/test/template/render_test.rb
@@ -451,6 +451,15 @@ def test_render_layout_with_object
assert_equal %(<title>David</title>),
@view.render(:file => "test/layout_render_object")
end
+
+ def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call
+ ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler
+ assert_equal @view.render(:inline => "Hello, World!", :type => :foo1), @view.render(:inline => "Hello, World!", :type => :foo2)
+ end
+
+ def test_render_throws_exception_when_no_extensions_passed_to_register_template_handler_function_call
+ assert_raises(ArgumentError) { ActionView::Template.register_template_handler CustomHandler }
+ end
end
class CachedViewRenderTest < ActiveSupport::TestCase
Something went wrong with that request. Please try again.