sitediff 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,98 +1,139 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sitediff'
2
4
  require 'sitediff/webserver'
3
5
  require 'erb'
4
6
 
5
7
  class SiteDiff
6
- class Webserver
7
- class ResultServer < Webserver
8
- # Display a page from the cache
9
- class CacheServlet < WEBrick::HTTPServlet::AbstractServlet
10
- def initialize(server, cache)
11
- @cache = cache
12
- end
8
+ class Webserver
9
+ class ResultServer < Webserver
10
+ # Display a page from the cache
11
+ class CacheServlet < WEBrick::HTTPServlet::AbstractServlet
12
+ def initialize(_server, cache)
13
+ @cache = cache
14
+ end
13
15
 
14
- def do_GET(req, res)
15
- path = req.path_info
16
- md = %r[^/([^/]+)(/.*)$].match(path) or
17
- raise WEBrick::HTTPStatus::NotFound
18
- tag, path = *md.captures
19
- r = @cache.get(tag.to_sym, path) or
20
- raise WEBrick::HTTPStatus::NotFound
16
+ def do_GET(req, res)
17
+ path = req.path_info
18
+ (md = %r{^/([^/]+)(/.*)$}.match(path)) ||
19
+ raise(WEBrick::HTTPStatus::NotFound)
20
+ tag, path = *md.captures
21
+ (r = @cache.get(tag.to_sym, path)) ||
22
+ raise(WEBrick::HTTPStatus::NotFound)
21
23
 
22
- raise WEBrick::HTTPStatus[r.error_code] if r.error_code
23
- raise WEBrick::HTTPStatus::InternalServerError, r.error if r.error
24
+ raise WEBrick::HTTPStatus[r.error_code] if r.error_code
25
+ raise WEBrick::HTTPStatus::InternalServerError, r.error if r.error
24
26
 
25
- res['content-type'] = 'text/html'
26
- res.body = r.content
27
- end
28
- end
27
+ res['content-type'] = 'text/html'
28
+ res.body = r.content
29
+ end
30
+ end
29
31
 
30
- # Display two pages side by side
31
- class SideBySideServlet < WEBrick::HTTPServlet::AbstractServlet
32
- def initialize(server, cache, settings)
33
- @cache = cache
34
- @settings = settings
35
- end
32
+ # Display two pages side by side
33
+ class SideBySideServlet < WEBrick::HTTPServlet::AbstractServlet
34
+ def initialize(_server, cache, settings)
35
+ @cache = cache
36
+ @settings = settings
37
+ end
38
+
39
+ def urls(path)
40
+ %w[before after].map do |tag|
41
+ base = @settings[tag]
42
+ base = "/cache/#{tag}" if @settings['cached'].include? tag
43
+ base + path
44
+ end
45
+ end
36
46
 
37
- def urls(path)
38
- %w[before after].map do |tag|
39
- base = @settings[tag]
40
- base = "/cache/#{tag}" if @settings['cached'].include? tag
41
- base + path
47
+ def do_GET(req, res)
48
+ path = req.path_info
49
+ before, after = *urls(path)
50
+
51
+ res['content-type'] = 'text/html'
52
+ erb = File.join(SiteDiff::FILES_DIR, 'sidebyside.html.erb')
53
+ res.body = ERB.new(File.read(erb)).result(binding)
54
+ end
42
55
  end
43
- end
44
56
 
45
- def do_GET(req, res)
46
- path = req.path_info
47
- before, after = *urls(path)
57
+ # Run sitediff command from browser. Probably dangerous in general.
58
+ class RunServlet < WEBrick::HTTPServlet::AbstractServlet
59
+ def initialize(_server, dir)
60
+ @dir = dir
61
+ end
48
62
 
49
- res['content-type'] = 'text/html'
50
- erb = File.join(SiteDiff::FILES_DIR, 'sidebyside.html.erb')
51
- res.body = ERB.new(File.read(erb)).result(binding)
52
- end
53
- end
63
+ def do_GET(req, res)
64
+ path = req.path_info
65
+ if path != '/diff'
66
+ res['content-type'] = 'text/plain'
67
+ res.body = 'ERROR: Only /run/diff is supported by the /run API at the moment'
68
+ return
69
+ end
70
+ # Thor assumes only one command is called and some values like
71
+ # `options` are share across all SiteDiff::Cli instances so
72
+ # we can't just call SiteDiff::Cli.new().diff
73
+ # This is likely to go very wrong depending on how `sitediff serve`
74
+ # was actually called
75
+ cmd = "#{$PROGRAM_NAME} diff -C #{@dir} --cached=all"
76
+ system(cmd)
54
77
 
55
- def initialize(port, dir, opts = {})
56
- @settings = YAML.load_file(File.join(dir, SiteDiff::SETTINGS_FILE))
57
- @cache = opts[:cache]
58
- super(port, [dir], opts)
59
- end
78
+ # Could also add a message to indicate success/failure
79
+ # But for the moment, all our files are static
80
+ res.set_redirect(WEBrick::HTTPStatus::Found,
81
+ "/files/#{SiteDiff::REPORT_FILE}")
82
+ end
83
+ end
60
84
 
61
- def server(opts)
62
- dir = opts.delete(:DocumentRoot)
63
- srv = super(opts)
64
- srv.mount_proc('/') do |req, res|
65
- res.set_redirect(WEBrick::HTTPStatus::Found,
66
- "/files/#{SiteDiff::REPORT_FILE}")
67
- end
85
+ def initialize(port, dir, opts = {})
86
+ unless File.exist?(File.join(dir, SiteDiff::SETTINGS_FILE))
87
+ raise SiteDiffException,
88
+ "Please run 'sitediff diff' before running 'sitediff serve'"
89
+ end
68
90
 
69
- srv.mount('/files', WEBrick::HTTPServlet::FileHandler, dir, true)
70
- srv.mount('/cache', CacheServlet, @cache)
71
- srv.mount('/sidebyside', SideBySideServlet, @cache, @settings)
72
- return srv
73
- end
91
+ @settings = YAML.load_file(File.join(dir, SiteDiff::SETTINGS_FILE))
92
+ @cache = opts[:cache]
93
+ super(port, [dir], opts)
94
+ end
74
95
 
75
- def setup
76
- super
77
- root = uris.first
78
- puts "Serving at #{root}"
79
- open_in_browser(root) if @opts[:browse]
80
- end
96
+ def server(opts)
97
+ dir = opts.delete(:DocumentRoot)
98
+ srv = super(opts)
99
+ srv.mount_proc('/') do |req, res|
100
+ if req.path == '/'
101
+ res.set_redirect(WEBrick::HTTPStatus::Found,
102
+ "/files/#{SiteDiff::REPORT_FILE}")
103
+ else
104
+ res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect,
105
+ "#{@settings['after']}#{req.path}")
106
+ end
107
+ end
81
108
 
82
- def open_in_browser(url)
83
- commands = %w[xdg-open open]
84
- cmd = commands.find { |c| which(c) }
85
- system(cmd, url) if cmd
86
- return cmd
87
- end
109
+ srv.mount('/files', WEBrick::HTTPServlet::FileHandler, dir, true)
110
+ srv.mount('/cache', CacheServlet, @cache)
111
+ srv.mount('/sidebyside', SideBySideServlet, @cache, @settings)
112
+ srv.mount('/run', RunServlet, dir)
113
+ srv
114
+ end
88
115
 
89
- def which(cmd)
90
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
91
- file = File.join(path, cmd)
92
- return file if File.executable?(file)
116
+ def setup
117
+ super
118
+ root = uris.first
119
+ puts "Serving at #{root}"
120
+ open_in_browser(root) if @opts[:browse]
121
+ end
122
+
123
+ def open_in_browser(url)
124
+ commands = %w[xdg-open open]
125
+ cmd = commands.find { |c| which(c) }
126
+ system(cmd, url) if cmd
127
+ cmd
128
+ end
129
+
130
+ def which(cmd)
131
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
132
+ file = File.join(path, cmd)
133
+ return file if File.executable?(file)
134
+ end
135
+ nil
136
+ end
93
137
  end
94
- return nil
95
138
  end
96
139
  end
97
- end
98
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitediff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dergachev
@@ -10,22 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-10 00:00:00.000000000 Z
13
+ date: 2018-12-14 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pkg-config
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.1'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: thor
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
33
  - - "~>"
20
34
  - !ruby/object:Gem::Version
21
- version: 0.19.0
35
+ version: 0.20.0
22
36
  type: :runtime
23
37
  prerelease: false
24
38
  version_requirements: !ruby/object:Gem::Requirement
25
39
  requirements:
26
40
  - - "~>"
27
41
  - !ruby/object:Gem::Version
28
- version: 0.19.0
42
+ version: 0.20.0
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: typhoeus
31
45
  requirement: !ruby/object:Gem::Requirement
@@ -46,89 +60,63 @@ dependencies:
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: '2.0'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '2.2'
63
+ version: 3.0.0
53
64
  type: :runtime
54
65
  prerelease: false
55
66
  version_requirements: !ruby/object:Gem::Requirement
56
67
  requirements:
57
68
  - - "~>"
58
69
  - !ruby/object:Gem::Version
59
- version: '2.0'
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '2.2'
70
+ version: 3.0.0
63
71
  - !ruby/object:Gem::Dependency
64
72
  name: nokogiri
65
73
  requirement: !ruby/object:Gem::Requirement
66
74
  requirements:
67
75
  - - "~>"
68
76
  - !ruby/object:Gem::Version
69
- version: '1.0'
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '1.7'
77
+ version: 1.8.2
73
78
  type: :runtime
74
79
  prerelease: false
75
80
  version_requirements: !ruby/object:Gem::Requirement
76
81
  requirements:
77
82
  - - "~>"
78
83
  - !ruby/object:Gem::Version
79
- version: '1.0'
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '1.7'
84
+ version: 1.8.2
83
85
  - !ruby/object:Gem::Dependency
84
- name: diffy
86
+ name: addressable
85
87
  requirement: !ruby/object:Gem::Requirement
86
88
  requirements:
87
89
  - - "~>"
88
90
  - !ruby/object:Gem::Version
89
- version: '3.0'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: 3.0.5
91
+ version: 2.5.2
93
92
  type: :runtime
94
93
  prerelease: false
95
94
  version_requirements: !ruby/object:Gem::Requirement
96
95
  requirements:
97
96
  - - "~>"
98
97
  - !ruby/object:Gem::Version
99
- version: '3.0'
100
- - - "<"
101
- - !ruby/object:Gem::Version
102
- version: 3.0.5
98
+ version: 2.5.2
103
99
  - !ruby/object:Gem::Dependency
104
- name: addressable
100
+ name: diffy
105
101
  requirement: !ruby/object:Gem::Requirement
106
102
  requirements:
107
103
  - - "~>"
108
104
  - !ruby/object:Gem::Version
109
- version: '2.0'
110
- - - "<"
111
- - !ruby/object:Gem::Version
112
- version: '2.5'
105
+ version: 3.2.0
113
106
  type: :runtime
114
107
  prerelease: false
115
108
  version_requirements: !ruby/object:Gem::Requirement
116
109
  requirements:
117
110
  - - "~>"
118
111
  - !ruby/object:Gem::Version
119
- version: '2.0'
120
- - - "<"
121
- - !ruby/object:Gem::Version
122
- version: '2.5'
123
- description: 'SiteDiff makes it easy to see differences between two versions of a
124
- website. It accepts a set of paths to compare two versions of the site together
112
+ version: 3.2.0
113
+ description: " SiteDiff makes it easy to see differences between two versions of
114
+ a website. It accepts a set of paths to compare two versions of the site together
125
115
  with potential normalization/sanitization rules. From the provided paths and configuration
126
116
  SiteDiff generates an HTML report of all the status of HTML comparison between the
127
117
  given paths together with a readable diff-like HTML for each specified path containing
128
118
  the differences between the two versions of the site. It is useful tool for QAing
129
- re-deployments, site upgrades, etc.
130
-
131
- '
119
+ re-deployments, site upgrades, etc.\n"
132
120
  email: alex@evolvingweb.ca
133
121
  executables:
134
122
  - sitediff
@@ -171,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
159
  requirements:
172
160
  - - ">="
173
161
  - !ruby/object:Gem::Version
174
- version: 1.9.3
162
+ version: '2.3'
175
163
  required_rubygems_version: !ruby/object:Gem::Requirement
176
164
  requirements:
177
165
  - - ">="