wraptext 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,8 +44,10 @@ module Wraptext
44
44
  def replace_single_breaks
45
45
  nodes = @root.xpath("//p//text()")
46
46
  nodes.each do |node|
47
- frag = Nokogiri::HTML::DocumentFragment.parse node.content.gsub(/(\r\n|\n)/, "<br />")
48
- node.swap frag
47
+ if node.content.match(/[\r\n]/)
48
+ frag = Nokogiri::HTML::DocumentFragment.parse node.content.gsub(/(\r\n|\n)/, "<br />")
49
+ node.swap frag
50
+ end
49
51
  end
50
52
 
51
53
  @root.xpath("//p").each do |node|
@@ -82,6 +84,7 @@ module Wraptext
82
84
  # simple_format is not appropriate here, as it does not consider block-level
83
85
  # html element context when performing substitutions.
84
86
  def reparent_nodes(top, parent)
87
+ return if parent.nil?
85
88
  for i in (0..parent.children.length - 1) do
86
89
  node = parent.children[i]
87
90
  # Block-level tags like <div> and <blockquote> should be traversed into.
@@ -148,6 +148,21 @@ EOF
148
148
  <p>This is some <em>emphasized</em> text</p>
149
149
  <p>And here is <i>another</i> line</p>
150
150
  EOF
151
- Wraptext::Parser.new(doc).to_html.should == expects.strip
151
+ specify { Wraptext::Parser.new(doc).to_html.should == expects.strip }
152
+ end
153
+
154
+ context "when passed an empty document" do
155
+ specify { expect { Wraptext::Parser.new("") }.to_not raise_error }
156
+ end
157
+
158
+ context "Given an article with two concurrent non-block tags" do
159
+ let(:article) {<<-EOF
160
+ A "Get the Facts" button sends you to a <em>Washington Post</em> <a href="http://www.washingtonpost.com/wp-srv/special/politics/campaign-finance/" target="_blank">article</a> about campaign finance.
161
+ EOF
162
+ }
163
+
164
+ it "should preserve spacing between non-block tags" do
165
+ Wraptext::Parser.new(article).to_html.should match("</em> <a")
166
+ end
152
167
  end
153
168
  end
data/wraptext.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
12
  gem.name = "wraptext"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.1.3"
14
+ gem.version = "0.1.4"
15
15
 
16
16
  gem.add_dependency('nokogiri')
17
17
  end
metadata CHANGED
@@ -1,25 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wraptext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
4
  prerelease:
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Heald
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: nokogiri
15
+ type: :runtime
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  none: false
@@ -27,6 +26,7 @@ dependencies:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: '0'
29
+ name: nokogiri
30
30
  description: Wraps bare text nodes from an HTML document in <p> tags and splits text
31
31
  nodes on double newlines. Conveniently serves to format Wordpress post content properly
32
32
  as a side effect.
@@ -98,3 +98,4 @@ test_files:
98
98
  - spec/data/wordpress_autop.php
99
99
  - spec/spec_helper.rb
100
100
  - spec/wraptext/parser_spec.rb
101
+ has_rdoc: