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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aab61ab2ec51e7a9457ad3fc762341ecc59862b7
4
- data.tar.gz: 687b06a1b1ee2447c5fb29248307f74726550589
2
+ SHA256:
3
+ metadata.gz: bd673fcea44270d6cdcfeb8b87938e7224c2a111520ef859e35ce1df4ba785b1
4
+ data.tar.gz: fb7470beacfab30cfadd994023ae33f00753ddb7714854b642d8257561550491
5
5
  SHA512:
6
- metadata.gz: c03051dbfce0714ee802493eb44ecabeeb669b9eef87a847b5a21c3a03380832f247ed9192032b804dd8363046fe8c474600fbd3bc16c221587d7337bf380f2a
7
- data.tar.gz: 800a199fde5ee931a01078e1a08f2587952b577c9852b30dae3ea726f24cd3d6740edd96d1277871718df97f815b72bb80f16bc1cb1dd1c65d09ce2dbfbe7438
6
+ metadata.gz: 63302f4838675fd77e69186b58fb6a91948c1d4d34f2f55779af8c2a615f07d9568a4a7c0771155036851ce2f74fc5f6b1d8f90ea81150ee294e1eb0ff90f281
7
+ data.tar.gz: 38288b327cc615cd9a63c37e581b0ac707e9568087189e38ac5bfd2f64c988124b1b359b4e63bc63b3c8f9a3e5ea2c93c639239f94a4fc32f9d63838c15e9341
data/Rakefile CHANGED
@@ -4,6 +4,7 @@ require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.pattern = "test/**/*_test.rb"
7
+ t.warning = false
7
8
  end
8
9
 
9
10
  task default: :test
@@ -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 =~ /!([\w._\/]+)!/ do
47
- text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1, interpolation_options) }
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, '&nbsp;\1')
69
+ rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, '\1&nbsp;\2')
69
70
  rendered = rendered.gsub(/<\/?p>/, '') if options[:inline]
70
71
  rendered.html_safe
71
72
  end
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -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&nbsp;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.1
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.4.5
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