sitediff 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sitediff.rb +3 -1
- data/lib/sitediff/api.rb +265 -0
- data/lib/sitediff/cache.rb +18 -0
- data/lib/sitediff/cli.rb +58 -214
- data/lib/sitediff/config.rb +78 -6
- data/lib/sitediff/config/creator.rb +8 -6
- data/lib/sitediff/crawler.rb +9 -9
- data/lib/sitediff/diff.rb +5 -1
- data/lib/sitediff/files/report.html.erb +35 -8
- data/lib/sitediff/files/sitediff.css +78 -1
- data/lib/sitediff/files/sitediff.js +204 -13
- data/lib/sitediff/report.rb +17 -1
- data/lib/sitediff/result.rb +2 -0
- data/lib/sitediff/sanitize.rb +49 -1
- data/lib/sitediff/uriwrapper.rb +4 -1
- metadata +7 -6
data/lib/sitediff/report.rb
CHANGED
@@ -69,6 +69,8 @@ class SiteDiff
|
|
69
69
|
)
|
70
70
|
report_before ||= @config.before_url
|
71
71
|
report_after ||= @config.after_url
|
72
|
+
@config.before_time = get_timestamp(:before)
|
73
|
+
@config.after_time = get_timestamp(:after)
|
72
74
|
|
73
75
|
dir = SiteDiff.ensure_dir dir
|
74
76
|
|
@@ -81,7 +83,7 @@ class SiteDiff
|
|
81
83
|
report_before,
|
82
84
|
report_after,
|
83
85
|
@cache,
|
84
|
-
@config
|
86
|
+
@config
|
85
87
|
)
|
86
88
|
|
87
89
|
# Write report.
|
@@ -234,5 +236,19 @@ class SiteDiff
|
|
234
236
|
output += File.read(File.join(SiteDiff::FILES_DIR, 'sitediff.js'))
|
235
237
|
output
|
236
238
|
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
# Get crawl timestamps
|
243
|
+
def get_timestamp(tag)
|
244
|
+
timestamp_file = File.join(@config.directory, 'snapshot', tag.to_s, SiteDiff::Cache::TIMESTAMP_FILE)
|
245
|
+
if File.exist? timestamp_file
|
246
|
+
file = File::Stat.new(timestamp_file)
|
247
|
+
time = file.mtime
|
248
|
+
time.class == Time ? time.strftime('%Y-%m-%d %H:%M') : ''
|
249
|
+
else
|
250
|
+
'unknown'
|
251
|
+
end
|
252
|
+
end
|
237
253
|
end
|
238
254
|
end
|
data/lib/sitediff/result.rb
CHANGED
data/lib/sitediff/sanitize.rb
CHANGED
@@ -35,7 +35,7 @@ class SiteDiff
|
|
35
35
|
@html = nil
|
36
36
|
|
37
37
|
remove_spacing
|
38
|
-
selector
|
38
|
+
regions || selector
|
39
39
|
dom_transforms
|
40
40
|
regexps
|
41
41
|
|
@@ -84,6 +84,13 @@ class SiteDiff
|
|
84
84
|
Sanitizer.remove_node_spacing(@node) if rule['value']
|
85
85
|
end
|
86
86
|
|
87
|
+
# Perform 'regions' action, don't perform 'selector' if regions exist.
|
88
|
+
def regions
|
89
|
+
return unless validate_regions
|
90
|
+
|
91
|
+
@node = select_regions(@node, @config['regions'], @opts[:output])
|
92
|
+
end
|
93
|
+
|
87
94
|
# Perform 'selector' action, to choose a new root
|
88
95
|
def selector
|
89
96
|
(rule = canonicalize_rule('selector')) || return
|
@@ -135,6 +142,20 @@ class SiteDiff
|
|
135
142
|
end
|
136
143
|
end
|
137
144
|
|
145
|
+
# Restructure the node into regions.
|
146
|
+
def select_regions(node, regions, output)
|
147
|
+
regions = output.map do |name|
|
148
|
+
selector = get_named_region(regions, name)['selector']
|
149
|
+
region = Nokogiri::XML.fragment('<region id="' + name + '"></region>').at_css('region')
|
150
|
+
matching = node.css(selector)
|
151
|
+
matching.each { |m| region.add_child m }
|
152
|
+
region
|
153
|
+
end
|
154
|
+
node = Nokogiri::HTML.fragment('')
|
155
|
+
regions.each { |r| node.add_child r }
|
156
|
+
node
|
157
|
+
end
|
158
|
+
|
138
159
|
# Get a fragment consisting of the elements matching the selector(s)
|
139
160
|
def self.select_fragments(node, sel)
|
140
161
|
# When we choose a new root, we always become a DocumentFragment,
|
@@ -208,5 +229,32 @@ class SiteDiff
|
|
208
229
|
to_document(domify(obj, false))
|
209
230
|
end
|
210
231
|
end
|
232
|
+
|
233
|
+
private
|
234
|
+
|
235
|
+
# Validate `regions` and `output` from config.
|
236
|
+
def validate_regions
|
237
|
+
return false unless @config['regions'].is_a?(Array)
|
238
|
+
|
239
|
+
return false unless @opts[:output].is_a?(Array)
|
240
|
+
|
241
|
+
regions = @config['regions']
|
242
|
+
output = @opts[:output]
|
243
|
+
regions.each do |region|
|
244
|
+
return false unless region.key?('name') && region.key?('selector')
|
245
|
+
end
|
246
|
+
|
247
|
+
# Check that each named output has an associated region.
|
248
|
+
output.each do |name|
|
249
|
+
return false unless get_named_region(regions, name)
|
250
|
+
end
|
251
|
+
|
252
|
+
true
|
253
|
+
end
|
254
|
+
|
255
|
+
# Return the selector from a named region.
|
256
|
+
def get_named_region(regions, name)
|
257
|
+
regions.find { |region| region['name'] == name }
|
258
|
+
end
|
211
259
|
end
|
212
260
|
end
|
data/lib/sitediff/uriwrapper.rb
CHANGED
@@ -17,7 +17,10 @@ class SiteDiff
|
|
17
17
|
followlocation: true,
|
18
18
|
headers: {
|
19
19
|
'User-Agent' => 'Sitediff - https://github.com/evolvingweb/sitediff'
|
20
|
-
}
|
20
|
+
},
|
21
|
+
# always accept SSL certs
|
22
|
+
ssl_verifypeer: false,
|
23
|
+
ssl_verifyhost: 0
|
21
24
|
}.freeze
|
22
25
|
|
23
26
|
# This lets us treat errors or content as one object
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitediff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dergachev
|
8
8
|
- Amir Kadivar
|
9
9
|
- Dave Vasilevsky
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-06
|
13
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pkg-config
|
@@ -139,6 +139,7 @@ extra_rdoc_files: []
|
|
139
139
|
files:
|
140
140
|
- bin/sitediff
|
141
141
|
- lib/sitediff.rb
|
142
|
+
- lib/sitediff/api.rb
|
142
143
|
- lib/sitediff/cache.rb
|
143
144
|
- lib/sitediff/cli.rb
|
144
145
|
- lib/sitediff/config.rb
|
@@ -169,7 +170,7 @@ licenses:
|
|
169
170
|
- GPL-2.0
|
170
171
|
metadata:
|
171
172
|
source_code_uri: https://github.com/evolvingweb/sitediff
|
172
|
-
post_install_message:
|
173
|
+
post_install_message:
|
173
174
|
rdoc_options: []
|
174
175
|
require_paths:
|
175
176
|
- lib
|
@@ -177,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
178
|
requirements:
|
178
179
|
- - ">="
|
179
180
|
- !ruby/object:Gem::Version
|
180
|
-
version: '2.
|
181
|
+
version: '2.6'
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
requirements:
|
183
184
|
- - ">="
|
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
188
|
rubygems_version: 3.1.2
|
188
|
-
signing_key:
|
189
|
+
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Compare two versions of a site with ease!
|
191
192
|
test_files: []
|