Remove inline script from default.hbs

no issue
- added config values as data attributes
- removed inline script
- removed current-user.js
This commit is contained in:
Sebastian Gierlinger 2014-07-21 20:00:54 +02:00
parent 29800356de
commit 05b3606fd3
7 changed files with 17 additions and 59 deletions

View File

@ -269,7 +269,7 @@ var path = require('path'),
files: [{
expand: true,
cwd: 'core/client/',
src: ['**/*.js'],
src: ['**/*.js', '!loader.js'],
dest: '.tmp/ember-transpiled/'
}]
}
@ -279,7 +279,7 @@ var path = require('path'),
// Compiles Ember es6 modules
concat_sourcemap: {
client: {
src: ['.tmp/ember-transpiled/**/*.js'],
src: ['.tmp/ember-transpiled/**/*.js', 'core/client/loader.js'],
dest: 'core/built/scripts/ghost-dev-ember.js',
options: {
sourcesContent: true

View File

@ -1,36 +0,0 @@
var currentUserInitializer = {
name: 'currentUser',
after: 'store',
initialize: function (container, application) {
var store = container.lookup('store:main'),
preloadedUser = application.get('user');
// If we don't have a user, don't do the injection
if (!preloadedUser) {
return;
}
// Push the preloaded user into the data store
store.pushPayload({
users: [preloadedUser]
});
// Signal to wait until the user is loaded before continuing.
application.deferReadiness();
// Find the user (which should be fast since we just preloaded it in the store)
store.find('user', preloadedUser.id).then(function (user) {
// Register the value for injection
application.register('user:current', user, { instantiate: false });
// Inject into the routes and controllers as the user property.
application.inject('route', 'user', 'user:current');
application.inject('controller', 'user', 'user:current');
application.advanceReadiness();
});
}
};
export default currentUserInitializer;

View File

@ -2,7 +2,10 @@ var ConfigInitializer = {
name: 'config',
initialize: function (container, application) {
application.register('ghost:config', application.get('config'), {instantiate: false});
var apps = $('body').data('apps'),
fileStorage = $('body').data('filestorage');
application.register('ghost:config', {apps: apps, fileStorage: fileStorage}, {instantiate: false});
application.inject('route', 'config', 'ghost:config');
application.inject('controller', 'config', 'ghost:config');

4
core/client/loader.js Normal file
View File

@ -0,0 +1,4 @@
// Loader to create the Ember.js application
/*global require */
window.App = require('ghost/app')['default'].create();

View File

@ -1,5 +1,4 @@
var config = require('../config'),
_ = require('lodash'),
var _ = require('lodash'),
when = require('when'),
api = require('../api'),
errors = require('../errors'),
@ -12,18 +11,9 @@ adminControllers = {
// Method: GET
'index': function (req, res) {
/*jslint unparam:true*/
var userData,
// config we need on the frontend
frontConfig = {
apps: config().apps,
fileStorage: config().fileStorage
};
function renderIndex() {
res.render('default', {
user: userData,
config: JSON.stringify(frontConfig)
});
res.render('default');
}
updateCheck().then(function () {

View File

@ -782,6 +782,10 @@ registerHelpers = function (adminHbs, assetHash) {
registerAdminHelper('ghost_script_tags', coreHelpers.ghost_script_tags);
registerAdminHelper('asset', coreHelpers.asset);
registerAdminHelper('apps', coreHelpers.apps);
registerAdminHelper('file_storage', coreHelpers.file_storage);
};
module.exports = coreHelpers;

View File

@ -31,16 +31,9 @@
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,700" />
<link rel="stylesheet" href="{{asset "css/ghost-ui.min.css" ghost="true"}}" />
</head>
<body class="{{bodyClass}}">
<body class="{{bodyClass}}" data-apps="{{apps}}" data-filestorage="{{file_storage}}">
{{{ghost_script_tags}}}
<script>
window.ENV = {
{{#user}}user: {{{this}}},{{/user}}
config: {{{config}}}
};
window.App = require('ghost/app')['default'].create(window.ENV);
</script>
</body>
</html>