snatch 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/snatch/clean.rb +8 -0
- data/lib/snatch/clean/html.rb +3 -3
- data/snatch.gemspec +3 -2
- data/spec/snatch/clean/html_spec.rb +2 -2
- data/xsl/pretty_print.xsl +47 -0
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.8
|
data/lib/snatch/clean.rb
CHANGED
@@ -22,5 +22,13 @@ class Snatch
|
|
22
22
|
|
23
23
|
File.open(@file_name, 'w') { |f| f.write @doc.to_xhtml }
|
24
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Sadly we can't use this as our XSLT won't output valid XHTML
|
29
|
+
# def clean_xhtml
|
30
|
+
# xsl_io = File.open(File.expand_path('../../../xsl/pretty_print.xsl', __FILE__))
|
31
|
+
# Nokogiri::XSLT(xsl_io).apply_to(@doc)
|
32
|
+
# end
|
25
33
|
end
|
26
34
|
end
|
data/lib/snatch/clean/html.rb
CHANGED
@@ -63,17 +63,17 @@ class Snatch
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def update
|
66
|
-
@doc.css('base, meta[generator]').each { |node| node.remove }
|
66
|
+
@doc.css('base, meta[name=generator]').each { |node| node.remove }
|
67
67
|
|
68
68
|
@doc.search('//comment()').remove
|
69
69
|
|
70
|
+
klass = Class.new { include HrefFixMethods }.new
|
70
71
|
HrefFixMethods.instance_methods.each do |m|
|
71
|
-
klass = Class.new { include HrefFixMethods }.new
|
72
72
|
@doc.css('a[href]').each { |a| klass.send m, a }
|
73
73
|
end
|
74
74
|
|
75
|
+
klass = Class.new { include SrcFixMethods }.new
|
75
76
|
SrcFixMethods.instance_methods.each do |m|
|
76
|
-
klass = Class.new { include SrcFixMethods }.new
|
77
77
|
@doc.css('[src]').each { |a| klass.send m, a }
|
78
78
|
end
|
79
79
|
end
|
data/snatch.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{snatch}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Conroy-Finn"]
|
@@ -36,7 +36,8 @@ Gem::Specification.new do |s|
|
|
36
36
|
"spec/snatch_spec.rb",
|
37
37
|
"spec/spec.opts",
|
38
38
|
"spec/spec_helper.rb",
|
39
|
-
"spec/support/matchers/nokogiri.rb"
|
39
|
+
"spec/support/matchers/nokogiri.rb",
|
40
|
+
"xsl/pretty_print.xsl"
|
40
41
|
]
|
41
42
|
s.homepage = %q{http://github.com/jcf/snatch}
|
42
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -14,7 +14,7 @@ describe Snatch::Clean::HTML do
|
|
14
14
|
|
15
15
|
it 'should remove any base tags' do
|
16
16
|
mock_nodes = [(mock_node = mock('nokogiri_node'))]
|
17
|
-
@html.doc.should_receive(:css).with('base, meta[generator]').and_return(mock_nodes)
|
17
|
+
@html.doc.should_receive(:css).with('base, meta[name=generator]').and_return(mock_nodes)
|
18
18
|
@html.doc.should_receive(:search).and_return(mock_node)
|
19
19
|
mock_node.should_receive(:remove).twice.and_return([])
|
20
20
|
mock_nodes.should_receive(:each).and_yield(mock_node)
|
@@ -23,7 +23,7 @@ describe Snatch::Clean::HTML do
|
|
23
23
|
|
24
24
|
it 'should remove comments and the generator meta tag' do
|
25
25
|
mock_nodes = [(mock_node = mock('nokogiri_node'))]
|
26
|
-
@html.doc.should_receive(:css).with('base, meta[generator]').and_return([])
|
26
|
+
@html.doc.should_receive(:css).with('base, meta[name=generator]').and_return([])
|
27
27
|
@html.doc.should_receive(:search).with('//comment()').and_return(mock_nodes)
|
28
28
|
mock_nodes.should_receive(:remove).and_return([mock_node])
|
29
29
|
@html.send(:update)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2
|
+
<xsl:output method="xml" encoding="ISO-8859-1"/>
|
3
|
+
<xsl:param name="indent-increment" select="' '"/>
|
4
|
+
|
5
|
+
<xsl:template name="newline">
|
6
|
+
<xsl:text disable-output-escaping="yes">
|
7
|
+
</xsl:text>
|
8
|
+
</xsl:template>
|
9
|
+
|
10
|
+
<xsl:template match="comment() | processing-instruction()">
|
11
|
+
<xsl:param name="indent" select="''"/>
|
12
|
+
<xsl:call-template name="newline"/>
|
13
|
+
<xsl:value-of select="$indent"/>
|
14
|
+
<xsl:copy />
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
<xsl:template match="text()">
|
18
|
+
<xsl:param name="indent" select="''"/>
|
19
|
+
<xsl:call-template name="newline"/>
|
20
|
+
<xsl:value-of select="$indent"/>
|
21
|
+
<xsl:value-of select="normalize-space(.)"/>
|
22
|
+
</xsl:template>
|
23
|
+
|
24
|
+
<xsl:template match="text()[normalize-space(.)='']"/>
|
25
|
+
|
26
|
+
<xsl:template match="*">
|
27
|
+
<xsl:param name="indent" select="''"/>
|
28
|
+
<xsl:call-template name="newline"/>
|
29
|
+
<xsl:value-of select="$indent"/>
|
30
|
+
<xsl:choose>
|
31
|
+
<xsl:when test="count(child::*) > 0">
|
32
|
+
<xsl:copy>
|
33
|
+
<xsl:copy-of select="@*"/>
|
34
|
+
<xsl:apply-templates select="*|text()">
|
35
|
+
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
|
36
|
+
</xsl:apply-templates>
|
37
|
+
<xsl:call-template name="newline"/>
|
38
|
+
<xsl:value-of select="$indent"/>
|
39
|
+
</xsl:copy>
|
40
|
+
</xsl:when>
|
41
|
+
<xsl:otherwise>
|
42
|
+
<xsl:copy-of select="."/>
|
43
|
+
</xsl:otherwise>
|
44
|
+
</xsl:choose>
|
45
|
+
</xsl:template>
|
46
|
+
</xsl:stylesheet>
|
47
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Conroy-Finn
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- spec/spec.opts
|
63
63
|
- spec/spec_helper.rb
|
64
64
|
- spec/support/matchers/nokogiri.rb
|
65
|
+
- xsl/pretty_print.xsl
|
65
66
|
has_rdoc: true
|
66
67
|
homepage: http://github.com/jcf/snatch
|
67
68
|
licenses: []
|