Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2143a0

Browse files
committedNov 15, 2019
wip
1 parent f08518a commit c2143a0

File tree

6 files changed

+72
-20
lines changed

6 files changed

+72
-20
lines changed
 

Diff for: ‎lib/reverse_coverage/formatters/html/assets/javascripts/application.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ $(document).ready(function() {
153153
let node = {
154154
name: currentNode.name,
155155
example: currentNode.example,
156+
is_file_name: currentNode.is_file_name,
157+
path: currentNode.path,
156158
expanded: true,
157159
children: traverseTreeData([], paths.slice(1))
158160
};
@@ -170,19 +172,21 @@ $(document).ready(function() {
170172

171173
$('.source_table.highlighted li.covered').live('click', function() {
172174
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
173-
if(!$(this).children('.reverse_coverage').is(':visible')){
175+
if(!$(this).children('.reverse_coverage').is(':visible')) {
174176
let treeData = [];
175177
const self = this;
176178
exampleRefs.forEach(function(ref) {
177-
const example = window.examples[ref]
178-
const treeNodes = []
179-
example["file_path"].split('/').slice(1).forEach(function(node_path){
180-
treeNodes.push({ name: node_path })
179+
const example = window.examples[ref];
180+
const treeNodes = [];
181+
const parts = example['file_path'].split('/').slice(1);
182+
parts.forEach(function(node_path, i) {
183+
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
184+
if(node.is_file_name) node.path = example['file_path'];
185+
treeNodes.push(node);
181186
});
182187
treeNodes.push({ example: example, name: example['full_description'] });
183-
184-
treeData = traverseTreeData(treeData, treeNodes)
185-
})
188+
treeData = traverseTreeData(treeData, treeNodes);
189+
});
186190

187191
const domElement = self.querySelector('.reverse_coverage');
188192

Diff for: ‎lib/reverse_coverage/formatters/html/assets/javascripts/treeview.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@
8383
var expando = document.createElement('div');
8484

8585
leaf.setAttribute('class', 'tree-leaf');
86-
content.setAttribute('class', 'tree-leaf-content');
86+
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
8787
content.setAttribute('data-item', JSON.stringify(item));
8888
text.setAttribute('class', 'tree-leaf-text');
8989
text.textContent = item.name;
90-
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
90+
if(item.is_file_name) {
91+
var copyURL = document.createElement('a');
92+
copyURL.setAttribute('href', 'Javascript:void(0)');
93+
copyURL.setAttribute('class', 'copy-example-path');
94+
copyURL.setAttribute('data-path', item.path);
95+
text.appendChild(copyURL);
96+
}
97+
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
9198
expando.textContent = item.expanded ? '-' : '+';
9299
content.appendChild(expando);
93100
content.appendChild(text);
@@ -140,6 +147,14 @@
140147
forEach(container.querySelectorAll('.tree-expando'), function (node) {
141148
node.onclick = click;
142149
});
150+
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
151+
node.onclick = function(e) {
152+
var el = (e.target || e.currentTarget);
153+
event.stopPropagation();
154+
var path = el.getAttribute('data-path');
155+
navigator.clipboard.writeText(path);
156+
};
157+
});
143158
}
144159

145160
/**

Diff for: ‎lib/reverse_coverage/formatters/html/assets/stylesheets/screen.css.sass

+7
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,10 @@ td
247247

248248
&:before
249249
content: ''
250+
251+
a.copy-example-path
252+
background: url('./clipboard.gif') no-repeat
253+
display: inline-block
254+
width: 11px
255+
height: 13px
256+
margin-left: 12px

Diff for: ‎lib/reverse_coverage/formatters/html/public/application.css

+7
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@ td {
836836
.tree-expando.hidden + .tree-leaf-text:before {
837837
content: "↳ "; }
838838

839+
a.copy-example-path {
840+
background: url("./clipboard.gif") no-repeat;
841+
display: inline-block;
842+
width: 11px;
843+
height: 13px;
844+
margin-left: 12px; }
845+
839846

840847

841848

Diff for: ‎lib/reverse_coverage/formatters/html/public/application.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -1663,11 +1663,18 @@ jQuery.url = function()
16631663
var expando = document.createElement('div');
16641664

16651665
leaf.setAttribute('class', 'tree-leaf');
1666-
content.setAttribute('class', 'tree-leaf-content');
1666+
content.setAttribute('class', 'tree-leaf-content' + (item.is_file_name ? ' file_name' : ''));
16671667
content.setAttribute('data-item', JSON.stringify(item));
16681668
text.setAttribute('class', 'tree-leaf-text');
16691669
text.textContent = item.name;
1670-
expando.setAttribute('class', 'tree-expando ' + (item.expanded ? 'expanded' : ''));
1670+
if(item.is_file_name) {
1671+
var copyURL = document.createElement('a');
1672+
copyURL.setAttribute('href', 'Javascript:void(0)');
1673+
copyURL.setAttribute('class', 'copy-example-path');
1674+
copyURL.setAttribute('data-path', item.path);
1675+
text.appendChild(copyURL);
1676+
}
1677+
expando.setAttribute('class', 'tree-expando' + (item.expanded ? ' expanded' : ''));
16711678
expando.textContent = item.expanded ? '-' : '+';
16721679
content.appendChild(expando);
16731680
content.appendChild(text);
@@ -1720,6 +1727,14 @@ jQuery.url = function()
17201727
forEach(container.querySelectorAll('.tree-expando'), function (node) {
17211728
node.onclick = click;
17221729
});
1730+
forEach(container.querySelectorAll('.copy-example-path'), function (node) {
1731+
node.onclick = function(e) {
1732+
var el = (e.target || e.currentTarget);
1733+
event.stopPropagation();
1734+
var path = el.getAttribute('data-path');
1735+
navigator.clipboard.writeText(path);
1736+
};
1737+
});
17231738
}
17241739

17251740
/**
@@ -1994,6 +2009,8 @@ $(document).ready(function() {
19942009
let node = {
19952010
name: currentNode.name,
19962011
example: currentNode.example,
2012+
is_file_name: currentNode.is_file_name,
2013+
path: currentNode.path,
19972014
expanded: true,
19982015
children: traverseTreeData([], paths.slice(1))
19992016
};
@@ -2011,19 +2028,21 @@ $(document).ready(function() {
20112028

20122029
$('.source_table.highlighted li.covered').live('click', function() {
20132030
const exampleRefs = $(this).children('.reverse_coverage')[0].dataset.exampleRefs.split(",");
2014-
if(!$(this).children('.reverse_coverage').is(':visible')){
2031+
if(!$(this).children('.reverse_coverage').is(':visible')) {
20152032
let treeData = [];
20162033
const self = this;
20172034
exampleRefs.forEach(function(ref) {
2018-
const example = window.examples[ref]
2019-
const treeNodes = []
2020-
example["file_path"].split('/').slice(1).forEach(function(node_path){
2021-
treeNodes.push({ name: node_path })
2035+
const example = window.examples[ref];
2036+
const treeNodes = [];
2037+
const parts = example['file_path'].split('/').slice(1);
2038+
parts.forEach(function(node_path, i) {
2039+
var node = { name: node_path, is_file_name: (parts.length - 1 == i) };
2040+
if(node.is_file_name) node.path = example['file_path'];
2041+
treeNodes.push(node);
20222042
});
20232043
treeNodes.push({ example: example, name: example['full_description'] });
2024-
2025-
treeData = traverseTreeData(treeData, treeNodes)
2026-
})
2044+
treeData = traverseTreeData(treeData, treeNodes);
2045+
});
20272046

20282047
const domElement = self.querySelector('.reverse_coverage');
20292048

333 Bytes
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.