text_helpers 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c49f9648a3bb95e99aea71aedff8bae0454e01e0
4
- data.tar.gz: ed92fc57ef9f89ac19d1b29f54a9245f912d721b
3
+ metadata.gz: b830f91668677103c3ef206b9921ee1b22002f38
4
+ data.tar.gz: b8083debf8108e5a2aabbb006a3a714d8ccd7326
5
5
  SHA512:
6
- metadata.gz: 21a84ee6259dfe61a832c93fdbdb7ad26fc3ffcdbd574eb33f4b63ecb5cf1bb3ad82f97a59e54000998e91c1ed51bf66b35547b3016db2fbc4055ef4ae0db67e
7
- data.tar.gz: c5df917ab268762229f9e586e39f1d669b33affae097f2e87154b4ea50fe000ee1879f3e1f98ee0a3ad0e61043c0b679804f9211124b2c6a6beb4d8afcbec190
6
+ metadata.gz: 775485ba26237b01b0b037517fd2a684d4c409a197bb7e30a87e2c760d40ac390e9810f241c7cc546487326bbefc7cceff3c10932bdefc767f9499a873c8ea8d
7
+ data.tar.gz: 3c3d7e67185f1f54e3a6a8afc6281f1c492214a739fda44e6a3d9e6f51efde7d3cccd291709e535aa3fd6a9cce05207338b59d0e1ce698e6e385858156f4fd2a
@@ -20,14 +20,15 @@ module TextHelpers
20
20
  #
21
21
  # Returns a String resulting from the I18n lookup.
22
22
  def text(key, options = {})
23
+ options = html_safe_options(options)
23
24
  text = I18n.t(key, {
24
25
  scope: self.translation_scope,
25
26
  default: "!#{key}!"
26
- }.merge(html_safe_options(options))).strip
27
+ }.merge(options)).strip
27
28
 
28
29
  # Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
29
30
  while text =~ /!([\w._\/]+)!/ do
30
- text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1) }
31
+ text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1, options) }
31
32
  end
32
33
 
33
34
  text = smartify(text) if options.fetch(:smart, true)
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -20,11 +20,13 @@ describe TextHelpers::Translation do
20
20
  I18n.backend.store_translations :en, {
21
21
  test_key: @global_text,
22
22
  multiline_key: @multiline_text,
23
+ interpolated_key: "%{interpolate_with}",
23
24
  test: {
24
25
  email_key: "<#{@email_address}>",
25
26
  test_key: "*#{@scoped_text}*",
26
27
  list_key: "* #{@scoped_text}",
27
28
  interpolated_key: "Global? (!test_key!)",
29
+ interpol_arg_key: "Interpolate global? (!interpolated_key!)",
28
30
  recursive_key: "Recursively !test.interpolated_key!",
29
31
  quoted_key: "They're looking for \"#{@global_text}\"--#{@scoped_text}",
30
32
  argument_key: "This is what %{user} said",
@@ -92,6 +94,10 @@ describe TextHelpers::Translation do
92
94
  assert_equal "Global? (#{@global_text})", @helper.text(:interpolated_key)
93
95
  end
94
96
 
97
+ it "interpolates contents of scopes wrapped in !!" do
98
+ assert_equal "Interpolate global? (My interpolated text)", @helper.text(:interpol_arg_key, interpolate_with: "My interpolated text")
99
+ end
100
+
95
101
  it "handles recursive interpolation" do
96
102
  assert_equal "Recursively Global? (#{@global_text})", @helper.text(:recursive_key)
97
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport