html_massage 0.2.0 → 0.2.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.
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'reverse_markdown', :git => 'git://github.com/harlantwood/reverse_markdown.git'
4
-
5
3
  # Specify your gem's dependencies in html_massage.gemspec
6
4
  gemspec
data/README.md CHANGED
@@ -19,62 +19,63 @@ Give your HTML a massage, in just the ways it loves:
19
19
  </head>
20
20
  <body>
21
21
  <div id="header">My Site</div>
22
- <div>This is some great content!</div>
23
- <a href ="foo/bar.html">Click this link</a>
22
+ <div>This is some <i>great</i> content!</div>
24
23
  </body>
25
24
  </html>
26
25
  }
27
26
 
28
- puts HtmlMassage.html( html )
29
- # => "<div>This is some great content!</div>"
27
+ HtmlMassage.html( html )
28
+ # => "<div>This is some <i>great</i> content!</div>"
30
29
 
31
- puts HtmlMassage.text( html )
32
- # => "This is some great content!\n"
30
+ HtmlMassage.markdown( html )
31
+ # => "This is some _great_ content!"
33
32
 
34
- ### Content Only
33
+ HtmlMassage.text( html )
34
+ # => "This is some great content!"
35
35
 
36
- html_massage = HtmlMassage.new( html,
37
- :exclude => [ '#header' ] )
38
- # => #<HtmlMassager::HtmlMassage ... >
36
+ ### Custom includes and excludes
39
37
 
40
- puts html_massage.exclude!
41
- # <div>This is some great content!</div>
42
- # <a href="foo/bar.html">Click this link</a>
38
+ html = %{
39
+ <html>
40
+ <body>
41
+ <div class="custom_navigation">some links to other pages...</div>
42
+ <div>This is some <i>great</i> content!</div>
43
+ </body>
44
+ </html>
45
+ }
46
+
47
+ html_massage = HtmlMassage.new( html )
48
+ html_massage.exclude!( [ '.custom_navigation' ] )
49
+ html_massage.include!( [ 'body' ] )
50
+ html_massage.to_html
51
+ # => <div>This is some <i>great</i> content!</div>
43
52
 
44
53
  ### Sanitize HTML
45
54
 
46
- html_massage = HtmlMassage.new( html,
47
- :exclude => [ '#header' ] )
48
- # => #<HtmlMassager::HtmlMassage ... >
55
+ html = %{
56
+ <html>
57
+ <head>
58
+ <script type="text/javascript">document.write('I am a bad script');</script>
59
+ </head>
60
+ <body>
61
+ <div>This is some <i>great</i> content!</div>
62
+ </body>
63
+ </html>
64
+ }
49
65
 
50
- puts html_massage.sanitize_html!
51
- # <html>
52
- # <head>
53
- # </head>
54
- # <body>
55
- # <div id="header">My Site</div>
56
- # <div>This is some great content!</div>
57
- # </body>
58
- # </html>
66
+ html_massage = HtmlMassage.new( html )
67
+ html_massage.sanitize!( :elements => ['div'] )
68
+ html_massage.to_html
69
+ # => <div>This is some <i>great</i> content!</div>
59
70
 
60
71
  ### Make Links Absolute
61
72
 
62
- html_massage = HtmlMassage.new( html,
63
- :exclude => [ '#header' ],
64
- :source_url => 'http://example.com/joe/page1.html' )
65
-
66
- puts html_massage.absolutify_links!
67
- # <html>
68
- # <head>
69
- # <script type="text/javascript">document.write('I am a bad script');</script>
70
- # </head>
71
- # <body>
72
- # <div id="header">My Site</div>
73
- # <div>This is some great content!</div>
74
- # <a href ="http://example.com/joe/foo/bar.html">Click this link</a>
75
- # </body>
76
- # </html>
77
-
78
- puts html_massage.absolutify_images!
79
- #
73
+ html = %{
74
+ <a href ="/foo/bar.html">Click this link</a>
75
+ }
76
+
77
+ html_massage = HtmlMassage.new( html )
78
+ html_massage.absolutify_links!( 'http://example.com/joe/page1.html' )
79
+ html_massage.to_html
80
+ # <a href ="http://example.com/foo/bar.html">Click this link</a>
80
81
 
data/html_massage.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["code@harlantwood.net"]
11
11
  gem.homepage = "https://github.com/harlantwood/html_massage"
12
12
  gem.summary = %{Massages HTML how you want to.}
13
- gem.description = %{Massages HTML how you want to: sanitize tags, remove headers and footers, convert to plain text.}
13
+ gem.description = %{Massages HTML how you want to: sanitize tags, remove headers and footers; output to html, markdown, or plain text.}
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "sanitize", ">= 2.0"
22
22
  gem.add_dependency "thor"
23
23
  gem.add_dependency "rest-client", ">= 1.6"
24
+ gem.add_dependency "reverse_markdown", ">= 0.4"
24
25
 
25
26
  gem.add_development_dependency "rspec", ">= 2.5"
26
27
 
@@ -1,3 +1,3 @@
1
1
  module HtmlMassager
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/html_massage.rb CHANGED
@@ -185,8 +185,9 @@ module HtmlMassager
185
185
  def massage!( options={} )
186
186
  self.class.translate_old_options( options )
187
187
  options = DEFAULTS.merge( options )
188
- absolutify_links!(options[:source_url]) if options.delete( :links ) == :absolute
189
- absolutify_images!(options[:source_url]) if options.delete( :images ) == :absolute
188
+ source_url = options.delete( :source_url )
189
+ absolutify_links!(source_url) if options.delete( :links ) == :absolute
190
+ absolutify_images!(source_url) if options.delete( :images ) == :absolute
190
191
  include!( options.delete( :include ) )
191
192
  exclude!( options.delete( :exclude ) )
192
193
  sanitize!( options.delete( :sanitize ) )
@@ -204,7 +205,7 @@ module HtmlMassager
204
205
  selectors_to_exclude.to_a.each do |selector_to_exclude|
205
206
  ( doc / selector_to_exclude ).remove
206
207
  end
207
- @html = doc.to_s
208
+ @html = doc.inner_html
208
209
  end
209
210
 
210
211
  def include!( selectors_to_include )
@@ -225,7 +226,6 @@ module HtmlMassager
225
226
  end
226
227
 
227
228
  @html = Sanitize.clean( @html, sanitize_options )
228
- @html
229
229
  end
230
230
 
231
231
  def absolutify_links!(source_url)
@@ -146,6 +146,15 @@ describe HtmlMassager::HtmlMassage do
146
146
  end
147
147
 
148
148
  it 'should work for relative links' do
149
+ pending
150
+ source_url = 'http://en.wikipedia.org/wiki/Singularity'
151
+ original_html = '<a href="Ray_Kurzweil">Ray</a>'
152
+ html_massager = HtmlMassage.new( original_html )
153
+ html_massager.absolutify_links!(source_url).should ==
154
+ '<a href="http://en.wikipedia.org/wiki/Ray_Kurzweil">Ray</a>'
155
+ end
156
+
157
+ it 'should work for relative links to a parent director' do
149
158
  source_url = 'http://en.wikipedia.org/wiki/Singularity'
150
159
  original_html = '<a href="../wiki/Ray_Kurzweil">Ray</a>'
151
160
  html_massager = HtmlMassage.new( original_html )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_massage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '1.6'
78
+ - !ruby/object:Gem::Dependency
79
+ name: reverse_markdown
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0.4'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0.4'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: rspec
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -91,8 +107,8 @@ dependencies:
91
107
  - - ! '>='
92
108
  - !ruby/object:Gem::Version
93
109
  version: '2.5'
94
- description: ! 'Massages HTML how you want to: sanitize tags, remove headers and footers,
95
- convert to plain text.'
110
+ description: ! 'Massages HTML how you want to: sanitize tags, remove headers and footers;
111
+ output to html, markdown, or plain text.'
96
112
  email:
97
113
  - code@harlantwood.net
98
114
  executables: