text_helpers 0.3.1 → 0.3.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: 4e2db46337e4ccd6c5cf3609f275c86577e6b279
4
- data.tar.gz: 8e70eb0089b918df6c827b431a1ef309d88206ae
3
+ metadata.gz: f610ed6fbdfcc77dc691a49ec829c6476a061f08
4
+ data.tar.gz: 244695c5fe67c660b3c140d75a68c4deb5f3e529
5
5
  SHA512:
6
- metadata.gz: b0acd95b3ea75f251c838679a6313cd3f3fd93c8f3dcb2647b6864116bd5b35c608b6ba80a1629ab74a3edc3ed2884e4f7b975c9c95409f6c8e6770c3e34d415
7
- data.tar.gz: 44fe0277b39c60bdd06c8a6f2bc478cb60ad3494c7026c74edabf190e4346d86725fcbb694e464f3265a9ad91c1d1a6a1a5ad39ef5c47d10488c02ecff2019c4
6
+ metadata.gz: 1bad27e3bf042294009be3a0924c761e9ddac5ff51024a32032cf4d2b9f5a7dc586a17b77258e45b9211690ee55245fe74e5c45b870ed6af5df8f8c2944884e6
7
+ data.tar.gz: 4450a67219284ab29a6d8f6cded17ce561764ae274f1804c45304d4e77795b0d623658821d9bc29dd1602c0a2d64b88a072e02294d9d68f21f356f6091fa7e11
@@ -15,6 +15,8 @@ module TextHelpers
15
15
  # :orphans - A special option that will prevent the insertion of
16
16
  # non-breaking space characters at the end of the text
17
17
  # when set to true.
18
+ # :smart - Whether or not to apply smart quoting to the output.
19
+ # Defaults to true.
18
20
  #
19
21
  # Returns a String resulting from the I18n lookup.
20
22
  def text(key, options = {})
@@ -28,6 +30,7 @@ module TextHelpers
28
30
  text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1) }
29
31
  end
30
32
 
33
+ text = smartify(text) if options.fetch(:smart, true)
31
34
  text.html_safe
32
35
  end
33
36
 
@@ -43,7 +46,7 @@ module TextHelpers
43
46
  #
44
47
  # Returns a String containing the localized text rendered via Markdown
45
48
  def html(key, options = {})
46
- rendered = markdown(text(key, options))
49
+ rendered = markdown(text(key, options.merge(smart: false)))
47
50
 
48
51
  rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, ' \1')
49
52
  rendered = rendered.gsub(/<\/?p>/, '') if options[:inline]
@@ -59,7 +62,16 @@ module TextHelpers
59
62
  # Returns a String.
60
63
  def markdown(text)
61
64
  @renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true)
62
- Redcarpet::Render::SmartyPants.render(@renderer.render(text))
65
+ smartify(@renderer.render(text))
66
+ end
67
+
68
+ # Protected: Auto-apply smart quotes and to the passed text.
69
+ #
70
+ # text - A String which should be passed through the SmartyPants renderer.
71
+ #
72
+ # Returns a String.
73
+ def smartify(text)
74
+ Redcarpet::Render::SmartyPants.render(text)
63
75
  end
64
76
 
65
77
  # Protected: The proper scope for I18n translation.
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -26,7 +26,7 @@ describe TextHelpers::Translation do
26
26
  list_key: "* #{@scoped_text}",
27
27
  interpolated_key: "Global? (!test_key!)",
28
28
  recursive_key: "Recursively !test.interpolated_key!",
29
- quoted_key: "\"#{@global_text}\"--#{@scoped_text}"
29
+ quoted_key: "They're looking for \"#{@global_text}\"--#{@scoped_text}"
30
30
  }
31
31
  }
32
32
  end
@@ -90,8 +90,16 @@ describe TextHelpers::Translation do
90
90
  assert_equal "Recursively Global? (#{@global_text})", @helper.text(:recursive_key)
91
91
  end
92
92
 
93
+ it "applies smart quotes to text by default" do
94
+ assert_equal "They&rsquo;re looking for &ldquo;#{@global_text}&rdquo;&ndash;#{@scoped_text}", @helper.text(:quoted_key)
95
+ end
96
+
97
+ it "allows smart quoting to be disabled" do
98
+ assert_equal "They're looking for \"#{@global_text}\"--#{@scoped_text}", @helper.text(:quoted_key, smart: false)
99
+ end
100
+
93
101
  it "automatically converts quotes and dashes to clean HTML replacements" do
94
- assert_equal "<p>&ldquo;#{@global_text}&rdquo;&ndash;#{@nb_scoped_text}</p>\n", @helper.html(:quoted_key)
102
+ assert_equal "<p>They&rsquo;re looking for &ldquo;#{@global_text}&rdquo;&ndash;#{@nb_scoped_text}</p>\n", @helper.html(:quoted_key)
95
103
  end
96
104
  end
97
105
 
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.3.1
4
+ version: 0.3.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-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport