From 895fe26bc9d141c64730b3bfc5bc7cbfc6da99f1 Mon Sep 17 00:00:00 2001 From: Stefan Baumgartner Date: Thu, 31 Jul 2014 21:36:20 +0200 Subject: [PATCH 1/2] adds code injection admin frontend implementation, handlebar helpers + settings escaping handlebars --- .../controllers/settings/code-injection.js | 19 ++++++++++++ ghost/admin/models/setting.js | 4 ++- ghost/admin/router.js | 1 + ghost/admin/routes/settings/code-injection.js | 23 ++++++++++++++ ghost/admin/templates/settings.hbs | 4 +++ .../templates/settings/code-injection.hbs | 31 +++++++++++++++++++ ghost/admin/views/settings/code-injection.js | 5 +++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 ghost/admin/controllers/settings/code-injection.js create mode 100644 ghost/admin/routes/settings/code-injection.js create mode 100644 ghost/admin/templates/settings/code-injection.hbs create mode 100644 ghost/admin/views/settings/code-injection.js diff --git a/ghost/admin/controllers/settings/code-injection.js b/ghost/admin/controllers/settings/code-injection.js new file mode 100644 index 0000000000..95af5d5344 --- /dev/null +++ b/ghost/admin/controllers/settings/code-injection.js @@ -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; diff --git a/ghost/admin/models/setting.js b/ghost/admin/models/setting.js index 5da5b6384a..025a664051 100644 --- a/ghost/admin/models/setting.js +++ b/ghost/admin/models/setting.js @@ -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; diff --git a/ghost/admin/router.js b/ghost/admin/router.js index 4d1fa9b974..e2fc518007 100644 --- a/ghost/admin/router.js +++ b/ghost/admin/router.js @@ -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 diff --git a/ghost/admin/routes/settings/code-injection.js b/ghost/admin/routes/settings/code-injection.js new file mode 100644 index 0000000000..d2f8acf0c2 --- /dev/null +++ b/ghost/admin/routes/settings/code-injection.js @@ -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; diff --git a/ghost/admin/templates/settings.hbs b/ghost/admin/templates/settings.hbs index f8171aec4a..141a6fb526 100644 --- a/ghost/admin/templates/settings.hbs +++ b/ghost/admin/templates/settings.hbs @@ -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"}} diff --git a/ghost/admin/templates/settings/code-injection.hbs b/ghost/admin/templates/settings/code-injection.hbs new file mode 100644 index 0000000000..964c069ae5 --- /dev/null +++ b/ghost/admin/templates/settings/code-injection.hbs @@ -0,0 +1,31 @@ +
+ {{#link-to "settings" class="btn btn-default btn-back"}}Back{{/link-to}} +

Code Injection

+
+ +
+
+ +
+
+
+
+

+ 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. +

+
+ +
+ +

Code here will be injected to the \{{ghost_head}} helper at the top of your page

+ {{textarea id="ghost-head" name="codeInjection[ghost_head]" type="text" value=ghost_head}} +
+ +
+ +

Code here will be injected to the \{{ghost_foot}} helper at the top of your page

+ {{textarea id="blog-foot" name="codeInjection[ghost_foot]" type="text" value=ghost_foot}} +
+
+
+
diff --git a/ghost/admin/views/settings/code-injection.js b/ghost/admin/views/settings/code-injection.js new file mode 100644 index 0000000000..235261fac3 --- /dev/null +++ b/ghost/admin/views/settings/code-injection.js @@ -0,0 +1,5 @@ +import BaseView from 'ghost/views/settings/content-base'; + +var SettingsGeneralView = BaseView.extend(); + +export default SettingsGeneralView; From a7845cfd70f108846611862f7f0d7f1fb2f5878a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 28 Nov 2014 11:09:45 +0000 Subject: [PATCH 2/2] Code Injection - adds perms, shortcuts, icon, flag refs #1993 - adds ctrl/cmd+s for save - adds config flag - adds icon on settings page, puts items in the right order - sorts out permissions for all settings pages with consistent configuration --- ghost/admin/assets/sass/modules/icons.scss | 3 ++ ghost/admin/controllers/settings.js | 23 +++++++++++-- ghost/admin/routes/settings/code-injection.js | 16 +++++++++- ghost/admin/templates/settings.hbs | 32 +++++++++++-------- .../templates/settings/code-injection.hbs | 2 +- 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ghost/admin/assets/sass/modules/icons.scss b/ghost/admin/assets/sass/modules/icons.scss index cd8bdb00c0..fc0953ec5a 100755 --- a/ghost/admin/assets/sass/modules/icons.scss +++ b/ghost/admin/assets/sass/modules/icons.scss @@ -388,6 +388,9 @@ $i-compass: \e602; .icon-lightning:before { content: '#{$i-lightning}'; } +.icon-code:before { + content: '#{$i-code}'; +} .icon-atom:before { content: '#{$i-atom}'; } diff --git a/ghost/admin/controllers/settings.js b/ghost/admin/controllers/settings.js index d3e4277570..5ea159700d 100644 --- a/ghost/admin/controllers/settings.js +++ b/ghost/admin/controllers/settings.js @@ -1,6 +1,25 @@ var SettingsController = Ember.Controller.extend({ - showApps: Ember.computed.bool('config.apps'), - showTags: Ember.computed.bool('config.tagsUI') + showGeneral: Ember.computed('session.user.name', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; + }), + showUsers: Ember.computed('session.user.name', function () { + return this.get('session.user.isAuthor') ? false : true; + }), + showTags: Ember.computed('session.user.name', 'config.tagsUI', function () { + return this.get('session.user.isAuthor') || !this.get('config.tagsUI') ? false : true; + }), + + showCodeInjection: Ember.computed('session.user.name', 'config.codeInjectionUI', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('config.codeInjectionUI') ? false : true; + }), + + showLabs: Ember.computed('session.user.name', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; + }), + + showAbout: Ember.computed('session.user.name', function () { + return this.get('session.user.isAuthor') ? false : true; + }) }); export default SettingsController; diff --git a/ghost/admin/routes/settings/code-injection.js b/ghost/admin/routes/settings/code-injection.js index d2f8acf0c2..4c7742a70c 100644 --- a/ghost/admin/routes/settings/code-injection.js +++ b/ghost/admin/routes/settings/code-injection.js @@ -2,9 +2,15 @@ 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'; +import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; +import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; +var shortcuts = {}, + SettingsCodeInjectionRoute; -var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, { +shortcuts[ctrlOrCmd + '+s'] = {action: 'save'}; + +SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, ShortcutsRoute, { classNames: ['settings-view-code'], beforeModel: function () { @@ -17,6 +23,14 @@ var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingInd return this.store.find('setting', {type: 'blog,theme'}).then(function (records) { return records.get('firstObject'); }); + }, + + shortcuts: shortcuts, + + actions: { + save: function () { + this.get('controller').send('save'); + } } }); diff --git a/ghost/admin/templates/settings.hbs b/ghost/admin/templates/settings.hbs index 141a6fb526..55bc0e3c36 100644 --- a/ghost/admin/templates/settings.hbs +++ b/ghost/admin/templates/settings.hbs @@ -6,26 +6,30 @@
diff --git a/ghost/admin/templates/settings/code-injection.hbs b/ghost/admin/templates/settings/code-injection.hbs index 964c069ae5..10281de526 100644 --- a/ghost/admin/templates/settings/code-injection.hbs +++ b/ghost/admin/templates/settings/code-injection.hbs @@ -23,7 +23,7 @@
-

Code here will be injected to the \{{ghost_foot}} helper at the top of your page

+

Code here will be injected to the \{{ghost_foot}} helper at the bottom of your page

{{textarea id="blog-foot" name="codeInjection[ghost_foot]" type="text" value=ghost_foot}}