Skip to content

Commit c834820

Browse files
committed
Merge branch 'clipboard'
2 parents af41230 + 3487586 commit c834820

File tree

8 files changed

+95
-44
lines changed

8 files changed

+95
-44
lines changed

build/client.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5370,7 +5370,7 @@ function renderResponse (err, resp, body) {
53705370
var insertContent = body
53715371
}
53725372
else {
5373-
console.log(body)
5373+
//console.log(body)
53745374
var results = JSON.parse(body)
53755375

53765376
if (mode == 'plain') {
@@ -5384,7 +5384,9 @@ function renderResponse (err, resp, body) {
53845384
dom('.container.target').replace('#loading', "<div class='markdown-body'>{insert}</div>", {insert: insertContent} )
53855385

53865386
dom('.container.header').toggleClass('hidden')
5387-
dom('.container.dependencies').add( "<pre>{insert}</pre>", {insert: treeToDependencies(results)} )
5387+
5388+
dom('.container.dependencies .target').add( "<pre>{insert}</pre>", {insert: treeToDependencies(results).replace(/\n/g, '</pre><pre>')} )
5389+
new Clipboard('.btn.clipboard')
53885390
dom('.container.dependencies').toggleClass('hidden')
53895391
}
53905392

@@ -5420,8 +5422,13 @@ function treeToArchyTree(tree) {
54205422
var newTree = {}
54215423

54225424
function recurssiveArchyFormat(tree, newTree) {
5423-
newTree.label = "<a href ='"+ tree.url + "'>" + tree.label + "</a>"
5424-
if (tree.parent == null) { newTree.label = "<a href ='"+ tree.url + "'>This file</a>" }
5425+
var label = tree.parent == null ? tree.url.replace(/^.*\//,'') : tree.label
5426+
5427+
newTree.label = "<a href ='"+tree.url+"'>"+label+"</a>"
5428+
newTree.label += "<button class='btn clipboard' data-clipboard-text='+["+label+"]("+tree.url+")'>"
5429+
newTree.label += " <img class='clippy' src='images/clippy.svg' alt='Copy to clipboard' width='13'>"
5430+
newTree.label += "</button>"
5431+
54255432
newTree.nodes = []
54265433

54275434
tree.children.forEach( function(childTree, index) {

images/clippy.svg

Lines changed: 3 additions & 0 deletions
Loading
File renamed without changes.

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1 class='header'>hypermarkdown</h1>
1616
</div>
1717
<div class='container target'>
1818
<div id='loading' >
19-
<img src='/loading.gif' />
19+
<img src='/images/loading.gif' />
2020
<p>Loading...</p>
2121
</div>
2222
<div id='how-to' class='hidden'>
@@ -33,9 +33,13 @@ <h1 class='header'>hypermarkdown</h1>
3333
<div class='container dependencies hidden'>
3434
<h2>Dependencies</h2>
3535
This was page woven together from several markdown files. If you'd like to propose changes, or reference these modules in your own works, the master copies are listed below. Note it's a nested tree strucutre because Hypermarkdown allows you to build modules of text with modules of text.
36+
37+
<div class='target'></div>
38+
<img class='clippy' src='images/clippy.svg' width='13'> = copy include code to clipboard
3639
</div>
3740
</main>
3841
</body>
3942

43+
<script src="/clipboard.min.js"></script>
4044
<script src='/app.js'></script>
4145
</html>

server.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,37 @@ function buildHypermarkdownTree(req, res, match) {
5757
}
5858
}
5959

60-
router.addRoute('/api/authors', authorsResponse)
61-
function authorsResponse(req, res, match) {
62-
var requestDetails = url.parse(req.url, true)
63-
var source = requestDetails.query.source
64-
65-
if (source && source.match( regexps.mdUrl ) && source.match( regexps.githublab )) {
66-
var ownerAndRepo = source.match(/.*github.com\/([\w-_]+\/[\w-_]+)/)[1]
67-
// this path assumes a lot about the source provided
68-
var path = source.match(/.*github.com\/[\w-_]+\/[\w-_]+\/(.*\.md)/)[1].replace('blob/master/', '')
69-
70-
fetchAuthors(ownerAndRepo, {path: path}, function(err, users) {
71-
if (err) {
72-
res.writeHead(400, {'content-type': 'text/plain'})
73-
res.write("You've hit a bad url somewhere in there, we got the error:<br />"+ err)
74-
res.end()
75-
return
76-
}
77-
78-
console.log(users)
79-
res.writeHead(200, {'content-type': 'application/json'})
80-
81-
res.write( stringify(users, null, 2) )
82-
res.end()
83-
})
84-
}
85-
else {
86-
res.writeHead(400, {'content-type': 'text/plain'})
87-
res.write("error or no easy way to determine authors")
88-
res.end()
89-
}
90-
}
60+
//router.addRoute('/api/authors', authorsResponse)
61+
//function authorsResponse(req, res, match) {
62+
//var requestDetails = url.parse(req.url, true)
63+
//var source = requestDetails.query.source
64+
65+
//if (source && source.match( regexps.mdUrl ) && source.match( regexps.githublab )) {
66+
//var ownerAndRepo = source.match(/.*github.com\/([\w-_]+\/[\w-_]+)/)[1]
67+
//// this path assumes a lot about the source provided
68+
//var path = source.match(/.*github.com\/[\w-_]+\/[\w-_]+\/(.*\.md)/)[1].replace('blob/master/', '')
69+
70+
//fetchAuthors(ownerAndRepo, {path: path}, function(err, users) {
71+
//if (err) {
72+
//res.writeHead(400, {'content-type': 'text/plain'})
73+
//res.write("You've hit a bad url somewhere in there, we got the error:<br />"+ err)
74+
//res.end()
75+
//return
76+
//}
77+
78+
//console.log(users)
79+
//res.writeHead(200, {'content-type': 'application/json'})
80+
81+
//res.write( stringify(users, null, 2) )
82+
//res.end()
83+
//})
84+
//}
85+
//else {
86+
//res.writeHead(400, {'content-type': 'text/plain'})
87+
//res.write("error or no easy way to determine authors")
88+
//res.end()
89+
//}
90+
//}
9191

9292

9393
function handler(req, res) {
@@ -101,11 +101,17 @@ function handler(req, res) {
101101
else if (req.url === '/app.js') {
102102
fs.createReadStream('./build/client.js').pipe(res)
103103
}
104+
else if (req.url === '/clipboard.min.js') {
105+
fs.createReadStream('./node_modules/clipboard/dist/clipboard.min.js').pipe(res)
106+
}
104107
else if (req.url === '/styles.css') {
105108
fs.createReadStream('./styles.css').pipe(res)
106109
}
107-
else if (req.url === '/loading.gif') {
108-
fs.createReadStream('./loading.gif').pipe(res)
110+
else if (req.url === '/images/loading.gif') {
111+
fs.createReadStream('./images/loading.gif').pipe(res)
112+
}
113+
else if (req.url === '/images/clippy.svg') {
114+
fs.createReadStream('./images/clippy.svg').pipe(res)
109115
}
110116
else if (requestDetails.path.match( regexps.mdUrl )) {
111117
// redirects shortened urls

source/client.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function renderResponse (err, resp, body) {
2727
var insertContent = body
2828
}
2929
else {
30-
console.log(body)
30+
//console.log(body)
3131
var results = JSON.parse(body)
3232

3333
if (mode == 'plain') {
@@ -41,7 +41,9 @@ function renderResponse (err, resp, body) {
4141
dom('.container.target').replace('#loading', "<div class='markdown-body'>{insert}</div>", {insert: insertContent} )
4242

4343
dom('.container.header').toggleClass('hidden')
44-
dom('.container.dependencies').add( "<pre>{insert}</pre>", {insert: treeToDependencies(results)} )
44+
45+
dom('.container.dependencies .target').add( "<pre>{insert}</pre>", {insert: treeToDependencies(results).replace(/\n/g, '</pre><pre>')} )
46+
new Clipboard('.btn.clipboard')
4547
dom('.container.dependencies').toggleClass('hidden')
4648
}
4749

styles.css

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,21 @@ button.collapser.has-plus::after {
102102
margin-bottom: 40px;
103103
}
104104

105-
.container.dependencies pre {
106-
font-size: 14px;
105+
.container.dependencies .target {
107106
padding: 15px 0 20px 20px;
108107
}
109108

109+
.container.dependencies .target pre {
110+
font-size: 14px;
111+
padding 0;
112+
margin: 0;
113+
}
114+
115+
.container.dependencies .target pre:hover button {
116+
opacity: .5;
117+
}
118+
119+
110120
.stitch-mark.visible {
111121
/*box-shadow: 2px 3px 8px #D2D2D2;*/
112122
/*margin: 0px 8px;*/
@@ -131,6 +141,17 @@ button {
131141
margin-right: 10px;
132142
}
133143

144+
button.btn.clipboard {
145+
background-color: #fff;
146+
opacity: 0;
147+
}
148+
149+
150+
.container.dependencies .target pre button.btn.clipboard:hover {
151+
cursor: pointer;
152+
opacity: 1;
153+
}
154+
134155
button.active {
135156
background: rgba(52, 233, 213, 0.39);
136157
}
@@ -148,6 +169,9 @@ button::-moz-focus-inner {
148169
}
149170

150171

172+
173+
174+
151175
/*markdown style from : https://github.com/jasonm23/markdown-css-themes/blob/gh-pages/markdown.css*/
152176

153177
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }

treeToDependencies.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ function treeToArchyTree(tree) {
1010
var newTree = {}
1111

1212
function recurssiveArchyFormat(tree, newTree) {
13-
newTree.label = "<a href ='"+ tree.url + "'>" + tree.label + "</a>"
14-
if (tree.parent == null) { newTree.label = "<a href ='"+ tree.url + "'>This file</a>" }
13+
var label = tree.parent == null ? tree.url.replace(/^.*\//,'') : tree.label
14+
15+
newTree.label = "<a href ='"+tree.url+"'>"+label+"</a>"
16+
newTree.label += "<button class='btn clipboard' data-clipboard-text='+["+label+"]("+tree.url+")'>"
17+
newTree.label += " <img class='clippy' src='images/clippy.svg' alt='Copy to clipboard' width='13'>"
18+
newTree.label += "</button>"
19+
1520
newTree.nodes = []
1621

1722
tree.children.forEach( function(childTree, index) {

0 commit comments

Comments
 (0)