text_helpers 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/text_helpers/translation.rb +12 -2
- data/lib/text_helpers/version.rb +1 -1
- data/lib/text_helpers.rb +3 -3
- data/test/lib/text_helpers/translation_test.rb +6 -1
- data/text_helpers.gemspec +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e2db46337e4ccd6c5cf3609f275c86577e6b279
|
4
|
+
data.tar.gz: 8e70eb0089b918df6c827b431a1ef309d88206ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0acd95b3ea75f251c838679a6313cd3f3fd93c8f3dcb2647b6864116bd5b35c608b6ba80a1629ab74a3edc3ed2884e4f7b975c9c95409f6c8e6770c3e34d415
|
7
|
+
data.tar.gz: 44fe0277b39c60bdd06c8a6f2bc478cb60ad3494c7026c74edabf190e4346d86725fcbb694e464f3265a9ad91c1d1a6a1a5ad39ef5c47d10488c02ecff2019c4
|
data/README.md
CHANGED
@@ -44,6 +44,12 @@ html_safe (so HTML can be used here, when absolutely necessary).
|
|
44
44
|
`html` parses the requested text using Markdown, making it useful for rendering
|
45
45
|
larger pieces of text involving multiple paragraphs, list items or links.
|
46
46
|
|
47
|
+
`html` automatically parses Markdown using
|
48
|
+
[`SmartyPants`-style](http://daringfireball.net/projects/smartypants/)
|
49
|
+
character conversions, so you can write plain text and have the proper
|
50
|
+
typographical elements generated for you without having to explicitly insert
|
51
|
+
HTML entities for common cases.
|
52
|
+
|
47
53
|
If you want to render a small fragment of Markdown without `p` tag wrappers,
|
48
54
|
you can pass `inline: true` as an option to `html`.
|
49
55
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "i18n"
|
2
2
|
require "active_support/core_ext/string/output_safety"
|
3
|
-
require "
|
3
|
+
require "redcarpet"
|
4
4
|
|
5
5
|
module TextHelpers
|
6
6
|
|
@@ -43,7 +43,7 @@ module TextHelpers
|
|
43
43
|
#
|
44
44
|
# Returns a String containing the localized text rendered via Markdown
|
45
45
|
def html(key, options = {})
|
46
|
-
rendered =
|
46
|
+
rendered = markdown(text(key, options))
|
47
47
|
|
48
48
|
rendered = options[:orphans] ? rendered : rendered.gsub(ORPHAN_MATCHER, ' \1')
|
49
49
|
rendered = rendered.gsub(/<\/?p>/, '') if options[:inline]
|
@@ -52,6 +52,16 @@ module TextHelpers
|
|
52
52
|
|
53
53
|
protected
|
54
54
|
|
55
|
+
# Protected: Render the passed text as HTML via Markdown.
|
56
|
+
#
|
57
|
+
# text - A String representing the text which should be rendered to HTML.
|
58
|
+
#
|
59
|
+
# Returns a String.
|
60
|
+
def markdown(text)
|
61
|
+
@renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true)
|
62
|
+
Redcarpet::Render::SmartyPants.render(@renderer.render(text))
|
63
|
+
end
|
64
|
+
|
55
65
|
# Protected: The proper scope for I18n translation.
|
56
66
|
#
|
57
67
|
# Must be implemented by any classes which include this module.
|
data/lib/text_helpers/version.rb
CHANGED
data/lib/text_helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "text_helpers/version"
|
2
|
+
require "text_helpers/translation"
|
3
|
+
require "text_helpers/railtie" if defined?(Rails)
|
4
4
|
|
5
5
|
module TextHelpers; end
|
@@ -25,7 +25,8 @@ describe TextHelpers::Translation do
|
|
25
25
|
test_key: "*#{@scoped_text}*",
|
26
26
|
list_key: "* #{@scoped_text}",
|
27
27
|
interpolated_key: "Global? (!test_key!)",
|
28
|
-
recursive_key: "Recursively !test.interpolated_key!"
|
28
|
+
recursive_key: "Recursively !test.interpolated_key!",
|
29
|
+
quoted_key: "\"#{@global_text}\"--#{@scoped_text}"
|
29
30
|
}
|
30
31
|
}
|
31
32
|
end
|
@@ -88,6 +89,10 @@ describe TextHelpers::Translation do
|
|
88
89
|
it "handles recursive interpolation" do
|
89
90
|
assert_equal "Recursively Global? (#{@global_text})", @helper.text(:recursive_key)
|
90
91
|
end
|
92
|
+
|
93
|
+
it "automatically converts quotes and dashes to clean HTML replacements" do
|
94
|
+
assert_equal "<p>“#{@global_text}”–#{@nb_scoped_text}</p>\n", @helper.html(:quoted_key)
|
95
|
+
end
|
91
96
|
end
|
92
97
|
|
93
98
|
describe "when no valid scope is provided" do
|
data/text_helpers.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.version = TextHelpers::VERSION
|
23
23
|
gem.license = "MIT"
|
24
24
|
|
25
|
-
gem.add_dependency(
|
26
|
-
gem.add_dependency(
|
27
|
-
gem.add_dependency(
|
25
|
+
gem.add_dependency("activesupport")
|
26
|
+
gem.add_dependency("i18n", ">=0.6.8")
|
27
|
+
gem.add_dependency("redcarpet")
|
28
28
|
end
|
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.
|
4
|
+
version: 0.3.1
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: redcarpet
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|