File tree Expand file tree Collapse file tree 5 files changed +91
-7
lines changed
sandbox/app/components/simple-list
tests/acceptance/sandbox/api Expand file tree Collapse file tree 5 files changed +91
-7
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,13 @@ export default Route.extend({
16
16
|| module . get ( 'classes' ) . findBy ( 'id' , itemId )
17
17
|| module ;
18
18
} else {
19
+ // Create a regex that will match modules by either the path, or the
20
+ // pod-path (/component, /route, etc)
21
+ let type = path . match ( / ^ ( .* ) s \/ / ) [ 1 ] ;
22
+ let pathRegex = new RegExp ( `${ path } (/${ type } )?$` ) ;
23
+
19
24
let modules = this . store . peekAll ( 'module' ) ;
20
- let matches = modules . filter ( m => m . id . match ( path ) ) ;
25
+ let matches = modules . filter ( m => m . id . match ( pathRegex ) ) ;
21
26
let module = matches [ 0 ] ;
22
27
23
28
assert ( `no modules match the path '${ path } '` , matches . length > 0 ) ;
Original file line number Diff line number Diff line change @@ -154,26 +154,29 @@ const RESOLVED_TYPES = [
154
154
function generateResolvedTypeNavigationItems ( modules , type ) {
155
155
let items = modules . map ( m => {
156
156
let segments = m . file . split ( '/' ) ;
157
- let fileName = segments . pop ( ) ;
157
+ segments = segments . slice ( segments . indexOf ( type ) + 1 ) ;
158
158
159
- if ( type . match ( fileName ) ) {
160
- fileName = segments . pop ( ) ;
159
+ if ( type . match ( segments [ segments . length - 1 ] ) ) {
160
+ segments . pop ( ) ;
161
161
}
162
162
163
+ let path = segments . join ( '/' ) ;
163
164
let name ;
165
+
164
166
if ( [ 'components' , 'helpers' ] . includes ( type ) ) {
165
- name = `{{${ fileName } }}` ;
167
+ name = `{{${ path } }}` ;
166
168
} else {
169
+ let fileName = segments . pop ( ) ;
167
170
name = _ . upperFirst ( _ . camelCase ( fileName ) ) ;
168
171
}
169
172
170
173
return {
171
- path : `${ type } /${ fileName } ` ,
174
+ path : `${ type } /${ path } ` ,
172
175
name
173
176
} ;
174
177
} ) ;
175
178
176
- return _ . sortBy ( items , [ 'name ' ] ) ;
179
+ return _ . sortBy ( items , [ 'path ' ] ) ;
177
180
}
178
181
179
182
function generateModuleNavigationItems ( modules , type ) {
Original file line number Diff line number Diff line change
1
+ /** @documenter esdoc */
2
+
3
+ import Component from '@ember/component' ;
4
+ import { argument } from '@ember-decorators/argument' ;
5
+ import { type } from '@ember-decorators/argument/type' ;
6
+
7
+ /**
8
+ Pretty cool component, right?
9
+
10
+ To use it, you could enter the following in your template:
11
+
12
+ ```handlebars
13
+ {{#simple-list items=(arr 1 2 3) as |item|}}
14
+ {{#item as |value|}}
15
+ {{value}}
16
+ {{/item}}
17
+ {{/simple-list}}
18
+ ```
19
+
20
+ @yield {SimpleListItem} item
21
+ */
22
+ export default class SimpleList extends Component {
23
+ /**
24
+ The items for the list
25
+ */
26
+ @argument
27
+ @type ( 'object' )
28
+ items ;
29
+ }
Original file line number Diff line number Diff line change
1
+ /** @documenter esdoc */
2
+
3
+ import Component from '@ember/component' ;
4
+ import { argument } from '@ember-decorators/argument' ;
5
+ import { type } from '@ember-decorators/argument/type' ;
6
+
7
+ /**
8
+ Pretty cool component, right?
9
+
10
+ To use it, you could enter the following in your template:
11
+
12
+ ```handlebars
13
+ {{simple-list/item value=1}}
14
+ ```
15
+
16
+ @yield {object} value
17
+ */
18
+ export default class SimpleListItem extends Component {
19
+ /**
20
+ The count
21
+ */
22
+ @argument
23
+ @type ( 'object' )
24
+ value ;
25
+ }
Original file line number Diff line number Diff line change
1
+ import { module , test } from 'qunit' ;
2
+ import { setupApplicationTest } from 'ember-qunit' ;
3
+ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage' ;
4
+ import { currentURL , visit } from '@ember/test-helpers' ;
5
+
6
+ import modulePage from '../../../pages/api/module' ;
7
+
8
+ module ( 'Acceptance | API | components' , function ( hooks ) {
9
+ setupApplicationTest ( hooks ) ;
10
+ setupMirage ( hooks ) ;
11
+
12
+ test ( 'nested components work' , async function ( assert ) {
13
+ await visit ( '/sandbox' ) ;
14
+ await modulePage . navItems . findOne ( { text : `{{simple-list}}` } ) . click ( ) ;
15
+
16
+ assert . equal ( currentURL ( ) , `/sandbox/api/components/simple-list` , 'correct url' ) ;
17
+
18
+ await modulePage . navItems . findOne ( { text : `{{simple-list/item}}` } ) . click ( ) ;
19
+
20
+ assert . equal ( currentURL ( ) , `/sandbox/api/components/simple-list/item` , 'correct url' ) ;
21
+ } ) ;
22
+ } ) ;
You can’t perform that action at this time.
0 commit comments