Skip to content

Commit

Permalink
Fix file paths displayed in the routes tab
Browse files Browse the repository at this point in the history
  • Loading branch information
omarhamdan committed Feb 25, 2018
1 parent 84645dd commit 43991ea
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 40 deletions.
106 changes: 68 additions & 38 deletions ember_debug/general-debug.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
/* eslint no-empty:0 */
import PortMixin from "ember-debug/mixins/port-mixin";
const Ember = window.Ember;
const { computed, Object: EmberObject, A } = Ember;
const { computed, Object: EmberObject } = Ember;
let { libraries } = Ember;
const { readOnly } = computed;

const GeneralDebug = EmberObject.extend(PortMixin, {
/**
* Class that handles gathering general information of the inspected app.
* ex:
* - Determines if the app was booted
* - Gathers the libraries. Found in the info tab of the inspector.
* - Gathers ember-cli configuration information from the meta tags.
*
* @module ember-debug/general-debug
*/
export default EmberObject.extend(PortMixin, {
/**
* Fetches the ember-cli configuration info and sets them on
* the `emberCliConfig` property.
*/
init() {
this._super(...arguments);
let found = findMetaTag('name', /environment$/);
if (found) {
try {
let config = JSON.parse(unescape(found.getAttribute('content')));
this.set('emberCliConfig', config);
} catch (e) {}
}
},

/**
* Passed on creation.
*
Expand All @@ -14,42 +38,38 @@ const GeneralDebug = EmberObject.extend(PortMixin, {
namespace: null,

/**
* Used by PortMixin.
* Used by the PortMixin
*
* @type {Port}
* @type {String}
*/
port: readOnly('namespace.port'),
portNamespace: 'general',

/**
* Used by the PortMixin
* Set on creation.
* Contains ember-cli configuration info.
*
* @type {String}
* Info used to determine the file paths of an ember-cli app.
*
* @return {Object}
* {String} environment ex: 'development'
* {String} modulePrefix ex: 'my-app'
* {String} podModulePrefix ex: 'my-app/pods'
* {Boolean} usePodsByDefault
*/
portNamespace: 'general',
emberCliConfig: null,

/**
* Used by PortMixin.
*
* @type {Port}
*/
port: readOnly('namespace.port'),

/**
* @type {Application}
*/
application: readOnly('namespace.application'),

// Keep an eye on https://github.com/ember-cli/ember-cli/issues/3045
emberCliConfig: computed(function() {
let config;
let metas = document.querySelectorAll('meta[name]');
for (let i = 0; i < metas.length; i++) {
let meta = metas[i];
let match = meta.getAttribute('name').match(/environment$/);
if (match) {
try {
/* global unescape */
config = JSON.parse(unescape(meta.attr('content')));
return false;
} catch (e) {}
}
}
return config;
}),

/**
* Sends a reply back indicating if the app has been booted.
*
Expand Down Expand Up @@ -84,24 +104,34 @@ const GeneralDebug = EmberObject.extend(PortMixin, {
* the info tab.
*/
getLibraries() {
// Ember has changed where the array of libraries is located.
// In older versions, `Ember.libraries` was the array itself,
// but now it's found under _registry.
if (libraries._registry) {
libraries = libraries._registry;
}

this.sendMessage('libraries', { libraries: arrayize(libraries) });
this.sendMessage('libraries', { libraries: libraries._registry });
},

/**
* Called from the inspector to refresh the inspected app.
* Used in case the inspector was opened late and therefore missed capturing
* all info.
*/
refresh() {
window.location.reload();
}
}
});

function arrayize(enumerable) {
return A(enumerable).map(item => item);
/**
* Finds a meta tag by searching through a certain meta attribute.
*
* @param {String} attribute
* @param {RegExp} regExp
* @return {Element}
*/
function findMetaTag(attribute, regExp = /.*/) {
let metas = document.querySelectorAll(`meta[${attribute}]`);
for (let i = 0; i < metas.length; i++) {
let match = metas[i].getAttribute(attribute).match(regExp);
if (match) {
return metas[i];
}
}
return null;
}

export default GeneralDebug;
4 changes: 2 additions & 2 deletions ember_debug/route-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PortMixin from 'ember-debug/mixins/port-mixin';

const Ember = window.Ember;
const { String: { classify, dasherize }, computed, observer, run: { later }, Object: EmberObject, getOwner } = Ember;
const { oneWay } = computed;
const { oneWay, readOnly } = computed;

const { hasOwnProperty } = Object.prototype;

Expand All @@ -25,7 +25,7 @@ export default EmberObject.extend(PortMixin, {

portNamespace: 'route',

emberCliConfig: oneWay('namespace.generalDebug.emberCliConfig').readOnly(),
emberCliConfig: readOnly('namespace.generalDebug.emberCliConfig'),

messages: {
getTree() {
Expand Down

0 comments on commit 43991ea

Please sign in to comment.