Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From fbe5ddcd44555eadc0ce69e0822515db14601c8b Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com>
- Date: Tue, 26 Jan 2010 18:37:25 +0100
- Subject: [PATCH] Make t('.helper') work again.
- ---
- actionpack/lib/action_view/base.rb | 2 +-
- .../lib/action_view/helpers/translation_helper.rb | 2 +-
- actionpack/lib/action_view/template.rb | 5 +++++
- actionpack/lib/action_view/template/resolver.rb | 12 +++++++-----
- actionpack/test/controller/helper_test.rb | 20 ++++++++++----------
- actionpack/test/fixtures/test/translation.erb | 1 +
- .../test/template/translation_helper_test.rb | 10 +++++-----
- 7 files changed, 30 insertions(+), 22 deletions(-)
- create mode 100644 actionpack/test/fixtures/test/translation.erb
- diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
- index c4b0455..3e38b70 100644
- --- a/actionpack/lib/action_view/base.rb
- +++ b/actionpack/lib/action_view/base.rb
- @@ -220,7 +220,7 @@ module ActionView #:nodoc:
- ActionController::Base.allow_concurrency || (cache_template_loading.nil? ? !ActiveSupport::Dependencies.load? : cache_template_loading)
- end
- - attr_internal :request, :layout
- + attr_internal :request, :layout, :_template
- def controller_path
- @controller_path ||= controller && controller.controller_path
- diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb
- index 35c431d..4ca8a11 100644
- --- a/actionpack/lib/action_view/helpers/translation_helper.rb
- +++ b/actionpack/lib/action_view/helpers/translation_helper.rb
- @@ -29,7 +29,7 @@ module ActionView
- private
- def scope_key_by_partial(key)
- if key.to_s.first == "."
- - template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s
- + _template.path_without_details.gsub(%r{/_?}, ".") + key.to_s
- else
- key
- end
- diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
- index adaf654..0eef8a3 100644
- --- a/actionpack/lib/action_view/template.rb
- +++ b/actionpack/lib/action_view/template.rb
- @@ -37,6 +37,7 @@ module ActionView
- def render(view, locals, &block)
- method_name = compile(locals, view)
- + view._template = self
- view.send(method_name, locals, &block)
- rescue Exception => e
- if e.is_a?(Template::Error)
- @@ -47,6 +48,10 @@ module ActionView
- end
- end
- + def path_without_details
- + @details[:path]
- + end
- +
- # TODO: Figure out how to abstract this
- def variable_name
- @variable_name ||= identifier[%r'_?(\w+)(\.\w+)*$', 1].to_sym
- diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
- index c6a1790..323d99e 100644
- --- a/actionpack/lib/action_view/template/resolver.rb
- +++ b/actionpack/lib/action_view/template/resolver.rb
- @@ -117,15 +117,17 @@ module ActionView
- # # :api: plugin
- def path_to_details(path)
- # [:erb, :format => :html, :locale => :en, :partial => true/false]
- - if m = path.match(%r'(?:^|/)(_)?[\w-]+((?:\.[\w-]+)*)\.(\w+)$')
- - partial = m[1] == '_'
- - details = (m[2]||"").split('.').reject { |e| e.empty? }
- - handler = Template.handler_class_for_extension(m[3])
- + if m = path.match(%r'^(.*/(_)?[\w-]+)((?:\.[\w-]+)*)\.(\w+)$')
- + partial = m[2] == '_'
- + details = (m[3]||"").split('.').reject { |e| e.empty? }
- + handler = Template.handler_class_for_extension(m[4])
- format = Mime[details.last] && details.pop.to_sym
- locale = details.last && details.pop.to_sym
- - return handler, :format => format, :locale => locale, :partial => partial
- + path = (m[1].gsub("#{@path}/", "") << details.join("."))
- +
- + return handler, :format => format, :locale => locale, :partial => partial, :path => path
- end
- end
- end
- diff --git a/actionpack/test/fixtures/test/translation.erb b/actionpack/test/fixtures/test/translation.erb
- new file mode 100644
- index 0000000..81a837d
- --- /dev/null
- +++ b/actionpack/test/fixtures/test/translation.erb
- @@ -0,0 +1 @@
- +<%= t('.helper') %>
- \ No newline at end of file
- diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
- index d67d2c7..4b73c44 100644
- --- a/actionpack/test/template/translation_helper_test.rb
- +++ b/actionpack/test/template/translation_helper_test.rb
- @@ -1,9 +1,9 @@
- require 'abstract_unit'
- -class TranslationHelperTest < Test::Unit::TestCase
- +class TranslationHelperTest < ActiveSupport::TestCase
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TranslationHelper
- -
- +
- attr_reader :request
- def setup
- end
- @@ -25,8 +25,8 @@ class TranslationHelperTest < Test::Unit::TestCase
- end
- def test_scoping_by_partial
- - expects(:template).returns(stub(:path_without_format_and_extension => "people/index"))
- - I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true).returns("")
- - translate ".foo", :locale => 'en'
- + I18n.expects(:translate).with("test.translation.helper", :raise => true).returns("helper")
- + @view = ActionView::Base.new(ActionController::Base.view_paths, {})
- + assert_equal "helper", @view.render(:file => "test/translation")
- end
- end
- --
- 1.6.5
Add Comment
Please, Sign In to add comment