Skip to content

Commit c290162

Browse files
authored
Merge pull request #28 from rakeshAlgo/view-source-url-style
View source url style
2 parents 92c720a + 7bc0209 commit c290162

File tree

6 files changed

+161
-81
lines changed

6 files changed

+161
-81
lines changed

gulp.d/tasks/build-preview-pages.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ module.exports = (src, previewSrc, previewDest, sink = () => map()) => (done) =>
106106
pageModel.attributes = Object.entries({ ...attributes, ...componentVersion.asciidoc.attributes })
107107
.filter(([name, val]) => name.startsWith('page-'))
108108
.reduce((accum, [name, val]) => ({ ...accum, [name.substr(5)]: val }), {})
109-
pageModel.contents = Buffer.from(doc.convert())
109+
pageModel.contents = Buffer.from(
110+
doc
111+
.convert()
112+
// NOTE emulates the behavior of the view source url extension
113+
.replace(
114+
/<pre([^>]*)(><code[^>]*)?>\[data-source-url=(.+?)\]\n/g,
115+
'<pre$1$2 data-source-url="$3">'
116+
)
117+
)
110118
}
111119
file.extname = '.html'
112120
try {

preview-src/index.adoc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,17 @@ The *Server Resources* statistics section displays the resource information on t
275275
.A query using the fluent API (lines are forced to wrap)
276276
[source,java]
277277
----
278-
Observable<AsyncN1qlQueryResult> theAirline = bucket.async() // <1>
279-
.query(
280-
N1qlQuery.simple(select("name").from("travel_sample").as("Airline").where(x("id").eq(5209)))
281-
);
282-
return thisAirline; // <2>
278+
[data-source-url=https://github.com/couchbase/docs-sdk-java/blob/20c44c9e7ca86ea475b7aa33c58d5670aa7c4495/modules/ROOT/pages/n1ql-queries-with-sdk.adoc#L53-L58]
279+
Statement statement = select("fname", "lname", "age").from(i("default")).where(x("age").gt(x("$age"))); // <1>
280+
JsonObject placeholderValues = JsonObject.create().put("age", 22);
281+
q = N1qlQuery.parameterized(statement, placeholderValues); // <2>
282+
for (N1qlQueryRow row : bkt.query(q)) { // <3>
283+
System.out.println(row);
284+
}
283285
----
284-
<1> Sets up an async query.
285-
<2> Returns the result of the query.
286+
<1> Defines the query.
287+
<2> Inserts placeholder values into the query.
288+
<3> Runs the query.
286289

287290
[#vbucket-stats]
288291
== Monitoring `vBucket` Resources

src/css/clipboard.css

Lines changed: 115 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,88 @@
1-
.copy-code-button {
1+
.view-source-button {
2+
color: var(--color-brand-gray4);
3+
font-family: "Source Code Pro", sans-serif;
4+
background: url(../img/awesome-github.svg) no-repeat center center;
5+
background-size: cover;
6+
display: inline-block;
7+
width: 16px;
8+
height: 15.5px;
9+
font-size: 0;
10+
margin-left: 0.5rem;
11+
}
12+
13+
.view-source-button:hover::after {
14+
content: attr(data-title);
15+
color: var(--color-brand-gray4);
16+
font-size: var(--font-base);
17+
font-weight: var(--weight-light);
18+
line-height: 1;
19+
text-transform: capitalize;
20+
position: absolute;
21+
bottom: -53px;
22+
right: -30%;
23+
left: auto;
24+
margin: 0;
25+
padding: 5px;
26+
text-align: center;
27+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
28+
background: var(--color-brand-white);
29+
border: 1px solid var(--color-brand-gray7);
30+
box-sizing: border-box;
31+
border-radius: 3px;
32+
min-width: 90px;
33+
font-family: "Source Sans Pro", sans-serif;
34+
}
35+
36+
.view-source-button:hover::before {
37+
width: 0;
38+
height: 0;
39+
border-left: 7px solid transparent;
40+
border-right: 7px solid transparent;
41+
border-bottom: 10px solid var(--color-brand-white);
242
position: absolute;
43+
content: "";
44+
box-shadow: inset 0 0 1px #bec0c1;
45+
bottom: -27px;
46+
right: auto;
47+
left: auto;
48+
}
49+
50+
.copy-code-button {
351
background: url(../img/copy.png) no-repeat center right/contain;
4-
width: 24px;
5-
height: 14px;
6-
right: 1rem;
7-
top: 12px;
8-
display: none;
52+
width: 13px;
53+
height: 16px;
954
cursor: pointer;
1055
font-family: "Source Sans Pro", sans-serif;
1156
color: var(--color-brand-gray4);
12-
z-index: 1;
57+
margin-left: 0.5rem;
58+
margin-right: 0.5rem;
1359
}
1460

1561
a.copy-code-button:focus,
1662
a.copy-code-button:hover {
1763
color: var(--color-brand-gray4);
1864
}
1965

20-
.doc .listingblock:hover .copy-code-button {
21-
display: block;
22-
}
23-
2466
.copy-code-button:hover::after {
2567
content: attr(data-title);
2668
color: var("--color-brand-gray4");
27-
font-size: 14px;
69+
font-size: var(--font-base);
2870
font-weight: var(--weight-light);
2971
line-height: 1;
3072
text-transform: capitalize;
3173
position: absolute;
3274
bottom: -53px;
33-
right: -100%;
34-
left: -100%;
35-
margin: auto;
75+
right: -30%;
76+
left: auto;
77+
margin: 0;
3678
padding: 5px;
3779
text-align: center;
3880
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
3981
background: var(--color-brand-white);
4082
border: 1px solid var(--color-brand-gray7);
4183
box-sizing: border-box;
4284
border-radius: 3px;
43-
/* min-width: 90px; */
85+
min-width: 80px;
4486
font-family: "Source Sans Pro", sans-serif;
4587
}
4688

@@ -54,5 +96,62 @@ a.copy-code-button:hover {
5496
content: "";
5597
box-shadow: inset 0 0 1px #bec0c1;
5698
bottom: -27px;
99+
right: auto;
100+
left: auto;
101+
}
102+
103+
.doc .listingblock code[data-lang] + .source-type-box {
104+
position: absolute;
105+
top: 0;
57106
right: 0;
107+
display: none;
108+
align-items: center;
109+
z-index: 1;
110+
padding-top: 12px;
111+
}
112+
113+
.doc .listingblock code[data-lang] + .source-type-box .data-source {
114+
content: attr(data-lang);
115+
color: var("--color-brand-gray1");
116+
font-size: 0.75rem;
117+
font-weight: var(--weight-normal);
118+
letter-spacing: 1px;
119+
line-height: 18px;
120+
text-transform: uppercase;
121+
font-family: "Source Code Pro", sans-serif;
122+
padding-right: 0.5rem;
123+
border-right: 1px solid var(--color-brand-gray9);
124+
}
125+
126+
/* .doc .listingblock:hover code[data-lang] + .source-type-box .data-source {
127+
display: block;
128+
} */
129+
130+
.doc .listingblock:hover code[data-lang] + .source-type-box {
131+
display: flex;
132+
}
133+
134+
.doc .listingblock pre .fade-shadow {
135+
content: "";
136+
display: inline-block;
137+
background:
138+
transparent
139+
linear-gradient(
140+
180deg,
141+
#f1f7fe0d 0%,
142+
#f1f7fe40 18%,
143+
#f1f7fe 68%,
144+
#f1f7fe 100%
145+
)
146+
0% 0% no-repeat padding-box;
147+
width: 65px;
148+
height: 80%;
149+
position: absolute;
150+
right: 0;
151+
top: 0;
152+
}
153+
154+
code.language-console.hljs.shell {
155+
white-space: nowrap;
156+
overflow-x: auto;
58157
}

src/css/doc.css

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -574,52 +574,6 @@
574574
575575
*/
576576

577-
.doc .listingblock code[data-lang] + .data-source {
578-
content: attr(data-lang);
579-
color: var("--color-brand-gray1");
580-
display: none;
581-
font-size: 0.75rem;
582-
font-weight: var(--weight-normal);
583-
letter-spacing: 1px;
584-
line-height: 18px;
585-
text-transform: uppercase;
586-
position: absolute;
587-
top: 12px;
588-
right: 2.4rem;
589-
font-family: "Source Sans Pro", sans-serif;
590-
padding-right: 0.5rem;
591-
border-right: 1px solid var(--color-brand-gray9);
592-
z-index: 1;
593-
}
594-
595-
.doc .listingblock:hover code[data-lang] + .data-source {
596-
display: block;
597-
}
598-
599-
.doc .listingblock pre .fade-shadow {
600-
display: inline-block;
601-
background:
602-
transparent
603-
linear-gradient(
604-
180deg,
605-
#f1f7fe0d 0%,
606-
#f1f7fe40 18%,
607-
#f1f7fe 68%,
608-
#f1f7fe 100%
609-
)
610-
0% 0% no-repeat padding-box;
611-
width: 65px;
612-
height: 80%;
613-
position: absolute;
614-
right: 2px;
615-
top: 0;
616-
}
617-
618-
code.language-console.hljs.shell {
619-
white-space: nowrap;
620-
overflow-x: auto;
621-
}
622-
623577
table.tableblock code.language-console.hljs.shell {
624578
white-space: normal;
625579
}

src/img/awesome-github.svg

Lines changed: 1 addition & 0 deletions
Loading

src/js/07-copy-to-clipboard.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
;(function () {
22
'use strict'
33
document.querySelectorAll('pre > code').forEach(function (codeBlock) {
4-
var button = document.createElement('a')
5-
button.className = 'copy-code-button'
6-
//button.type = 'button'
7-
button.dataset.title = 'Copy'
4+
var viewSourceLink
5+
var sourceUrl = codeBlock.dataset.sourceUrl
6+
if (sourceUrl) {
7+
viewSourceLink = document.createElement('a')
8+
viewSourceLink.href = codeBlock.dataset.sourceUrl
9+
viewSourceLink.className = 'view-source-button'
10+
viewSourceLink.target = '_blank'
11+
viewSourceLink.dataset.title = 'View On Github'
12+
viewSourceLink.appendChild(document.createTextNode('View'))
13+
}
14+
// console.log(codeBlock)
15+
var sourceTypeBox = document.createElement('div')
16+
sourceTypeBox.className = 'source-type-box'
17+
var copyButton = document.createElement('a')
18+
copyButton.className = 'copy-code-button'
19+
//copyButton.type = 'button'
20+
copyButton.dataset.title = 'Copy'
821

922
var dataSource = document.createElement('span')
1023
dataSource.className = 'data-source'
@@ -13,29 +26,31 @@
1326
var fadeShadow = document.createElement('span')
1427
fadeShadow.className = 'fade-shadow'
1528

16-
button.addEventListener('click', function (e) {
29+
copyButton.addEventListener('click', function (e) {
1730
if (e.target && e.target.matches('a.copy-code-button')) {
1831
navigator.clipboard.writeText(codeBlock.innerText).then(
1932
function () {
2033
/* Chrome doesn't seem to blur automatically,
2134
leaving the button in a focused state. */
22-
button.blur()
35+
copyButton.blur()
2336

24-
button.dataset.title = 'Copied ✓'
37+
copyButton.dataset.title = 'Copied ✓'
2538

2639
setTimeout(function () {
27-
button.dataset.title = 'Copy'
40+
copyButton.dataset.title = 'Copy'
2841
}, 2000)
2942
},
3043
function () {
31-
button.dataset.title = 'Error'
44+
copyButton.dataset.title = 'Error'
3245
}
3346
)
3447
}
3548
})
3649
var pre = codeBlock.parentNode
37-
pre.appendChild(dataSource)
38-
pre.appendChild(button)
50+
pre.appendChild(sourceTypeBox)
51+
sourceTypeBox.appendChild(dataSource)
52+
if (viewSourceLink) sourceTypeBox.appendChild(viewSourceLink)
53+
sourceTypeBox.appendChild(copyButton)
3954
pre.appendChild(fadeShadow)
4055
})
4156
})()

0 commit comments

Comments
 (0)