0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

adds code injection admin frontend implementation, handlebar helpers + settings

escaping handlebars
This commit is contained in:
Stefan Baumgartner 2014-07-31 21:36:20 +02:00 committed by Hannah Wolfe
parent f01fd0bbc0
commit 60effc1b51
10 changed files with 108 additions and 4 deletions

View file

@ -0,0 +1,19 @@
var SettingsCodeInjectionController = Ember.ObjectController.extend({
actions: {
save: function () {
var self = this;
return this.get('model').save().then(function (model) {
self.notifications.closePassive();
self.notifications.showSuccess('Settings successfully saved.');
return model;
}).catch(function (errors) {
self.notifications.closePassive();
self.notifications.showErrors(errors);
});
}
}
});
export default SettingsCodeInjectionController;

View file

@ -14,7 +14,9 @@ var Setting = DS.Model.extend(NProgressSaveMixin, ValidationEngine, {
forceI18n: DS.attr('boolean'),
permalinks: DS.attr('string'),
activeTheme: DS.attr('string'),
availableThemes: DS.attr()
availableThemes: DS.attr(),
ghost_head: DS.attr('string'),
ghost_foot: DS.attr('string')
});
export default Setting;

View file

@ -40,6 +40,7 @@ Router.map(function () {
this.route('about');
this.route('tags');
this.route('labs');
this.route('code-injection');
});
// Redirect debug to settings labs

View file

@ -0,0 +1,23 @@
import AuthenticatedRoute from 'ghost/routes/authenticated';
import loadingIndicator from 'ghost/mixins/loading-indicator';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import styleBody from 'ghost/mixins/style-body';
var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, {
classNames: ['settings-view-code'],
beforeModel: function () {
return this.currentUser()
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
model: function () {
return this.store.find('setting', {type: 'blog,theme'}).then(function (records) {
return records.get('firstObject');
});
}
});
export default SettingsCodeInjectionRoute;

View file

@ -11,6 +11,10 @@
{{gh-activating-list-item route="settings.general" title="General" classNames="settings-nav-general icon-settings"}}
{{/unless}}
{{#unless session.user.isEditor}}
{{gh-activating-list-item route="settings.code-injection" title="Code Injection" classNames="settings-nav-code"}}
{{/unless}}
{{! Whilst tag management is still in development only show tags button if there if tagsUI is true in config.js --}}
{{#if showTags}}
{{gh-activating-list-item route="settings.tags" title="Tags" classNames="settings-nav-tags icon-tag"}}

View file

@ -0,0 +1,31 @@
<header class="settings-view-header">
{{#link-to "settings" class="btn btn-default btn-back"}}Back{{/link-to}}
<h2 class="page-title">Code Injection</h2>
<section class="page-actions">
<button type="button" class="btn btn-blue" {{action "save"}}>Save</button>
</section>
</header>
<section class="content settings-code">
<form id="settings-code" novalidate="novalidate">
<fieldset>
<div class="form-group">
<p>
Ghost allows you to inject code into the top and bottom of your template files without editing them. This allows for quick modifications to insert useful things like tracking codes and meta data.
</p>
</div>
<div class="form-group">
<label for="blog-header">Blog Header</label>
<p>Code here will be injected to the \{{ghost_head}} helper at the top of your page</p>
{{textarea id="ghost-head" name="codeInjection[ghost_head]" type="text" value=ghost_head}}
</div>
<div class="form-group">
<label for="blog-header">Blog Footer</label>
<p>Code here will be injected to the \{{ghost_foot}} helper at the top of your page</p>
{{textarea id="blog-foot" name="codeInjection[ghost_foot]" type="text" value=ghost_foot}}
</div>
</fieldset>
</form>
</section>

View file

@ -0,0 +1,5 @@
import BaseView from 'ghost/views/settings/content-base';
var SettingsGeneralView = BaseView.extend();
export default SettingsGeneralView;

View file

@ -61,6 +61,12 @@
"matches": "(:id|:slug|:year|:month|:day)",
"notContains": "/ghost/"
}
},
"ghost_head": {
"defaultValue" : ""
},
"ghost_foot": {
"defaultValue" : ""
}
},
"theme": {

View file

@ -10,6 +10,7 @@ var hbs = require('express-hbs'),
_ = require('lodash'),
config = require('../config'),
filters = require('../filters'),
api = require('../api'),
utils = require('./utils'),
ghost_foot;
@ -23,8 +24,13 @@ ghost_foot = function (options) {
version: config.assetHash
}));
return filters.doFilter('ghost_foot', foot).then(function (foot) {
var footString = _.reduce(foot, function (memo, item) { return memo + '\n' + item; }, '\n');
return api.settings.read({key: 'ghost_foot'}).then(function (response) {
foot.push(response.settings[0].value);
return foot;
}).then(function (foot) {
return filters.doFilter('ghost_foot', foot);
}).then(function (foot) {
var footString = _.reduce(foot, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(footString.trim());
});
};

View file

@ -14,6 +14,7 @@ var hbs = require('express-hbs'),
config = require('../config'),
filters = require('../filters'),
api = require('../api'),
urlHelper = require('./url'),
meta_description = require('./meta_description'),
meta_title = require('./meta_title'),
@ -146,7 +147,7 @@ ghost_head = function (options) {
});
head.push('');
} else if (content !== null && content !== undefined) {
type = property.substring(0, 7) === 'twitter' ? 'name' : 'property';
type = property.substring(0, 7) === 'twitter' ? 'name' : 'property';
head.push('<meta ' + type + '="' + property + '" content="' + content + '" />');
}
});
@ -157,6 +158,12 @@ ghost_head = function (options) {
head.push('<meta name="generator" content="Ghost ' + trimmedVersion + '" />');
head.push('<link rel="alternate" type="application/rss+xml" title="' +
title + '" href="' + config.urlFor('rss', null, true) + '" />');
}).then(function () {
return api.settings.read({key: 'ghost_head'});
}).then(function (response) {
head.push(response.settings[0].value);
return head;
}).then(function (head) {
return filters.doFilter('ghost_head', head);
}).then(function (head) {
var headString = _.reduce(head, function (memo, item) { return memo + '\n ' + item; }, '');