text_helpers 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96b1413c9d4a7e4a7c09d61fcf73d31024088238
4
- data.tar.gz: f8d107fdadfb1d61b71fd41b3338b0981f325e2f
3
+ metadata.gz: 320e647924e409f4729c273ce71c68c2042c3748
4
+ data.tar.gz: f5a7f39ee0319697a1f6569666b28083043b892d
5
5
  SHA512:
6
- metadata.gz: b61a1f7ab9fdc3b2a0c7c40190c37609fd5d57058df512ea19376d462b90424f08da965975a53d3cc863665ed36c8ba1a275e754bfc24713bee61e2ac960ae96
7
- data.tar.gz: b800a3e4ae9fe750c3645de28546b38d51c10ced240b65d5b6ba311dfe719d117613c08d7f2d3637dc3a7faf55f209c0a74b96a7863f1bd3abca4c26b745c8c2
6
+ metadata.gz: a12a9414e716c6cc7c7d7a7a4265cb20222bced8ea6d607d0e2cfed59f08f0b8fcc3f9159f6013befd721b217a8040080a25406e09f0dac04fe85775bdeeff37
7
+ data.tar.gz: c81f7a27c1467d3d3c924f11176e7058d5dbf744e2326f4c48da33a6c126f36cf26443b33c539f2e76d02b14a0fef8b7242884481e3b69e7396753a1deee3cab
data/.gitignore CHANGED
@@ -4,6 +4,8 @@
4
4
  .config
5
5
  .yardoc
6
6
  .DS_Store
7
+ .ruby-version
8
+ .ruby-gemset
7
9
 
8
10
  Gemfile.lock
9
11
  InstalledFiles
data/README.md CHANGED
@@ -18,11 +18,19 @@ structure mirroring the app directory structure. The text for
18
18
  requirement, but will go a long way toward keeping your locales easily
19
19
  maintainable.
20
20
 
21
+ If you're using this within a Rails project, you'll probably want to add the
22
+ following line to your application.rb to ensure that Rails loads any locale
23
+ files organized this way:
24
+
25
+ ```ruby
26
+ config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
27
+ ```
28
+
21
29
  In any locale file entry, you can reference another key in the locale file by
22
- using the syntax `!scope.to.key!`. For the sake of maintainability, the use of
23
- this interpolation should be restricted to small fragments of highly-recycled
24
- static values. `I18n`'s built-in `%{value}` interpolation can be used for
25
- variable text.
30
+ using the syntax `!scope.to.key!`. For the sake of maintainability, I
31
+ recommend restricting the use of this feature to small, highly-recycled
32
+ fragments of static text. `I18n`'s built-in `%{value}` interpolation can be
33
+ used for variable text.
26
34
 
27
35
  ### In Views
28
36
 
@@ -22,12 +22,8 @@ shared_context "a view spec", view: true do
22
22
  def translation_scope
23
23
  matcher = /(?<path>.*)\/_?(?<view>[^\/.]+)(?<extension>\.html\.haml)?/
24
24
  info = matcher.match(example.metadata[:full_description])
25
+ path = info[:path].gsub('/', '.')
25
26
 
26
- if info
27
- path = info[:path].gsub('/', '.')
28
- "views.#{path}.#{info[:view]}"
29
- else
30
- "views.#{params[:controller]}.#{params[:action]}"
31
- end
27
+ "views.#{path}.#{info[:view]}"
32
28
  end
33
29
  end
@@ -21,11 +21,14 @@ module TextHelpers
21
21
  text = I18n.t(key, {
22
22
  scope: self.translation_scope,
23
23
  default: "!#{key}!"
24
- }.merge(options))
24
+ }.merge(options)).strip
25
25
 
26
26
  # Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
27
- final_text = text.strip.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1) }
28
- final_text.html_safe
27
+ while text =~ /!([\w._\/]+)!/ do
28
+ text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1) }
29
+ end
30
+
31
+ text.html_safe
29
32
  end
30
33
 
31
34
  # Public: Get an HTML representation of the rendered markdown for the passed I18n key.
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -21,10 +21,11 @@ describe TextHelpers::Translation do
21
21
  test_key: @global_text,
22
22
  multiline_key: @multiline_text,
23
23
  test: {
24
- email_key: "<#{@email_address}>",
25
- test_key: "*#{@scoped_text}*",
26
- list_key: "* #{@scoped_text}",
27
- interpolated_key: "Global? (!test_key!)"
24
+ email_key: "<#{@email_address}>",
25
+ test_key: "*#{@scoped_text}*",
26
+ list_key: "* #{@scoped_text}",
27
+ interpolated_key: "Global? (!test_key!)",
28
+ recursive_key: "Recursively !test.interpolated_key!"
28
29
  }
29
30
  }
30
31
  end
@@ -83,6 +84,10 @@ describe TextHelpers::Translation do
83
84
  it "interpolates values wrapped in !!" do
84
85
  assert_equal "Global? (#{@global_text})", @helper.text(:interpolated_key)
85
86
  end
87
+
88
+ it "handles recursive interpolation" do
89
+ assert_equal "Recursively Global? (#{@global_text})", @helper.text(:recursive_key)
90
+ end
86
91
  end
87
92
 
88
93
  describe "when no valid scope is provided" do
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.2.1
4
+ version: 0.2.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: 2013-12-26 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.0.6
96
+ rubygems_version: 2.2.2
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: TextHelpers is a gem which supplies some basic utilities for text localization