File tree 4 files changed +74
-4
lines changed
4 files changed +74
-4
lines changed Original file line number Diff line number Diff line change
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 ' />
Original file line number Diff line number Diff line change @@ -66,11 +66,14 @@ var getConfig = function(lineString, lineCount) {
66
66
return typeof val === 'number' && ! isNaN ( val ) ;
67
67
} )
68
68
;
69
-
69
+
70
70
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
+ }
72
75
}
73
-
76
+
74
77
current = ( range [ 1 ] || range [ 0 ] ) + padding + 1 ;
75
78
}
76
79
Original file line number Diff line number Diff line change 30
30
"prismjs" : " ^1.11.0"
31
31
},
32
32
"devDependencies" : {
33
- "bit-docs-generate-html" : " ^0.1 .0" ,
33
+ "bit-docs-generate-html" : " ^0.15 .0" ,
34
34
"connect" : " ^2.14.4" ,
35
35
"mocha" : " ^2.5.3" ,
36
36
"zombie" : " ^4.3.0"
Original file line number Diff line number Diff line change @@ -58,4 +58,38 @@ describe("bit-docs-html-highlight-line", function() {
58
58
} , done ) ;
59
59
} , done ) ;
60
60
} ) ;
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
+ } ) ;
61
95
} ) ;
You can’t perform that action at this time.
0 commit comments