Skip to content

Commit 8b659bb

Browse files
committed
Support title, language and showCopy on {{docs-snippet}}
Fixes #37, fixes #38.
1 parent 1c80641 commit 8b659bb

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

addon/components/docs-demo/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
&__snippets-nav {
13-
background: #E3E3E3;
13+
background: $code-title-background-color;
1414
padding: 12px 16px;
1515
font-weight: bold;
1616
}

addon/components/docs-demo/x-snippet/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.docs-demo-snippet {
22
font-size: 14px;
3-
background: #f8f8f8;
3+
background: $code-background-color;
44

55
&__inner {
66
padding: 15px 6px;

addon/components/docs-snippet/component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default Component.extend({
77
tagName: '',
88
layout,
99

10+
language: undefined,
11+
title: undefined,
12+
showCopy: false,
13+
1014
_unindent: function(src) {
1115
if (!this.get('unindent')) {
1216
return src;

addon/components/docs-snippet/styles.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
opacity: 1;
1515
}
1616
}
17+
18+
&__title {
19+
background-color: $code-title-background-color;
20+
font-family: monospace;
21+
font-size: 14px;
22+
padding: 8px 15px;
23+
}
1724
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
<div class='docs-snippet' data-test-id={{name}}>
2-
{{#copy-button
3-
clipboardText=snippetText
4-
title='copy to clipboard'
5-
}}
6-
Copy
7-
{{/copy-button}}
1+
{{#if file}}
2+
<div class='docs-snippet__title'>{{file}}</div>
3+
{{/if}}
84

9-
{{#if hasBlock}}
10-
{{code-snippet name=(concat name '.hbs')}}
11-
{{else}}
12-
{{code-snippet name=name language=language}}
5+
<div class='docs-snippet' data-test-id={{name}}>
6+
{{#if showCopy}}
7+
{{#copy-button
8+
clipboardText=snippetText
9+
title='copy to clipboard'
10+
}}
11+
Copy
12+
{{/copy-button}}
1313
{{/if}}
14+
15+
{{code-snippet name=(if hasBlock (concat name '.hbs') name) language=language}}
1416
</div>

addon/styles/addon.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
$code-color: #fafafa; // #f5f2f0
1+
$code-background-color: #fafafa; // #f5f2f0
2+
$code-title-background-color: #e3e3e3;
23

34
@import 'normalize';
45
@import 'pod-styles';
@@ -77,7 +78,7 @@ button {
7778
}
7879

7980
code {
80-
background: $code-color;
81+
background: $code-background-color;
8182
}
8283

8384
blockquote {
@@ -103,8 +104,9 @@ button {
103104
// font-style: italic;
104105
}
105106

106-
pre {
107-
background: $code-color;
107+
// Applied to fenced code in compiled markdown
108+
&__code {
109+
background: $code-background-color;
108110
padding: 20px;
109111
overflow-x: scroll;
110112
font-size: 14px;

lib/utils/compile-markdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class HBSRenderer extends marked.Renderer {
2828
}
2929

3030
code() {
31-
return this._escapeCurlies(super.code.apply(this, arguments));
31+
let code = this._escapeCurlies(super.code.apply(this, arguments));
32+
return code.replace(/^<pre>/, '<pre class="docs-md__code">');
3233
}
3334

3435
// Unescape quotes in text, as they may be part of a Handlebars statement

tests/dummy/app/pods/docs/components/docs-demo/template.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
Here's the code that rendered the above demo (you can copy-paste this block to get going in your own app):
4444
</p>
4545

46-
{{code-snippet name='docs-demo-basic-src.hbs'}}
46+
{{docs-snippet name='docs-demo-basic-src.hbs'}}
4747

4848
<p>To explain,</p>
4949

@@ -58,7 +58,7 @@
5858

5959
<p>You can render multiple snippets to support your example. This can be useful when part of your example relies on code defined elsewhere, for example in a controller or stylesheet.</p>
6060

61-
<p>Use a file extension to help code-snippet identify and properly syntax highlight your snippet. Templates end in `.hbs`, JavaScript snippets end in `.js`, stylesheets in `.css` or `.scss`.</p>
61+
<p>Use a file extension to help docs-snippet identify and properly syntax highlight your snippet. Templates end in `.hbs`, JavaScript snippets end in `.js`, stylesheets in `.css` or `.scss`.</p>
6262

6363
{{#docs-demo as |demo|}}
6464
{{#demo.example data-test-id='docs-demo-multiple'}}
@@ -113,7 +113,7 @@
113113

114114
<p>Here's the code for this:</p>
115115

116-
{{code-snippet name='live-example-src.hbs'}}
116+
{{docs-snippet name='live-example-src.hbs'}}
117117

118118
<p>Note that we're using the <code>demo.live-example</code> contextual component now. This component takes a block as a starting template for the user to see. It then puts that template into the <code>textarea</code>, and every time its value changes the template is recompiled and rerendered.</p>
119119

0 commit comments

Comments
 (0)