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({
1616 || module . get ( 'classes' ) . findBy ( 'id' , itemId )
1717 || module ;
1818 } 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+
1924 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 ) ) ;
2126 let module = matches [ 0 ] ;
2227
2328 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 = [
154154function generateResolvedTypeNavigationItems ( modules , type ) {
155155 let items = modules . map ( m => {
156156 let segments = m . file . split ( '/' ) ;
157- let fileName = segments . pop ( ) ;
157+ segments = segments . slice ( segments . indexOf ( type ) + 1 ) ;
158158
159- if ( type . match ( fileName ) ) {
160- fileName = segments . pop ( ) ;
159+ if ( type . match ( segments [ segments . length - 1 ] ) ) {
160+ segments . pop ( ) ;
161161 }
162162
163+ let path = segments . join ( '/' ) ;
163164 let name ;
165+
164166 if ( [ 'components' , 'helpers' ] . includes ( type ) ) {
165- name = `{{${ fileName } }}` ;
167+ name = `{{${ path } }}` ;
166168 } else {
169+ let fileName = segments . pop ( ) ;
167170 name = _ . upperFirst ( _ . camelCase ( fileName ) ) ;
168171 }
169172
170173 return {
171- path : `${ type } /${ fileName } ` ,
174+ path : `${ type } /${ path } ` ,
172175 name
173176 } ;
174177 } ) ;
175178
176- return _ . sortBy ( items , [ 'name ' ] ) ;
179+ return _ . sortBy ( items , [ 'path ' ] ) ;
177180}
178181
179182function 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