example_group_timer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +8 -0
- data/lib/example_group_timer/formatter.rb +4 -0
- data/lib/example_group_timer/root_timed_group.rb +22 -2
- data/lib/example_group_timer/timed_group.rb +4 -2
- data/lib/example_group_timer/timed_item.rb +19 -3
- data/lib/example_group_timer/version.rb +1 -1
- data/support/template.html +143 -0
- metadata +3 -2
data/HISTORY.md
CHANGED
@@ -49,6 +49,10 @@ module ExampleGroupTimer
|
|
49
49
|
|
50
50
|
def dump_summary(*args)
|
51
51
|
current_group.report
|
52
|
+
template = File.read(File.expand_path('../../../support/template.html', __FILE__))
|
53
|
+
File.open('time_report.html', 'w') do |f|
|
54
|
+
f.write template.sub('PLACEHOLDER', current_group.output.string)
|
55
|
+
end
|
52
56
|
super
|
53
57
|
end
|
54
58
|
end
|
@@ -8,8 +8,28 @@ module ExampleGroupTimer
|
|
8
8
|
0
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def output
|
12
|
+
@output ||= StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def report
|
16
|
+
puts '<div id="lists">'
|
17
|
+
puts '<ol>'
|
18
|
+
super
|
19
|
+
puts '</ol>'
|
20
|
+
puts '</div>'
|
21
|
+
end
|
22
|
+
|
23
|
+
def percentage
|
24
|
+
''
|
25
|
+
end
|
26
|
+
|
27
|
+
def description
|
28
|
+
'Spec suite'
|
29
|
+
end
|
30
|
+
|
31
|
+
def puts(*args)
|
32
|
+
output.puts(*args)
|
13
33
|
end
|
14
34
|
end
|
15
35
|
end
|
@@ -24,9 +24,11 @@ module ExampleGroupTimer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def report
|
27
|
-
|
28
|
-
|
27
|
+
super
|
28
|
+
puts "<ol>"
|
29
|
+
examples.sort_by { |o| o.duration }.reverse.each(&:report)
|
29
30
|
subgroups.sort_by { |o| o.duration }.reverse.each(&:report)
|
31
|
+
puts "</ol>"
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -27,9 +27,25 @@ module ExampleGroupTimer
|
|
27
27
|
('%.1f%' % [(duration.to_f / parent.duration.to_f) * 100]).rjust(5)
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
30
|
+
def report
|
31
|
+
template = <<-EOS
|
32
|
+
<li>
|
33
|
+
<div class="example-group">
|
34
|
+
<span class="title">%s</span>
|
35
|
+
<span class="duration">%s</span>
|
36
|
+
<span class="share">%s</span>
|
37
|
+
</div>
|
38
|
+
</li>
|
39
|
+
EOS
|
40
|
+
puts template % [description, duration, percentage]
|
41
|
+
end
|
42
|
+
|
43
|
+
def description
|
44
|
+
item.description.strip
|
45
|
+
end
|
46
|
+
|
47
|
+
def puts(*args)
|
48
|
+
parent.puts *args
|
33
49
|
end
|
34
50
|
end
|
35
51
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Charts</title>
|
6
|
+
<style type="text/css">
|
7
|
+
body {
|
8
|
+
font: 12px/18px sans-serif;
|
9
|
+
color: #333;
|
10
|
+
padding: 18px;
|
11
|
+
}
|
12
|
+
ol {
|
13
|
+
padding: 9px;
|
14
|
+
list-style: none;
|
15
|
+
background-color: rgba(0,0,0,.05);
|
16
|
+
font-weight: bold;
|
17
|
+
color: #999;
|
18
|
+
border: 1px solid rgba(0,0,0,.05);
|
19
|
+
}
|
20
|
+
ol ol {
|
21
|
+
margin: 9px;
|
22
|
+
}
|
23
|
+
div.example-group {
|
24
|
+
font-weight: normal;
|
25
|
+
color: #333;
|
26
|
+
overflow: hidden;
|
27
|
+
}
|
28
|
+
div.example-group .duration,
|
29
|
+
div.example-group .share {
|
30
|
+
margin-left: 10px;
|
31
|
+
}
|
32
|
+
div.example-group .title {
|
33
|
+
font-weight: bold;
|
34
|
+
margin-left: 0;
|
35
|
+
}
|
36
|
+
ol.active {
|
37
|
+
background-color: #ffffe1;
|
38
|
+
cursor: pointer;
|
39
|
+
}
|
40
|
+
ol.active ol {
|
41
|
+
background-color: #fff;
|
42
|
+
}
|
43
|
+
#chart {
|
44
|
+
width: 100%;
|
45
|
+
height: 400px;
|
46
|
+
}
|
47
|
+
hr {
|
48
|
+
border: none;
|
49
|
+
height: 1px;
|
50
|
+
background-color: #ccc;
|
51
|
+
margin: 18px 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
</style>
|
55
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
56
|
+
<script type="text/javascript">
|
57
|
+
google.load('visualization', '1', { packages: ['corechart'] });
|
58
|
+
</script>
|
59
|
+
<script type="text/javascript">
|
60
|
+
var DomEl = (function() {
|
61
|
+
function DomEl(node) {
|
62
|
+
this.node = node;
|
63
|
+
this.type = node.nodeName;
|
64
|
+
}
|
65
|
+
|
66
|
+
DomEl.prototype.nearestParent = function(query) {
|
67
|
+
var nearest_parent = this.node;
|
68
|
+
while(nearest_parent.nodeName.toLowerCase() !== query) {
|
69
|
+
nearest_parent = nearest_parent.parentNode;
|
70
|
+
}
|
71
|
+
return new DomEl(nearest_parent);
|
72
|
+
};
|
73
|
+
|
74
|
+
DomEl.prototype.addClass = function(class_name) {
|
75
|
+
if(this.node.className.indexOf(class_name) === -1) {
|
76
|
+
this.node.className = (this.node.className + ' ' + class_name).replace(/^ *| *$/, '');
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
DomEl.prototype.removeClass = function(class_name) {
|
81
|
+
if(this.node.className.indexOf(class_name) != -1) {
|
82
|
+
this.node.className = (this.node.className.replace(new RegExp('\\b' + class_name + '\\b', 'g'), '')).replace(/^ *| *$/, '');
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
DomEl.prototype.active_class = 'active';
|
87
|
+
|
88
|
+
DomEl.prototype.activate = function() {
|
89
|
+
this.addClass(this.active_class);
|
90
|
+
};
|
91
|
+
|
92
|
+
DomEl.prototype.deactivate = function() {
|
93
|
+
this.removeClass(this.active_class);
|
94
|
+
};
|
95
|
+
|
96
|
+
DomEl.prototype.attr = function(query) {
|
97
|
+
return this.node.querySelector(query).innerHTML;
|
98
|
+
};
|
99
|
+
|
100
|
+
return DomEl;
|
101
|
+
})();
|
102
|
+
|
103
|
+
function $(query, el) {
|
104
|
+
if(!el) el = document;
|
105
|
+
return Array.prototype.slice.call(el.querySelectorAll(query)).map(function(node) {
|
106
|
+
return new DomEl(node);
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
function showChartFromList(e) {
|
111
|
+
var items = $('ol.active > li > div.example-group').map(function(item) {
|
112
|
+
return [item.attr('span.title'), parseFloat(item.attr('span.duration'))];
|
113
|
+
});
|
114
|
+
items.unshift(['Group', 'Time']);
|
115
|
+
var data = google.visualization.arrayToDataTable(items);
|
116
|
+
new google.visualization.PieChart(document.getElementById('chart')).draw(data, { title: 'Time distribution' });
|
117
|
+
}
|
118
|
+
|
119
|
+
function highlightList(e) {
|
120
|
+
$('ol.active').forEach(function(el) { el.deactivate() });
|
121
|
+
new DomEl(e.target).nearestParent('ol').activate();
|
122
|
+
}
|
123
|
+
|
124
|
+
function revertList(e) {
|
125
|
+
new DomEl(e.target).deactivate();
|
126
|
+
}
|
127
|
+
|
128
|
+
window.onload = function() {
|
129
|
+
var lists = document.getElementById('lists');
|
130
|
+
lists.addEventListener('click', showChartFromList, true);
|
131
|
+
lists.addEventListener('mouseover', highlightList, true);
|
132
|
+
lists.addEventListener('mouseout', revertList, true);
|
133
|
+
highlightList({ target: document.querySelector('ol')});
|
134
|
+
showChartFromList();
|
135
|
+
};
|
136
|
+
</script>
|
137
|
+
</head>
|
138
|
+
<body>
|
139
|
+
<div id="chart"></div>
|
140
|
+
<hr>
|
141
|
+
PLACEHOLDER
|
142
|
+
</body>
|
143
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: example_group_timer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/example_group_timer/timed_group.rb
|
64
64
|
- lib/example_group_timer/timed_item.rb
|
65
65
|
- lib/example_group_timer/version.rb
|
66
|
+
- support/template.html
|
66
67
|
homepage: https://github.com/avdgaag/example_group_timer
|
67
68
|
licenses: []
|
68
69
|
post_install_message:
|