actionpack 2.3.7 → 2.3.8.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +5 -0
- data/Rakefile +1 -1
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view/helpers/capture_helper.rb +1 -1
- data/lib/action_view/helpers/translation_helper.rb +22 -11
- data/lib/action_view/template_handlers/erb.rb +5 -0
- data/lib/action_view/test_case.rb +1 -1
- data/test/abstract_unit.rb +5 -5
- data/test/controller/capture_test.rb +1 -1
- data/test/fixtures/test/array_translation.erb +1 -1
- data/test/fixtures/test/capturing.erb +2 -2
- data/test/fixtures/test/scoped_array_translation.erb +1 -1
- data/test/fixtures/test/translation.erb +1 -0
- data/test/template/translation_helper_test.rb +31 -15
- metadata +13 -8
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -79,7 +79,7 @@ spec = Gem::Specification.new do |s|
|
|
79
79
|
s.has_rdoc = true
|
80
80
|
s.requirements << 'none'
|
81
81
|
|
82
|
-
s.add_dependency('activesupport', '= 2.3.
|
82
|
+
s.add_dependency('activesupport', '= 2.3.8' + PKG_BUILD)
|
83
83
|
s.add_dependency('rack', '~> 1.1.0')
|
84
84
|
|
85
85
|
s.require_path = 'lib'
|
data/lib/action_pack/version.rb
CHANGED
@@ -124,7 +124,7 @@ module ActionView
|
|
124
124
|
|
125
125
|
# Use an alternate output buffer for the duration of the block.
|
126
126
|
# Defaults to a new empty string.
|
127
|
-
def with_output_buffer(buf =
|
127
|
+
def with_output_buffer(buf = '') #:nodoc:
|
128
128
|
self.output_buffer, old_buffer = buf, output_buffer
|
129
129
|
yield
|
130
130
|
output_buffer
|
@@ -3,17 +3,21 @@ require 'action_view/helpers/tag_helper'
|
|
3
3
|
module ActionView
|
4
4
|
module Helpers
|
5
5
|
module TranslationHelper
|
6
|
-
# Delegates to I18n#translate but also performs two additional functions. First, it'll catch MissingTranslationData exceptions
|
6
|
+
# Delegates to I18n#translate but also performs two additional functions. First, it'll catch MissingTranslationData exceptions
|
7
7
|
# and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where.
|
8
8
|
#
|
9
9
|
# Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the
|
10
10
|
# people/index.html.erb template, you'll actually be calling I18n.translate("people.index.foo"). This makes it less repetitive
|
11
11
|
# to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't
|
12
12
|
# prepend the key with a period, nothing is converted.
|
13
|
-
def translate(
|
14
|
-
options[:raise]
|
15
|
-
|
16
|
-
|
13
|
+
def translate(keys, options = {})
|
14
|
+
options[:raise] = true
|
15
|
+
are_keys_a_string = keys.is_a?(String)
|
16
|
+
keys = scope_keys_by_partial(keys)
|
17
|
+
|
18
|
+
translations = I18n.translate(keys, options)
|
19
|
+
translations = html_safe_translation_keys(keys, Array.wrap(translations))
|
20
|
+
are_keys_a_string ? translations.first : translations
|
17
21
|
rescue I18n::MissingTranslationData => e
|
18
22
|
keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
|
19
23
|
content_tag('span', keys.join(', '), :class => 'translation_missing')
|
@@ -28,12 +32,19 @@ module ActionView
|
|
28
32
|
|
29
33
|
|
30
34
|
private
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def scope_keys_by_partial(keys)
|
36
|
+
Array.wrap(keys).map do |key|
|
37
|
+
if key.to_s.first == "."
|
38
|
+
template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s
|
39
|
+
else
|
40
|
+
key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def html_safe_translation_keys(keys, translations)
|
46
|
+
keys.zip(translations).map do |key, translation|
|
47
|
+
key =~ /(\b|_|\.)html$/ ? translation.html_safe : translation
|
37
48
|
end
|
38
49
|
end
|
39
50
|
end
|
@@ -13,6 +13,11 @@ module ActionView
|
|
13
13
|
def compile(template)
|
14
14
|
magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
|
15
15
|
erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
|
16
|
+
|
17
|
+
if erb.respond_to?(:force_encoding)
|
18
|
+
erb.force_encoding(template.source.encoding)
|
19
|
+
end
|
20
|
+
|
16
21
|
::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
|
17
22
|
end
|
18
23
|
end
|
data/test/abstract_unit.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
$:.unshift
|
2
|
-
$:.unshift
|
3
|
-
$:.unshift
|
4
|
-
$:.unshift
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
|
3
|
+
$:.unshift File.expand_path('../fixtures/helpers', __FILE__)
|
4
|
+
$:.unshift File.expand_path('../fixtures/alternate_helpers', __FILE__)
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'yaml'
|
@@ -58,4 +58,4 @@ class DummyMutex
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
ActionController::Reloader.default_lock = DummyMutex.new
|
61
|
+
ActionController::Reloader.default_lock = DummyMutex.new
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
<% translation = t(['foo', 'bar', 'baz_html']) %><%= translation.first %>, <%= translation.second %>, <%= translation.third %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= t(['.foo', '.bar']) %>
|
1
|
+
<%= t(['.foo', '.bar']).join(", ") %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= t('.helper') %>
|
@@ -1,32 +1,33 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
|
-
class TranslationHelperTest <
|
3
|
+
class TranslationHelperTest < ActiveSupport::TestCase
|
4
4
|
include ActionView::Helpers::TagHelper
|
5
5
|
include ActionView::Helpers::TranslationHelper
|
6
|
-
|
6
|
+
|
7
7
|
attr_reader :request
|
8
8
|
def setup
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def test_delegates_to_i18n_setting_the_raise_option
|
12
|
-
I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true).returns("")
|
12
|
+
I18n.expects(:translate).with([:foo], :locale => 'en', :raise => true).returns([""])
|
13
13
|
translate :foo, :locale => 'en'
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_returns_missing_translation_message_wrapped_into_span
|
17
17
|
expected = '<span class="translation_missing">en, foo</span>'
|
18
18
|
assert_equal expected, translate(:foo)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_translation_of_an_array
|
22
22
|
I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
|
23
|
-
assert_equal "
|
23
|
+
assert_equal ["foo", "bar"], translate(["foo", "bar"])
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_translation_of_an_array_with_html
|
27
|
-
|
28
|
-
I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(
|
27
|
+
translate_expected = ['<a href="#">foo</a>', '<a href="#">bar</a>', '<a href="#">baz</a>']
|
28
|
+
I18n.expects(:translate).with(["foo", "bar", "baz_html"], :raise => true).returns(translate_expected)
|
29
29
|
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
30
|
+
expected = '<a href="#">foo</a>, <a href="#">bar</a>, <a href="#">baz</a>'
|
30
31
|
assert_equal expected, @view.render(:file => "test/array_translation")
|
31
32
|
end
|
32
33
|
|
@@ -35,16 +36,31 @@ class TranslationHelperTest < Test::Unit::TestCase
|
|
35
36
|
I18n.expects(:localize).with(@time)
|
36
37
|
localize @time
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
def test_scoping_by_partial
|
40
|
-
expects(:
|
41
|
-
|
42
|
-
|
41
|
+
I18n.expects(:translate).with(["test.translation.helper"], :raise => true).returns(["helper"])
|
42
|
+
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
43
|
+
assert_equal "helper", @view.render(:file => "test/translation")
|
43
44
|
end
|
44
45
|
|
45
46
|
def test_scoping_by_partial_of_an_array
|
46
|
-
I18n.expects(:translate).with("test.scoped_array_translation.foo.bar", :raise => true).returns(["foo", "bar"])
|
47
|
+
I18n.expects(:translate).with(["test.scoped_array_translation.foo", "test.scoped_array_translation.bar"], :raise => true).returns(["foo", "bar"])
|
47
48
|
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
48
|
-
assert_equal "
|
49
|
+
assert_equal "foo, bar", @view.render(:file => "test/scoped_array_translation")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_translate_does_not_mark_plain_text_as_safe_html
|
53
|
+
I18n.expects(:translate).with(["hello"], :raise => true).returns(["Hello World"])
|
54
|
+
assert_equal false, translate("hello").html_safe?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_translate_marks_translations_named_html_as_safe_html
|
58
|
+
I18n.expects(:translate).with(["html"], :raise => true).returns(["<a>Hello World</a>"])
|
59
|
+
assert translate("html").html_safe?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_translate_marks_translations_with_a_html_suffix_as_safe_html
|
63
|
+
I18n.expects(:translate).with(["hello_html"], :raise => true).returns(["<a>Hello World</a>"])
|
64
|
+
assert translate("hello_html").html_safe?
|
49
65
|
end
|
50
66
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
|
8
|
+
- 8
|
9
|
+
- pre1
|
10
|
+
version: 2.3.8.pre1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- David Heinemeier Hansson
|
@@ -27,8 +28,9 @@ dependencies:
|
|
27
28
|
segments:
|
28
29
|
- 2
|
29
30
|
- 3
|
30
|
-
-
|
31
|
-
|
31
|
+
- 8
|
32
|
+
- pre1
|
33
|
+
version: 2.3.8.pre1
|
32
34
|
type: :runtime
|
33
35
|
version_requirements: *id001
|
34
36
|
- !ruby/object:Gem::Dependency
|
@@ -451,6 +453,7 @@ files:
|
|
451
453
|
- test/fixtures/test/scoped_array_translation.erb
|
452
454
|
- test/fixtures/test/sub_template_raise.html.erb
|
453
455
|
- test/fixtures/test/template.erb
|
456
|
+
- test/fixtures/test/translation.erb
|
454
457
|
- test/fixtures/test/update_element_with_capture.erb
|
455
458
|
- test/fixtures/test/using_layout_around_block.html.erb
|
456
459
|
- test/fixtures/test/using_layout_around_block_with_args.html.erb
|
@@ -508,11 +511,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
508
511
|
version: "0"
|
509
512
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
510
513
|
requirements:
|
511
|
-
- - "
|
514
|
+
- - ">"
|
512
515
|
- !ruby/object:Gem::Version
|
513
516
|
segments:
|
514
|
-
-
|
515
|
-
|
517
|
+
- 1
|
518
|
+
- 3
|
519
|
+
- 1
|
520
|
+
version: 1.3.1
|
516
521
|
requirements:
|
517
522
|
- none
|
518
523
|
rubyforge_project: actionpack
|