dom_glancy 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/Gemfile +4 -0
- data/README.md +5 -0
- data/app/controllers/dom_glancy_controller.rb +9 -12
- data/app/views/dom_glancy/about.html.erb +2 -2
- data/app/views/dom_glancy/path_config.html.erb +10 -8
- data/app/views/dom_glancy/show.html.erb +3 -18
- data/app/views/layouts/dom_glancy.html.erb +10 -19
- data/app/views/shared/_dom_glancy_nav.html.erb +1 -1
- data/app/views/shared/_dom_set.html.erb +17 -2
- data/lib/assets/javascripts/dom_glancy/dom_glancy.js +37 -0
- data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/1236_grid.css +0 -0
- data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/720_grid.css +0 -0
- data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/986_grid.css +0 -0
- data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/dom_glancy.css +35 -4
- data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/normalize.css +0 -0
- data/lib/dom_glancy.rb +6 -2
- data/lib/dom_glancy/analysis_reporter.rb +39 -0
- data/lib/dom_glancy/analyzer.rb +139 -0
- data/lib/dom_glancy/change_anlyzer.rb +22 -0
- data/lib/dom_glancy/dom_glancy.rb +35 -83
- data/lib/dom_glancy/element.rb +63 -12
- data/lib/dom_glancy/file_name_builder.rb +21 -0
- data/lib/dom_glancy/map_file.rb +14 -0
- data/lib/dom_glancy/page_mapper.rb +81 -0
- data/lib/dom_glancy/svg.rb +41 -2
- data/lib/dom_glancy/version.rb +1 -1
- data/test/page_objects/dom_glancy/show_page.rb +6 -0
- data/test/selenium/mapping_test.rb +28 -5
- data/test/selenium/viewer_test.rb +2 -2
- data/test/selenium_test_helper.rb +26 -43
- data/test/test_app/app/assets/stylesheets/local_app.css +9 -1
- data/test/test_app/app/views/local/index.html.erb +11 -1
- data/test/test_helper.rb +7 -5
- data/test/test_helpers/artifacts_helpers.rb +54 -0
- data/test/test_helpers/location_helpers.rb +5 -3
- data/test/test_objects/options_file_1.yaml +2145 -0
- data/test/test_objects/options_file_2.yaml +2177 -0
- data/test/test_objects/test_objects.rb +57 -6
- data/test/unit/analysis_reporter_test.rb +28 -0
- data/test/unit/analyzer_test.rb +146 -0
- data/test/unit/change_analyzer_test.rb +72 -0
- data/test/unit/dom_glancy_test.rb +16 -11
- data/test/unit/element_test.rb +56 -0
- data/test/unit/file_name_builder_test.rb +28 -0
- data/test/unit/map_file_test.rb +47 -0
- data/test/unit/page_mapper_test.rb +27 -0
- data/test/unit/svg_test.rb +17 -0
- metadata +35 -13
- data/app/assets/javascripts/application.js +0 -7
- data/lib/dom_glancy/analysis.rb +0 -146
- data/lib/dom_glancy/locations.rb +0 -16
- data/test/unit/analysis_test.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cd48c0ea852b13728e2f1248f6cb2232afc45ca
|
4
|
+
data.tar.gz: 564fd88c6ae4c6c780f832d14d202c326c1e6af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3b6b032528da837084dfad7e96af8f0e9557689ea2e7583cedfa86fecbf985d7f9e40045ab2af231015a60013ea8131391e9061a6f9835a1ba11679686fa8be
|
7
|
+
data.tar.gz: 8b81bfd4998db70ef47f013bbc59572c1c2c84b133db866ebde600b264dfd2ca3bbd617be5a39091f1ba480da41bfefbbb75ddc91d82c83498cda466a16f80e0
|
data/.travis.yml
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- "1.9.3"
|
4
|
-
- "2.0.0"
|
5
|
-
- "2.1.0"
|
6
4
|
- "2.1.2"
|
5
|
+
- "2.1.5"
|
7
6
|
before_script:
|
8
7
|
- export DISPLAY=:99.0
|
9
8
|
- sh -e /etc/init.d/xvfb start
|
@@ -11,3 +10,5 @@ script:
|
|
11
10
|
- bundle exec rake
|
12
11
|
addons:
|
13
12
|
firefox: "31.0"
|
13
|
+
code_climate:
|
14
|
+
repo_token: 83887755db231f4c094598500eb6044a9cc4cd0e3993fa5af7d705a6b64cfb2a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,11 @@ _you know. like taking a quick glance at the DOM, but make it sound kinda like T
|
|
8
8
|
|
9
9
|
[![Build Status](https://travis-ci.org/QuantumGeordie/dom_glancy.svg?branch=master)](https://travis-ci.org/QuantumGeordie/dom_glancy)
|
10
10
|
|
11
|
+
## Code Climate
|
12
|
+
|
13
|
+
[![Code Climate](https://codeclimate.com/github/QuantumGeordie/dom_glancy/badges/gpa.svg)](https://codeclimate.com/github/QuantumGeordie/dom_glancy)
|
14
|
+
[![Test Coverage](https://codeclimate.com/github/QuantumGeordie/dom_glancy/badges/coverage.svg)](https://codeclimate.com/github/QuantumGeordie/dom_glancy)
|
15
|
+
|
11
16
|
## Installation
|
12
17
|
|
13
18
|
Add this line to your application's Gemfile in the test and development groups:
|
@@ -34,8 +34,9 @@ class DomGlancyController < DomGlancyApplicationController
|
|
34
34
|
|
35
35
|
def make_master
|
36
36
|
test_root = params[:file]
|
37
|
-
|
38
|
-
|
37
|
+
fnb = DomGlancy::FileNameBuilder.new(test_root)
|
38
|
+
src = fnb.current
|
39
|
+
dst = fnb.master
|
39
40
|
FileUtils.cp src, dst
|
40
41
|
|
41
42
|
redirect_to '/dom_glancy/new'
|
@@ -43,7 +44,8 @@ class DomGlancyController < DomGlancyApplicationController
|
|
43
44
|
|
44
45
|
def delete_current
|
45
46
|
test_root = params[:file]
|
46
|
-
|
47
|
+
fnb = DomGlancy::FileNameBuilder.new(test_root)
|
48
|
+
src = fnb.current
|
47
49
|
FileUtils.rm_rf src
|
48
50
|
|
49
51
|
redirect_to '/dom_glancy/new'
|
@@ -74,12 +76,6 @@ class DomGlancyController < DomGlancyApplicationController
|
|
74
76
|
redirect_to dom_glancy_path
|
75
77
|
end
|
76
78
|
|
77
|
-
def about
|
78
|
-
about_file = File.expand_path('../../../README.md', __FILE__)
|
79
|
-
raw = File.read(about_file)
|
80
|
-
@about = Kramdown::Document.new(raw).to_html
|
81
|
-
end
|
82
|
-
|
83
79
|
def clear
|
84
80
|
Dir[File.join(DomGlancy.configuration.diff_file_location, '*.yaml'), File.join(DomGlancy.configuration.diff_file_location, '*.html')].each { |f| FileUtils.rm_rf(f) }
|
85
81
|
Dir[File.join(DomGlancy.configuration.current_file_location, '*.yaml')].each { |f| FileUtils.rm_rf(f) }
|
@@ -92,14 +88,15 @@ class DomGlancyController < DomGlancyApplicationController
|
|
92
88
|
|
93
89
|
blessings.each do |blessing|
|
94
90
|
base_test_name = blessing
|
91
|
+
fnb = DomGlancy::FileNameBuilder.new(base_test_name)
|
95
92
|
|
96
|
-
src_yaml =
|
97
|
-
dst_yaml =
|
93
|
+
src_yaml = fnb.current
|
94
|
+
dst_yaml = fnb.master
|
98
95
|
|
99
96
|
FileUtils.cp src_yaml, dst_yaml if File.exist?(src_yaml)
|
100
97
|
|
101
98
|
if params['delete_on_bless'] == 'true'
|
102
|
-
files_to_remove = [
|
99
|
+
files_to_remove = [fnb.diff]
|
103
100
|
files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__current_not_master__diff.yaml')
|
104
101
|
files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__master_not_current__diff.yaml')
|
105
102
|
files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__changed_master__diff.yaml')
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<div class="row kr--about">
|
2
|
-
|
3
|
-
</div>
|
2
|
+
<p>Info about Dom Glancy can be found <a href="https://github.com/QuantumGeordie/dom_glancy" class="kr">here</a> and <a href="http://quantumgeordie.github.io/dom_glancy/" class="kr">here</a>. Check it out.</p>
|
3
|
+
</div>
|
@@ -1,8 +1,10 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</
|
1
|
+
<div class="kr--about">
|
2
|
+
<h2>Path Configuration</h2>
|
3
|
+
<table class="kr">
|
4
|
+
<tbody>
|
5
|
+
<tr><th>master</th><td id="js-config_master"><%= DomGlancy.configuration.master_file_location %></td></tr>
|
6
|
+
<tr><th>current</th><td id="js-config_current"><%= DomGlancy.configuration.current_file_location %></td></tr>
|
7
|
+
<tr><th>diff</th><td id="js-config_diffs"><%= DomGlancy.configuration.diff_file_location %></td></tr>
|
8
|
+
</tbody>
|
9
|
+
</table>
|
10
|
+
</div>
|
@@ -11,32 +11,17 @@
|
|
11
11
|
<%= raw(contents) %>
|
12
12
|
</td>
|
13
13
|
<td>
|
14
|
-
<h2>in current dom, not master</h2>
|
15
14
|
<% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_not_master)) %>
|
15
|
+
<h2><span class="hideable" id="not_master_toggle">+</span> Not in Master [<%= elements.count %>]</h2>
|
16
16
|
<%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--not_master'} %>
|
17
17
|
|
18
|
-
<h2>in master dom, not current</h2>
|
19
18
|
<% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_not_current)) %>
|
19
|
+
<h2><span class="hideable" id="not_current_toggle">+</span> Not in Current [<%= elements.count %>]</h2>
|
20
20
|
<%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--not_current'} %>
|
21
21
|
|
22
|
-
<h2>changed</h2>
|
23
22
|
<% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_changed)) %>
|
23
|
+
<h2><span class="hideable" id="changed_toggle">+</span> Changed [<%= elements.count %>]</h2>
|
24
24
|
<%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--changed'} %>
|
25
|
-
|
26
25
|
</td>
|
27
26
|
</tr>
|
28
27
|
</table>
|
29
|
-
|
30
|
-
<script type="text/javascript">
|
31
|
-
highlightElement = function(element_id) {
|
32
|
-
var elements = document.getElementsByTagName('rect');
|
33
|
-
var element = null;
|
34
|
-
var length = elements.length;
|
35
|
-
|
36
|
-
for (var i = 0; i < length; i++) {
|
37
|
-
elements[i].setAttribute("stroke-width", "1");
|
38
|
-
}
|
39
|
-
var this_element = document.getElementById(element_id);
|
40
|
-
this_element.setAttribute("stroke-width", "5");
|
41
|
-
}
|
42
|
-
</script>
|
@@ -3,30 +3,21 @@
|
|
3
3
|
<head>
|
4
4
|
<title>DOM Glancy</title>
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
6
|
-
<%=
|
7
|
-
%>
|
8
|
-
<%= stylesheet_link_tag '
|
9
|
-
<%= stylesheet_link_tag '
|
10
|
-
<%= stylesheet_link_tag '
|
11
|
-
<%= stylesheet_link_tag '1236_grid.css', :media => 'screen and (min-width: 1236px)' %>
|
12
|
-
<%= stylesheet_link_tag 'dom_glancy', :media => 'all' %>
|
6
|
+
<%= stylesheet_link_tag 'dom_glancy/normalize.css', :media => 'all' %>
|
7
|
+
<%= stylesheet_link_tag 'dom_glancy/720_grid.css', :media => 'screen and (min-width: 720px)' %>
|
8
|
+
<%= stylesheet_link_tag 'dom_glancy/986_grid.css', :media => 'screen and (min-width: 986px)' %>
|
9
|
+
<%= stylesheet_link_tag 'dom_glancy/1236_grid.css', :media => 'screen and (min-width: 1236px)' %>
|
10
|
+
<%= stylesheet_link_tag 'dom_glancy/dom_glancy', :media => 'all' %>
|
13
11
|
|
14
12
|
<%= csrf_meta_tags %>
|
15
13
|
</head>
|
16
14
|
<body>
|
17
|
-
<
|
18
|
-
|
19
|
-
<h1>DOM Glancy</h1>
|
20
|
-
</div>
|
21
|
-
<div class="row">
|
22
|
-
<h2 class="caramel"><%= @parent_application_name %> {<span id="js-kr--gem_rev"><%= @gem_version %></span>}</h2>
|
23
|
-
</div>
|
15
|
+
<h1>DOM Glancy</h1>
|
16
|
+
<h2 class="caramel"><%= @parent_application_name %> {<span id="js-kr--gem_rev"><%= @gem_version %></span>}</h2>
|
24
17
|
|
25
|
-
|
18
|
+
<%= render :partial => 'shared/dom_glancy_nav' %>
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
</div>
|
30
|
-
</div>
|
20
|
+
<%= yield %>
|
21
|
+
<%= javascript_include_tag 'dom_glancy/dom_glancy' %>
|
31
22
|
</body>
|
32
23
|
</html>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div class="row" id="js-kr--nav"
|
1
|
+
<div class="row" id="js-kr--nav">
|
2
2
|
<a href="/dom_glancy/" class="kr"><div class="slot-0 kr--nav">home</div></a>
|
3
3
|
<a href="/dom_glancy/new" class="kr"><div class="slot-1 kr--nav">new</div></a>
|
4
4
|
<!--<a href="/dom_glancy/artifacts" class="kr"><div class="slot-2 kr--nav">artifacts</div></a>-->
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div id="<%= finder_id %>">
|
1
|
+
<div id="<%= finder_id %>" class="hide">
|
2
2
|
<% if elements.length > 0 %>
|
3
3
|
<table class='kr--dom'>
|
4
4
|
<thead>
|
@@ -11,12 +11,24 @@
|
|
11
11
|
<th>width</th>
|
12
12
|
<th>height</th>
|
13
13
|
<th>visible</th>
|
14
|
+
<% if finder_id == 'js--changed' %>
|
15
|
+
<th>was</th>
|
16
|
+
<% end %>
|
14
17
|
</tr>
|
15
18
|
</thead>
|
16
19
|
<tbody>
|
17
20
|
<% reset_cycle %>
|
18
21
|
<% elements.each do |element| %>
|
19
22
|
<tr onclick="highlightElement(<%= element[:js_id] %>);" class="<%= cycle("kr-dom_row_odd", "kr-dom_row_even") %>">
|
23
|
+
<% was_element = element['was'] %>
|
24
|
+
<% changed = [] %>
|
25
|
+
<% if was_element %>
|
26
|
+
<% changed << "height: #{was_element['height']}" unless element['height'] == was_element['height'] %>
|
27
|
+
<% changed << "width: #{was_element['width']}" unless element['width'] == was_element['width'] %>
|
28
|
+
<% changed << "top: #{was_element['top']}" unless element['top'] == was_element['top'] %>
|
29
|
+
<% changed << "left: #{was_element['left']}" unless element['left'] == was_element['left'] %>
|
30
|
+
<% changed << "class: #{was_element['class']}" unless element['class'] == was_element['class'] %>
|
31
|
+
<% end %>
|
20
32
|
<td><%= element['tag'] %></td>
|
21
33
|
<td><%= element['id'] %></td>
|
22
34
|
<td><%= element['class'] %></td>
|
@@ -25,6 +37,9 @@
|
|
25
37
|
<td><%= element['width'] %></td>
|
26
38
|
<td><%= element['height'] %></td>
|
27
39
|
<td><%= element['visible'] %></td>
|
40
|
+
<% if was_element %>
|
41
|
+
<td><%= changed.join(', ') %></td>
|
42
|
+
<% end %>
|
28
43
|
</tr>
|
29
44
|
<% end %>
|
30
45
|
</tbody>
|
@@ -32,4 +47,4 @@
|
|
32
47
|
<% else %>
|
33
48
|
<p>no elements found.</p>
|
34
49
|
<% end %>
|
35
|
-
</div>
|
50
|
+
</div>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
function checkByParent(aId, aChecked) {
|
2
|
+
var collection = document.getElementById(aId).getElementsByTagName('INPUT');
|
3
|
+
for (var x=0; x<collection.length; x++) {
|
4
|
+
if (collection[x].type.toUpperCase() === 'CHECKBOX')
|
5
|
+
collection[x].checked = aChecked;
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
function toggleDetailSection(section_id, event) {
|
10
|
+
var section = document.getElementById(section_id);
|
11
|
+
var classes = section.classList;
|
12
|
+
if(classes.contains("hide"))
|
13
|
+
{
|
14
|
+
classes.remove("hide");
|
15
|
+
event.currentTarget.innerHTML = '-';
|
16
|
+
}else
|
17
|
+
{
|
18
|
+
classes.add("hide");
|
19
|
+
event.currentTarget.innerHTML = '+';
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
function highlightElement (element_id) {
|
24
|
+
var elements = document.getElementsByTagName('rect');
|
25
|
+
var element = null;
|
26
|
+
var length = elements.length;
|
27
|
+
|
28
|
+
for (var i = 0; i < length; i++) {
|
29
|
+
elements[i].setAttribute("stroke-width", "1");
|
30
|
+
}
|
31
|
+
var this_element = document.getElementById(element_id);
|
32
|
+
this_element.setAttribute("stroke-width", "5");
|
33
|
+
}
|
34
|
+
|
35
|
+
document.getElementById("changed_toggle").addEventListener("click", function(e) { toggleDetailSection('js--changed', e) });
|
36
|
+
document.getElementById("not_master_toggle").addEventListener("click", function(e) { toggleDetailSection('js--not_master', e) });
|
37
|
+
document.getElementById("not_current_toggle").addEventListener("click", function(e) { toggleDetailSection('js--not_current', e) });
|
File without changes
|
File without changes
|
File without changes
|
@@ -27,9 +27,11 @@ html {
|
|
27
27
|
body {
|
28
28
|
background-color: #FFFBF5;
|
29
29
|
color: #2A2111;
|
30
|
-
margin
|
30
|
+
margin: 0 0 0 20px;
|
31
31
|
}
|
32
32
|
|
33
|
+
p { max-width: 960px; }
|
34
|
+
|
33
35
|
a.kr:link { text-decoration:none; color: #A3906D; }
|
34
36
|
a.kr:visited { text-decoration:none; color: #A3906D; }
|
35
37
|
a.kr:hover { text-decoration:none; color: #956C1F; }
|
@@ -102,15 +104,14 @@ a.kr:active { text-decoration:none; color: #A3906D; }
|
|
102
104
|
width: auto;
|
103
105
|
min-width: 0;
|
104
106
|
padding: 4px 4px 4px 4px;
|
105
|
-
|
106
107
|
}
|
107
108
|
|
108
109
|
.kr-dom_row_odd {
|
109
|
-
background-color: #
|
110
|
+
background-color: #ffffff;
|
110
111
|
}
|
111
112
|
|
112
113
|
.kr-dom_row_even {
|
113
|
-
background-color:
|
114
|
+
background-color: #FFFBF5;
|
114
115
|
}
|
115
116
|
|
116
117
|
.kr--svg_rect_highlight {
|
@@ -119,6 +120,7 @@ a.kr:active { text-decoration:none; color: #A3906D; }
|
|
119
120
|
|
120
121
|
.kr--about {
|
121
122
|
margin-top: 30px;
|
123
|
+
margin-left: 30px;
|
122
124
|
padding: 35px;
|
123
125
|
color: #2A2111;
|
124
126
|
background-color: #fff;
|
@@ -126,6 +128,7 @@ a.kr:active { text-decoration:none; color: #A3906D; }
|
|
126
128
|
-moz-border-radius: 20px;
|
127
129
|
-webkit-border-radius: 20px;
|
128
130
|
border-radius: 10px; /* future proofing */
|
131
|
+
max-width: 960px;
|
129
132
|
}
|
130
133
|
|
131
134
|
.kr--artifacts td {
|
@@ -147,3 +150,31 @@ a.kr:active { text-decoration:none; color: #A3906D; }
|
|
147
150
|
border-radius: 5px;
|
148
151
|
font-size: 75%;
|
149
152
|
}
|
153
|
+
|
154
|
+
.hide { display: none; }
|
155
|
+
.hideable {
|
156
|
+
color: #956C1F;
|
157
|
+
cursor: pointer;
|
158
|
+
}
|
159
|
+
|
160
|
+
/* tab list */
|
161
|
+
ul.tab_list {
|
162
|
+
float: left;
|
163
|
+
width: 100%;
|
164
|
+
padding: 0;
|
165
|
+
margin: 0;
|
166
|
+
list-style-type: none;
|
167
|
+
}
|
168
|
+
|
169
|
+
li.tab {
|
170
|
+
display: inline;
|
171
|
+
background-color: transparent;
|
172
|
+
font-size: 2em;
|
173
|
+
padding: 0 2em 0 2em;
|
174
|
+
}
|
175
|
+
|
176
|
+
.tab_active {
|
177
|
+
color: #956C1F;
|
178
|
+
background-color: #FFFBF5;
|
179
|
+
border-bottom: 4px solid #956C1F;
|
180
|
+
}
|
File without changes
|
data/lib/dom_glancy.rb
CHANGED
@@ -5,7 +5,11 @@ require 'dom_glancy/engine' if defined?(Rails)
|
|
5
5
|
require 'dom_glancy/dom_glancy'
|
6
6
|
require 'dom_glancy/version'
|
7
7
|
require 'dom_glancy/element'
|
8
|
-
require 'dom_glancy/
|
9
|
-
require 'dom_glancy/
|
8
|
+
require 'dom_glancy/analyzer'
|
9
|
+
require 'dom_glancy/file_name_builder'
|
10
10
|
require 'dom_glancy/svg'
|
11
11
|
require 'dom_glancy/configuration'
|
12
|
+
require 'dom_glancy/page_mapper'
|
13
|
+
require 'dom_glancy/map_file'
|
14
|
+
require 'dom_glancy/analysis_reporter'
|
15
|
+
require 'dom_glancy/change_anlyzer'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module DomGlancy
|
2
|
+
class AnalysisReporter
|
3
|
+
@test_root
|
4
|
+
@set_current_not_master
|
5
|
+
@set_master_not_current
|
6
|
+
@set_changed_master
|
7
|
+
@changed_pairs
|
8
|
+
|
9
|
+
def initialize(test_root, set_current_not_master,set_master_not_current, set_changed_master, changed_pairs)
|
10
|
+
@test_root = test_root
|
11
|
+
@set_current_not_master = set_current_not_master
|
12
|
+
@set_master_not_current = set_master_not_current
|
13
|
+
@set_changed_master = set_changed_master
|
14
|
+
@changed_pairs = changed_pairs
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_diff_file
|
18
|
+
filename = ::DomGlancy::FileNameBuilder.new(@test_root).diff
|
19
|
+
svg = make_svg
|
20
|
+
File.open(filename, 'w') { |file| file.write(svg) }
|
21
|
+
save_set_info('current_not_master', @set_current_not_master)
|
22
|
+
save_set_info('master_not_current', @set_master_not_current)
|
23
|
+
save_set_info('changed_master', @set_changed_master)
|
24
|
+
save_set_info('changed_pairs', @changed_pairs)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def make_svg
|
30
|
+
svg = ::DomGlancy::SVG.new(@set_current_not_master, @set_master_not_current, @set_changed_master)
|
31
|
+
svg.generate_svg
|
32
|
+
end
|
33
|
+
|
34
|
+
def save_set_info(suffix, data_set)
|
35
|
+
filename = File.join(::DomGlancy.configuration.diff_file_location, "#{@test_root}__#{suffix}__diff.yaml")
|
36
|
+
File.open(filename, 'w') { |file| file.write(data_set.to_a.to_yaml) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module DomGlancy
|
2
|
+
class Analyzer
|
3
|
+
attr_reader :set_current_not_master
|
4
|
+
attr_reader :set_master_not_current
|
5
|
+
attr_reader :set_changed_master
|
6
|
+
attr_reader :changed_element_pairs
|
7
|
+
|
8
|
+
@master_data
|
9
|
+
@current_data
|
10
|
+
@test_root
|
11
|
+
|
12
|
+
def initialize(master_data, current_data, test_root = nil)
|
13
|
+
@master_data = master_data
|
14
|
+
@current_data = current_data
|
15
|
+
@test_root = test_root
|
16
|
+
end
|
17
|
+
|
18
|
+
def analyze
|
19
|
+
clear_results
|
20
|
+
|
21
|
+
if missing_elements? || extra_elements?
|
22
|
+
remove_similar_elements
|
23
|
+
extract_changed_elements
|
24
|
+
end
|
25
|
+
|
26
|
+
# create_diff_file if @test_root && !all_same?
|
27
|
+
compile_results
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def clear_results
|
33
|
+
master_set = @master_data.to_set
|
34
|
+
current_set = @current_data.to_set
|
35
|
+
|
36
|
+
@set_current_not_master = current_set - master_set
|
37
|
+
@set_master_not_current = master_set - current_set
|
38
|
+
@set_changed_master = Set.new
|
39
|
+
|
40
|
+
@changed_element_pairs = []
|
41
|
+
end
|
42
|
+
|
43
|
+
def compile_results
|
44
|
+
{
|
45
|
+
not_in_master: @set_current_not_master,
|
46
|
+
not_in_current: @set_master_not_current,
|
47
|
+
changed_element_pairs: @changed_element_pairs,
|
48
|
+
changed_master: @set_changed_master,
|
49
|
+
test_root: @test_root,
|
50
|
+
same: all_same?
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def all_same?
|
55
|
+
@set_current_not_master.count == 0 && @set_master_not_current.count == 0 && @changed_element_pairs.count == 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def missing_elements?
|
59
|
+
@set_master_not_current.count > 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def extra_elements?
|
63
|
+
@set_current_not_master.count > 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_similar_elements
|
67
|
+
ok_pairs = similar_pairs(@set_current_not_master, @set_master_not_current)
|
68
|
+
|
69
|
+
ok_pairs.each do |item1, item2|
|
70
|
+
@set_current_not_master.delete(item1)
|
71
|
+
@set_master_not_current.delete(item2)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def extract_changed_elements
|
76
|
+
@changed_element_pairs = []
|
77
|
+
|
78
|
+
@set_current_not_master.each do |item1| # in current
|
79
|
+
element1 = DOMElement.new(item1)
|
80
|
+
changed_elements = []
|
81
|
+
@set_master_not_current.each do |item2| # in master
|
82
|
+
element2 = DOMElement.new(item2)
|
83
|
+
if element1.same_element?(element2)
|
84
|
+
changed_elements << element2
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
least_changed = changed_elements[0]
|
89
|
+
changed_elements.each do |element|
|
90
|
+
change_analyzer = ChangeAnalyzer.new
|
91
|
+
least_changed = element if change_analyzer.compare(element1, element) < change_analyzer.compare(element1, least_changed)
|
92
|
+
end
|
93
|
+
|
94
|
+
@changed_element_pairs << [item1, least_changed.to_hash] if least_changed
|
95
|
+
end
|
96
|
+
|
97
|
+
remove_elements_from_data_sets @changed_element_pairs
|
98
|
+
|
99
|
+
@changed_element_pairs.select!{ |pair| !DOMElement.new(add_similarity(pair[0])).close_enough?(DOMElement.new(add_similarity(pair[1]))) }
|
100
|
+
|
101
|
+
@changed_element_pairs.each do |pair|
|
102
|
+
current_element = pair[0].dup
|
103
|
+
master_element = pair[1].dup
|
104
|
+
current_element['was'] = master_element
|
105
|
+
@set_changed_master.add(current_element)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def remove_elements_from_data_sets(element_pairs)
|
110
|
+
element_pairs.each do |element_1, element_2|
|
111
|
+
remove_element_from_data_sets element_1
|
112
|
+
remove_element_from_data_sets element_2
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def remove_element_from_data_sets(element)
|
117
|
+
@set_current_not_master.delete element
|
118
|
+
@set_master_not_current.delete element
|
119
|
+
end
|
120
|
+
|
121
|
+
def similar_pairs(set1, set2)
|
122
|
+
ok_pairs = []
|
123
|
+
set1.each do |item1|
|
124
|
+
element1 = DOMElement.new(add_similarity(item1))
|
125
|
+
set2.each do |item2|
|
126
|
+
element2 = DOMElement.new(add_similarity(item2))
|
127
|
+
if element1.same_element?(element2) && element1.close_enough?(element2)
|
128
|
+
ok_pairs << [item1, item2]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
ok_pairs
|
133
|
+
end
|
134
|
+
|
135
|
+
def add_similarity(element)
|
136
|
+
element.merge('similarity' => ::DomGlancy.configuration.similarity)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|