mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Add ghostPaths util and initializer
No Issue - Move the ghostPaths from base model to utils - Add initializer that injects it into every route, model and controller - Add a adminUrl and apiUrl helper method
This commit is contained in:
parent
11cf0ae125
commit
f795a907f0
4 changed files with 45 additions and 11 deletions
|
@ -4,6 +4,7 @@ import injectCurrentUser from 'ghost/initializers/current-user';
|
||||||
import injectCsrf from 'ghost/initializers/csrf';
|
import injectCsrf from 'ghost/initializers/csrf';
|
||||||
import {registerNotifications, injectNotifications} from 'ghost/initializers/notifications';
|
import {registerNotifications, injectNotifications} from 'ghost/initializers/notifications';
|
||||||
import registerTrailingLocationHistory from 'ghost/initializers/trailing-history';
|
import registerTrailingLocationHistory from 'ghost/initializers/trailing-history';
|
||||||
|
import injectGhostPaths from 'ghost/initializers/ghost-paths';
|
||||||
import 'ghost/utils/link-view';
|
import 'ghost/utils/link-view';
|
||||||
import 'ghost/utils/text-field';
|
import 'ghost/utils/text-field';
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ initFixtures();
|
||||||
|
|
||||||
App.initializer(injectCurrentUser);
|
App.initializer(injectCurrentUser);
|
||||||
App.initializer(injectCsrf);
|
App.initializer(injectCsrf);
|
||||||
|
App.initializer(injectGhostPaths);
|
||||||
App.initializer(registerNotifications);
|
App.initializer(registerNotifications);
|
||||||
App.initializer(injectNotifications);
|
App.initializer(injectNotifications);
|
||||||
App.initializer(registerTrailingLocationHistory);
|
App.initializer(registerTrailingLocationHistory);
|
||||||
|
|
13
core/client/initializers/ghost-paths.js
Normal file
13
core/client/initializers/ghost-paths.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ghost-paths',
|
||||||
|
|
||||||
|
initialize: function (container) {
|
||||||
|
container.register('ghost:paths', ghostPaths(), {instantiate: false});
|
||||||
|
|
||||||
|
container.injection('route', 'ghostPaths', 'ghost:paths');
|
||||||
|
container.injection('model', 'ghostPaths', 'ghost:paths');
|
||||||
|
container.injection('controller', 'ghostPaths', 'ghost:paths');
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,14 +1,4 @@
|
||||||
|
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||||
function ghostPaths() {
|
|
||||||
var path = window.location.pathname,
|
|
||||||
subdir = path.substr(0, path.search('/ghost/'));
|
|
||||||
|
|
||||||
return {
|
|
||||||
subdir: subdir,
|
|
||||||
adminRoot: subdir + '/ghost',
|
|
||||||
apiRoot: subdir + '/ghost/api/v0.1'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var BaseModel = Ember.Object.extend({
|
var BaseModel = Ember.Object.extend({
|
||||||
|
|
||||||
|
|
29
core/client/utils/ghost-paths.js
Normal file
29
core/client/utils/ghost-paths.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
var makeRoute = function (root, args) {
|
||||||
|
var parts = Array.prototype.slice.call(args, 0).join('/'),
|
||||||
|
route = [root, parts].join('/');
|
||||||
|
|
||||||
|
if (route.slice(-1) !== '/') {
|
||||||
|
route += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return route;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ghostPaths() {
|
||||||
|
var path = window.location.pathname,
|
||||||
|
subdir = path.substr(0, path.search('/ghost/'));
|
||||||
|
|
||||||
|
return {
|
||||||
|
subdir: subdir,
|
||||||
|
adminRoot: subdir + '/ghost',
|
||||||
|
apiRoot: subdir + '/ghost/api/v0.1',
|
||||||
|
|
||||||
|
adminUrl: function () {
|
||||||
|
return makeRoute(this.adminRoot, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
apiUrl: function () {
|
||||||
|
return makeRoute(this.apiRoot, arguments);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue