text_helpers 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -0
- data/lib/text_helpers/translation.rb +5 -4
- data/lib/text_helpers/version.rb +1 -1
- data/test/lib/text_helpers/translation_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd673fcea44270d6cdcfeb8b87938e7224c2a111520ef859e35ce1df4ba785b1
|
4
|
+
data.tar.gz: fb7470beacfab30cfadd994023ae33f00753ddb7714854b642d8257561550491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63302f4838675fd77e69186b58fb6a91948c1d4d34f2f55779af8c2a615f07d9568a4a7c0771155036851ce2f74fc5f6b1d8f90ea81150ee294e1eb0ff90f281
|
7
|
+
data.tar.gz: 38288b327cc615cd9a63c37e581b0ac707e9568087189e38ac5bfd2f64c988124b1b359b4e63bc63b3c8f9a3e5ea2c93c639239f94a4fc32f9d63838c15e9341
|
data/Rakefile
CHANGED
@@ -22,7 +22,8 @@ module TextHelpers
|
|
22
22
|
|
23
23
|
module Translation
|
24
24
|
|
25
|
-
ORPHAN_MATCHER = /[ \t](?![^<]*>)(\S+\s*<\/(?:p|li)>)/.freeze
|
25
|
+
ORPHAN_MATCHER = /(\w+)[ \t](?![^<]*>)(\S+\s*<\/(?:p|li)>)/.freeze
|
26
|
+
KEYPATH_MATCHER = /!([\w.\/]+)!/.freeze
|
26
27
|
|
27
28
|
# Public: Get the I18n localized text for the passed key.
|
28
29
|
#
|
@@ -43,8 +44,8 @@ module TextHelpers
|
|
43
44
|
interpolation_options[:cascade] = true unless interpolation_options.has_key?(:cascade)
|
44
45
|
|
45
46
|
# Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
|
46
|
-
while text =~
|
47
|
-
text = text.gsub(
|
47
|
+
while text =~ KEYPATH_MATCHER do
|
48
|
+
text = text.gsub(KEYPATH_MATCHER) { |match| I18n.t($1, interpolation_options) }
|
48
49
|
end
|
49
50
|
|
50
51
|
text = smartify(text) if options.fetch(:smart, true)
|
@@ -65,7 +66,7 @@ module TextHelpers
|
|
65
66
|
def html(key, options = {})
|
66
67
|
rendered = markdown(text(key, options.merge(smart: false)))
|
67
68
|
|
68
|
-
rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, ' \
|
69
|
+
rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, '\1 \2')
|
69
70
|
rendered = rendered.gsub(/<\/?p>/, '') if options[:inline]
|
70
71
|
rendered.html_safe
|
71
72
|
end
|
data/lib/text_helpers/version.rb
CHANGED
@@ -32,6 +32,7 @@ describe TextHelpers::Translation do
|
|
32
32
|
test_key: "*#{@scoped_text}*",
|
33
33
|
list_key: "* #{@scoped_text}",
|
34
34
|
single_word_list_key: "* #{@single_word_text}",
|
35
|
+
prerendered_html_key: "<ul>\n <li> Get everything you ever wanted</li>\n <li> Practically-guaranteed</li>\n </ul>",
|
35
36
|
interpolated_key: "Global? (!test_key!)",
|
36
37
|
interpolated_scoped_key: "Global? (!test_scoped_key!)",
|
37
38
|
interpol_arg_key: "Interpolate global? (!interpolated_key!)",
|
@@ -86,6 +87,12 @@ describe TextHelpers::Translation do
|
|
86
87
|
assert_equal expected, @helper.html(:single_word_list_key)
|
87
88
|
end
|
88
89
|
|
90
|
+
it "correctly handles orphans in HTML with erratic whitespace" do
|
91
|
+
expected = "<ul>\n <li> Get everything you ever wanted</li>\n <li> Practically-guaranteed</li>\n </ul>\n"
|
92
|
+
|
93
|
+
assert_equal expected, @helper.html(:prerendered_html_key)
|
94
|
+
end
|
95
|
+
|
89
96
|
it "does not modify HTML tags" do
|
90
97
|
expected = "<p><a href=\"mailto:#{@email_address}\">#{@email_address}</a></p>\n"
|
91
98
|
assert_equal expected, @helper.html(:email_key)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.6
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: TextHelpers is a gem which supplies some basic utilities for text localization
|