text_helpers 0.2.2 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 320e647924e409f4729c273ce71c68c2042c3748
4
- data.tar.gz: f5a7f39ee0319697a1f6569666b28083043b892d
3
+ metadata.gz: 4e2db46337e4ccd6c5cf3609f275c86577e6b279
4
+ data.tar.gz: 8e70eb0089b918df6c827b431a1ef309d88206ae
5
5
  SHA512:
6
- metadata.gz: a12a9414e716c6cc7c7d7a7a4265cb20222bced8ea6d607d0e2cfed59f08f0b8fcc3f9159f6013befd721b217a8040080a25406e09f0dac04fe85775bdeeff37
7
- data.tar.gz: c81f7a27c1467d3d3c924f11176e7058d5dbf744e2326f4c48da33a6c126f36cf26443b33c539f2e76d02b14a0fef8b7242884481e3b69e7396753a1deee3cab
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 "github/markdown"
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 = GitHub::Markdown.render(text(key, options))
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.
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/text_helpers.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'text_helpers/version'
2
- require 'text_helpers/translation'
3
- require 'text_helpers/railtie' if defined?(Rails)
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>&ldquo;#{@global_text}&rdquo;&ndash;#{@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('activesupport')
26
- gem.add_dependency('i18n', '>=0.6.8')
27
- gem.add_dependency('github-markdown')
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.2.2
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-10 00:00:00.000000000 Z
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: github-markdown
42
+ name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='