sitediff 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.export
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
@@ -68,6 +68,8 @@ class SiteDiff
68
68
 
69
69
  # Printable URL
70
70
  def url(tag, prefix, cache)
71
+ return unless prefix
72
+
71
73
  base = cache.read_tags.include?(tag) ? "/cache/#{tag}" : prefix
72
74
  base.to_s + path
73
75
  end
@@ -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
@@ -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.0.0
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-08 00:00:00.000000000 Z
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.4'
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: []