Skip to content

Instantly share code, notes, and snippets.

View poteto's full-sized avatar
🥔
ポテト

lauren poteto

🥔
ポテト
View GitHub Profile
export default Component.extend({
layout,
tagName: 'ol',
linkable: true,
reverse: false,
classNameBindings: [ 'breadCrumbClass' ],
hasBlock: computed.bool('template').readOnly(),
currentRouteName: computed.readOnly('applicationController.currentRouteName'),
routeHierarchy: computed('currentRouteName', 'reverse', {
get() {
const currentRouteName = getWithDefault(this, 'currentRouteName', false);
assert('[ember-crumbly] Could not find a curent route', currentRouteName);
const routeNames = this._splitCurrentRouteName(currentRouteName);
const filteredRouteNames = this._filterIndexRoutes(routeNames);
const crumbs = this._lookupBreadCrumb(routeNames, filteredRouteNames);
_splitCurrentRouteName(currentRouteName) {
return currentRouteName.split('.');
},
_filterIndexRoutes(routeNames) {
return filter(routeNames, (name) => {
return name !== 'index';
});
},
_lookupBreadCrumb(routeNames, filteredRouteNames) {
const defaultLinkable = get(this, 'linkable');
const breadCrumbs = map(filteredRouteNames, (name, index) => {
const path = this._guessRoutePath(routeNames, name, index);
let breadCrumb = this._lookupRoute(path).getWithDefault('breadCrumb', undefined);
const breadCrumbType = typeOf(breadCrumb);
if (breadCrumbType === 'undefined') {
breadCrumb = {
path,
_guessRoutePath(routeNames, name, index) {
const routes = routeNames.slice(0, index + 1);
if (routes.length === 1) {
return `${name}.index`;
} else {
return routes.join('.');
}
},
_lookupRoute(routeName) {
const container = get(this, 'container');
const route = container.lookup(`route:${routeName}`);
assert(`[ember-crumbly] \`route:${routeName}\` was not found`, route);
return route;
},
let breadCrumb = this._lookupRoute(path).getWithDefault('breadCrumb', undefined);
const breadCrumbType = typeOf(breadCrumb);
if (breadCrumbType === 'undefined') {
breadCrumb = {
path,
linkable: defaultLinkable,
title: classify(name)
};
} else if (breadCrumbType === 'null') {
return emberArray(filter(breadCrumbs, (breadCrumb) => {
return typeOf(breadCrumb) !== 'undefined';
}));
{{#each routeHierarchy as |route|}}
<li class={{crumbClass}}>
{{#if hasBlock}}
{{#if route.linkable}}
{{#link-to route.path}}
{{yield this route}}
{{/link-to}}
{{else}}
{{yield this route}}
{{/if}}
import Ember from 'ember';
import { module } from 'qunit';
import startApp from 'livin/tests/helpers/start-app';
import OnboardPage from 'livin/tests/helpers/page-objects/onboard';
import { test } from 'qunit';
const { run } = Ember;
let application;
module('Acceptance | onboard', {