Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Master #78

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 22 additions & 33 deletions addon/components/bread-crumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ const {
Component,
getWithDefault,
assert,
typeOf,
setProperties,
A: emberArray,
String: { classify }
} = Ember;

const {
bool,
readOnly
Expand All @@ -25,35 +24,28 @@ export default Component.extend({
reverse: false,
classNameBindings: ['breadCrumbClass'],
hasBlock: bool('template').readOnly(),
// for Ember 2.0+
// router: Ember.inject.service('-routing'),
// currentUrl: readOnly('router.router.url'),
// currentRouteName: readOnly('router.currentRouteName'),
currentUrl: readOnly('applicationRoute.router.url'),
currentRouteName: readOnly('applicationRoute.controller.currentRouteName'),

routeHierarchy: computed('currentUrl', 'currentRouteName', 'reverse', {
get() {
const currentRouteName = getWithDefault(this, 'currentRouteName', false);
routeHierarchy: computed('currentUrl', 'reverse', function() {
const currentRouteName = get(this, 'currentRouteName');

assert('[ember-crumbly] Could not find a curent route', currentRouteName);
assert('[ember-crumbly] Could not find a curent route', currentRouteName);

const routeNames = currentRouteName.split('.');
const filteredRouteNames = this._filterIndexAndLoadingRoutes(routeNames);
const crumbs = this._lookupBreadCrumb(routeNames, filteredRouteNames);
const routeNames = currentRouteName.split('.');
const filteredRouteNames = this._filterIndexAndLoadingRoutes(routeNames);
const crumbs = this._lookupBreadCrumb(routeNames, filteredRouteNames);

return get(this, 'reverse') ? crumbs.reverse() : crumbs;
}
return get(this, 'reverse') ? Ember.A(crumbs.reverse()) : Ember.A(crumbs);
}).readOnly(),

breadCrumbClass: computed('outputStyle', {
get() {
let className = 'breadcrumb';
const outputStyle = getWithDefault(this, 'outputStyle', '');
const lowerCaseOutputStyle = outputStyle.toLowerCase();

if (lowerCaseOutputStyle === 'foundation') {
className = 'breadcrumbs';
}

return className;
}
breadCrumbClass: computed('outputStyle', function() {
const outputStyle = getWithDefault(this, 'outputStyle', '');
return (outputStyle.match(/foundation/i)) ? 'breadcrumbs' : 'breadcrumb';
}).readOnly(),

_guessRoutePath(routeNames, name, index) {
Expand All @@ -69,7 +61,7 @@ export default Component.extend({
},

_filterIndexAndLoadingRoutes(routeNames) {
return routeNames.filter((name) => !(name === 'index' || name === 'loading') );
return routeNames.filter((name) => !(name.match(/^(index|loading)$/)));
},

_lookupRoute(routeName) {
Expand All @@ -79,29 +71,26 @@ export default Component.extend({
_lookupBreadCrumb(routeNames, filteredRouteNames) {
const defaultLinkable = get(this, 'linkable');
const pathLength = routeNames.length;
const breadCrumbs = filteredRouteNames.map((name, index) => {

return Ember.A(filteredRouteNames.map((name, index) => {
const path = this._guessRoutePath(routeNames, name, index);
const route = this._lookupRoute(path);
const crumbLinkable = (index === pathLength - 1) ? false : defaultLinkable;

assert(`[ember-crumbly] \`route:${path}\` was not found`, route);

let breadCrumb = getWithDefault(route, 'breadCrumb', {
title: classify(name)
});

if (typeOf(breadCrumb) === 'null') {
return;
} else {
if (breadCrumb) {
const crumbLinkable = (index === pathLength - 1) ? false : defaultLinkable;
setProperties(breadCrumb, {
path,
linkable: breadCrumb.hasOwnProperty('linkable') ? breadCrumb.linkable : crumbLinkable
});
return breadCrumb;
}

return breadCrumb;
});

return emberArray(breadCrumbs.filter((breadCrumb) => typeOf(breadCrumb) !== 'undefined'));
})).compact();
}
});
1 change: 1 addition & 0 deletions testem.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Chrome"
],
"launch_in_dev": [
"PhantomJS",
"Chrome"
]
}