text_helpers 0.3.1 → 0.3.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 +4 -4
- data/lib/text_helpers/translation.rb +14 -2
- data/lib/text_helpers/version.rb +1 -1
- data/test/lib/text_helpers/translation_test.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f610ed6fbdfcc77dc691a49ec829c6476a061f08
|
4
|
+
data.tar.gz: 244695c5fe67c660b3c140d75a68c4deb5f3e529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
data/lib/text_helpers/version.rb
CHANGED
@@ -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’re looking for “#{@global_text}”–#{@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
|
102
|
+
assert_equal "<p>They’re looking for “#{@global_text}”–#{@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.
|
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-
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|