Skip to content

Commit b8e76fd

Browse files
authored
Merge pull request #9 from bit-docs/dont-expand-one-line
Don't collapse one line of code
2 parents 160a7f4 + 0167dcc commit b8e76fd

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

collapse-test.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Instead of connecting to a real backend API or web service, we’ll use [can-fixture fixtures]
2+
to “mock” an API. Whenever an [AJAX](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)
3+
request is made, the fixture will “capture” the request and instead respond with mock data.
4+
5+
> **Note:** if you open your browser’s Network panel, you will *not* see any network requests.
6+
> You can see the fixture requests and responses in your browser’s Console panel.
7+
8+
How fixtures work is outside the scope of this tutorial and not necessary to understand to continue,
9+
but you can learn more in the [can-fixture] documentation.
10+
11+
## Defining a custom element with CanJS
12+
13+
We mentioned above that CanJS helps you define custom elements. We call these [can-component components].
14+
15+
Add the following to the **JS** tab in your CodePen:
16+
17+
```js
18+
// Creates a mock backend with 3 todos
19+
import { todoFixture } from "//unpkg.com/can-demo-models@5";
20+
todoFixture(3);
21+
22+
import { Component } from "//unpkg.com/can@5/core.mjs";
23+
24+
Component.extend({
25+
tag: "todos-app",
26+
view: `
27+
<h1>Today’s to-dos</h1>
28+
`,
29+
ViewModel: {
30+
}
31+
});
32+
```
33+
<span line-highlight='2-7,9-14,only'/>

index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ var getConfig = function(lineString, lineCount) {
6666
return typeof val === 'number' && !isNaN(val);
6767
})
6868
;
69-
69+
7070
if (range[0] > current + padding) {
71-
collapse.push(current + '-' + (range[0] - 1 - padding));
71+
var collapseEnd = (range[0] - 1 - padding);
72+
if (collapseEnd !== current) {
73+
collapse.push(current + '-' + collapseEnd);
74+
}
7275
}
73-
76+
7477
current = (range[1] || range[0]) + padding + 1;
7578
}
7679

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"prismjs": "^1.11.0"
3131
},
3232
"devDependencies": {
33-
"bit-docs-generate-html": "^0.1.0",
33+
"bit-docs-generate-html": "^0.15.0",
3434
"connect": "^2.14.4",
3535
"mocha": "^2.5.3",
3636
"zombie": "^4.3.0"

test.js

+34
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,38 @@ describe("bit-docs-html-highlight-line", function() {
5858
}, done);
5959
}, done);
6060
});
61+
62+
it("dosen't show expand button for one line code", function(done) {
63+
this.timeout(60000);
64+
65+
var docMap = Promise.resolve({
66+
index: {
67+
name: "index",
68+
demo: "path/to/demo.html",
69+
body: fs.readFileSync(__dirname+"/collapse-test.md", "utf8")
70+
}
71+
});
72+
73+
generate(docMap, {
74+
html: {
75+
dependencies: {
76+
"bit-docs-html-highlight-line": __dirname
77+
}
78+
},
79+
dest: path.join(__dirname, "temp"),
80+
parent: "index",
81+
forceBuild: true,
82+
debug: true,
83+
minifyBuild: false
84+
}).then(function() {
85+
open("index.html",function(browser, close) {
86+
var doc = browser.window.document;
87+
var collapseCodes = doc.querySelectorAll('pre[data-collapse] code');
88+
assert.equal(collapseCodes.length, 0);
89+
close();
90+
done();
91+
}, done);
92+
}, done)
93+
94+
});
6195
});

0 commit comments

Comments
 (0)