text_helpers 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e580b82c75e3cf43132b59a8ad149e2d390d8be7
4
- data.tar.gz: df4a31f298410004501ab0dad411f901e9394be4
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTMwYzMxZWUwYTRhNGViOWQzOTk5MTNkZmIzMmZjNWQ2ZmM0NTRjYQ==
5
+ data.tar.gz: !binary |-
6
+ Y2I1MzBlOWY2YTY3ZTUyNWQyODFkY2U0MGM5ZmQzOGYzZjY3NWNlMw==
5
7
  SHA512:
6
- metadata.gz: 65bee9783a1513a997add55402ee2dcef6da947f79cbe7ea893571aae457b47cd99501a2500a6add832c1321c89ecfa4d1e35554d68dfc382cf84d94eb8abc39
7
- data.tar.gz: 383ee4e7373779411aa47b22dbb62e08897305c2c6c1e51f99dd0d4350f909e7b43c6bf019c74d04ec310483cc5c583120dad5b63b2b63c14f38ddb5f094f63a
8
+ metadata.gz: !binary |-
9
+ MDVkYjljZWY5MmVmNjg3MjhiZWNkODU1ZTBiNDRkZjg3YjdmODI4YTg2MDE3
10
+ MmI5ZmQ4YTczOWYyNWQ5MWM1YzRhMGEyMTYyNzNkYWEzNWE4NGY0YjIwYTk5
11
+ ZTU0ZTI1MDQ3MmU3NTI5MTE0NDRhZjk4MzMzM2Y1NzFhZmQwYjc=
12
+ data.tar.gz: !binary |-
13
+ NDU2Y2IzNDVjYjFhZTc3ZGFlNmU2ZTdlMzViOTJlMTQxNjNiYzEwNzg5YmJh
14
+ MDZmMDY5MWJjYjgxOGRjZWZhMmU4NWM4YTg3ZDVmY2RjZTRlYjBlZGFlNzA3
15
+ MzMxMGRkZGZlYTk3ZGIzOTJlMTJhZTk0MGVhYmIwNDQwODJkNTc=
@@ -6,6 +6,8 @@ module TextHelpers
6
6
 
7
7
  module Translation
8
8
 
9
+ ORPHAN_MATCHER = /\s(?![^<]*>)(\S+\s*<\/(?:p|li)>)/.freeze
10
+
9
11
  # Public: Get the I18n localized text for the passed key.
10
12
  #
11
13
  # key - The desired I18n lookup key.
@@ -43,7 +45,7 @@ module TextHelpers
43
45
  def html(key, options = {})
44
46
  rendered = GitHub::Markdown.render(text(key, options.merge(orphans: true)))
45
47
 
46
- rendered = options[:orphans] ? rendered : rendered.gsub(/\s(\S+\s*<\/(?:p|li)>)/, '&nbsp;\1')
48
+ rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, '&nbsp;\1')
47
49
  rendered = rendered.gsub(/<\/?p>/, '') if options[:inline]
48
50
  rendered.html_safe
49
51
  end
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -8,6 +8,7 @@ describe TextHelpers::Translation do
8
8
  before do
9
9
  @scoped_text = "Scoped lookup"
10
10
  @global_text = "Global lookup"
11
+ @email_address = "user@example.org"
11
12
  @multiline_text = <<-MULTI.gsub(/^[ \t]+/, '')
12
13
  This is some multiline text.
13
14
 
@@ -21,6 +22,7 @@ describe TextHelpers::Translation do
21
22
  test_key: @global_text,
22
23
  multiline_key: @multiline_text,
23
24
  test: {
25
+ email_key: "<#{@email_address}>",
24
26
  test_key: "*#{@scoped_text}*",
25
27
  list_key: "* #{@scoped_text}",
26
28
  interpolated_key: "Global? (!test_key!)"
@@ -57,6 +59,11 @@ describe TextHelpers::Translation do
57
59
  assert_equal expected, @helper.html(:list_key)
58
60
  end
59
61
 
62
+ it "does not modify HTML tags" do
63
+ expected = "<p><a href=\"mailto:#{@email_address}\">#{@email_address}</a></p>\n"
64
+ assert_equal expected, @helper.html(:email_key)
65
+ end
66
+
60
67
  it "allows orphaned text with :orphans" do
61
68
  assert_equal "<p><em>#{@scoped_text}</em></p>\n", @helper.html(:test_key, orphans: true)
62
69
  end
data/test/test_helper.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'minitest/autorun'
2
2
  require File.expand_path('../../lib/text_helpers.rb', __FILE__)
3
+
4
+ I18n.enforce_available_locales = false
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
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-03 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: github-markdown
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Easily fetch text and static content from your locales
@@ -83,17 +83,17 @@ require_paths:
83
83
  - lib
84
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ! '>='
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - '>='
91
+ - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.0.6
96
+ rubygems_version: 2.1.11
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: TextHelpers is a gem which supplies some basic utilities for text localization