govuk-diff-pages 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +14 -0
- data/config/settings.yml +53 -0
- data/docs/screenshots/gallery.png +0 -0
- data/govuk-diff-pages.gemspec +30 -0
- data/lib/govuk/diff/pages.rb +30 -0
- data/lib/govuk/diff/pages/app_config.rb +61 -0
- data/lib/govuk/diff/pages/format_searcher.rb +37 -0
- data/lib/govuk/diff/pages/html_diff.rb +10 -0
- data/lib/govuk/diff/pages/html_diff/assets/gallery_template.erb +30 -0
- data/lib/govuk/diff/pages/html_diff/assets/html_diff_styles.css +59 -0
- data/lib/govuk/diff/pages/html_diff/assets/html_diff_template.erb +31 -0
- data/lib/govuk/diff/pages/html_diff/differ.rb +84 -0
- data/lib/govuk/diff/pages/html_diff/runner.rb +44 -0
- data/lib/govuk/diff/pages/link_checker.rb +47 -0
- data/lib/govuk/diff/pages/page_indexer.rb +27 -0
- data/lib/govuk/diff/pages/page_searcher.rb +46 -0
- data/lib/govuk/diff/pages/tasks/rakefile.rake +93 -0
- data/lib/govuk/diff/pages/text_diff.rb +13 -0
- data/lib/govuk/diff/pages/text_diff/differ.rb +15 -0
- data/lib/govuk/diff/pages/text_diff/formatter.rb +15 -0
- data/lib/govuk/diff/pages/text_diff/renderer.rb +23 -0
- data/lib/govuk/diff/pages/text_diff/retriever.rb +13 -0
- data/lib/govuk/diff/pages/text_diff/runner.rb +41 -0
- data/lib/govuk/diff/pages/url_checker.rb +36 -0
- data/lib/govuk/diff/pages/version.rb +7 -0
- data/lib/govuk/diff/pages/wraith_config_generator.rb +79 -0
- metadata +189 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module Govuk
|
2
|
+
module Diff
|
3
|
+
module Pages
|
4
|
+
module TextDiff
|
5
|
+
class Runner
|
6
|
+
def initialize(
|
7
|
+
pages: Array.new,
|
8
|
+
differ: Differ.new,
|
9
|
+
retriever: Retriever.new,
|
10
|
+
formatter: Formatter.new,
|
11
|
+
renderer: Renderer.new,
|
12
|
+
left_domain: "www-origin.staging.publishing.service.gov.uk",
|
13
|
+
right_domain: "www-origin.publishing.service.gov.uk"
|
14
|
+
)
|
15
|
+
@pages = pages
|
16
|
+
@differ = differ
|
17
|
+
@retriever = retriever
|
18
|
+
@formatter = formatter
|
19
|
+
@renderer = renderer
|
20
|
+
@left_domain = left_domain
|
21
|
+
@right_domain = right_domain
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
responses = @pages.inject([]) do |response, page|
|
26
|
+
left = @retriever.call("https://#{@left_domain}/#{page}")
|
27
|
+
right = @retriever.call("https://#{@right_domain}/#{page}")
|
28
|
+
|
29
|
+
response << @differ.diff(
|
30
|
+
@formatter.call(left),
|
31
|
+
@formatter.call(right)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
@renderer.call(responses)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Govuk
|
2
|
+
module Diff
|
3
|
+
module Pages
|
4
|
+
class UrlChecker
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
@govuk_regex = /^#{@config.domains.production}/
|
8
|
+
@parameterised_url_regex = /\?/
|
9
|
+
@relative_path_regex = /^\//
|
10
|
+
end
|
11
|
+
|
12
|
+
# returns true if non parameterised and a relative or govuk url
|
13
|
+
def valid?(url)
|
14
|
+
if url =~ @parameterised_url_regex # question mark denotes it has parameters - we don't want those
|
15
|
+
false
|
16
|
+
elsif url =~ @relative_path_regex # starts with slash - so is a path on govuk website
|
17
|
+
true
|
18
|
+
elsif url =~ @govuk_regex # gov uk full link
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def normalize(url)
|
26
|
+
raise "Not GOVUK url: #{url}" unless valid?(url)
|
27
|
+
url.sub(@govuk_regex, '')
|
28
|
+
end
|
29
|
+
|
30
|
+
def production_url(url)
|
31
|
+
"#{@config.domains.production}#{normalize(url)}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Govuk
|
5
|
+
module Diff
|
6
|
+
module Pages
|
7
|
+
class WraithConfigGenerator
|
8
|
+
def initialize
|
9
|
+
@config = AppConfig.new
|
10
|
+
unless File.exist?(Govuk::Diff::Pages.govuk_pages_file)
|
11
|
+
raise "Cannot find file #{Govuk::Diff::Pages.govuk_pages_file}: run 'rake update_page_list' to generate."
|
12
|
+
end
|
13
|
+
@govuk_pages = YAML.load_file(Govuk::Diff::Pages.govuk_pages_file)
|
14
|
+
@url_checker = UrlChecker.new(@config)
|
15
|
+
puts "Generating wraith.yaml" if verbose?
|
16
|
+
validate_hard_coded_pages
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
@wraith_config = @config.wraith.to_h
|
21
|
+
@wraith_config['paths'] = generate_path_list
|
22
|
+
@wraith_config['domains'] = @config.domains.to_h
|
23
|
+
@wraith_config['browser'] = { 'phantomjs' => 'phantomjs' }
|
24
|
+
@wraith_config['phantomjs_options'] = "--ssl-protocol=tlsv1 --ignore-ssl-errors=true"
|
25
|
+
end
|
26
|
+
|
27
|
+
def save
|
28
|
+
File.open(WRAITH_CONFIG_FILE, 'w') do |fp|
|
29
|
+
fp.puts YAML.dump(@wraith_config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def verbose?
|
34
|
+
@config.verbose
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def validate_hard_coded_pages
|
39
|
+
errors = []
|
40
|
+
@config.hard_coded_pages.to_h.each do |_key, url|
|
41
|
+
next if @url_checker.valid?(url)
|
42
|
+
errors << "ERROR: Invalid url specified in hard coded pages: '#{url}'"
|
43
|
+
end
|
44
|
+
print_errors_and_exit(errors) unless errors.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def print_errors_and_exit(errors)
|
48
|
+
raise ArgumentError.new %[Invalid config:\n #{errors.join("\n ")}]
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_path_list
|
52
|
+
paths = generate_paths_from_govuk_pages_file
|
53
|
+
paths.merge(@config.hard_coded_pages.to_h)
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_paths_from_govuk_pages_file
|
57
|
+
paths = {}
|
58
|
+
@govuk_pages.each do |path|
|
59
|
+
next unless @url_checker.valid?(path)
|
60
|
+
normalized_path = @url_checker.normalize(path)
|
61
|
+
paths[keyify_path(normalized_path)] = normalized_path
|
62
|
+
end
|
63
|
+
paths
|
64
|
+
end
|
65
|
+
|
66
|
+
def normalize_path(path)
|
67
|
+
path.sub(/^#{@config.domains.production}/, '')
|
68
|
+
end
|
69
|
+
|
70
|
+
def keyify_path(path)
|
71
|
+
key = path.sub(/^\//, '').tr("/", "_")
|
72
|
+
# YAML DUMP doesn't work with very long keys
|
73
|
+
key = SecureRandom.uuid if key.size > 100
|
74
|
+
key
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: govuk-diff-pages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Lovell
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: diffy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gem_publisher
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.1'
|
125
|
+
description: Diffs web pages both visually and textually.
|
126
|
+
email:
|
127
|
+
- benjamin.lovell@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".ruby-version"
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- config/settings.yml
|
141
|
+
- docs/screenshots/gallery.png
|
142
|
+
- govuk-diff-pages.gemspec
|
143
|
+
- lib/govuk/diff/pages.rb
|
144
|
+
- lib/govuk/diff/pages/app_config.rb
|
145
|
+
- lib/govuk/diff/pages/format_searcher.rb
|
146
|
+
- lib/govuk/diff/pages/html_diff.rb
|
147
|
+
- lib/govuk/diff/pages/html_diff/assets/gallery_template.erb
|
148
|
+
- lib/govuk/diff/pages/html_diff/assets/html_diff_styles.css
|
149
|
+
- lib/govuk/diff/pages/html_diff/assets/html_diff_template.erb
|
150
|
+
- lib/govuk/diff/pages/html_diff/differ.rb
|
151
|
+
- lib/govuk/diff/pages/html_diff/runner.rb
|
152
|
+
- lib/govuk/diff/pages/link_checker.rb
|
153
|
+
- lib/govuk/diff/pages/page_indexer.rb
|
154
|
+
- lib/govuk/diff/pages/page_searcher.rb
|
155
|
+
- lib/govuk/diff/pages/tasks/rakefile.rake
|
156
|
+
- lib/govuk/diff/pages/text_diff.rb
|
157
|
+
- lib/govuk/diff/pages/text_diff/differ.rb
|
158
|
+
- lib/govuk/diff/pages/text_diff/formatter.rb
|
159
|
+
- lib/govuk/diff/pages/text_diff/renderer.rb
|
160
|
+
- lib/govuk/diff/pages/text_diff/retriever.rb
|
161
|
+
- lib/govuk/diff/pages/text_diff/runner.rb
|
162
|
+
- lib/govuk/diff/pages/url_checker.rb
|
163
|
+
- lib/govuk/diff/pages/version.rb
|
164
|
+
- lib/govuk/diff/pages/wraith_config_generator.rb
|
165
|
+
homepage: https://github.com/alphagov/govuk-diff-pages
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.4.5.1
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Visual and textual page diffing.
|
189
|
+
test_files: []
|