allow for arbitrary HTML at the top/bottom of every pages

This commit is contained in:
Régis Hanol 2013-11-18 17:13:24 +01:00
parent 639394e38a
commit dabdcf59c4
8 changed files with 44 additions and 7 deletions

View file

@ -1,4 +1,5 @@
Discourse.DiscourseLogoComponent = Ember.Component.extend({
linkUrl: function() {
return Discourse.getURL("/");
}.property(),

View file

@ -15,20 +15,22 @@ Discourse.StaticController = Discourse.Controller.extend({
}.property('path'),
loadPath: function(path) {
this.set('path', path);
var staticController = this;
this.set('content', null);
var self = this;
this.setProperties({
path: path,
content: null
});
// Load from <noscript> if we have it.
var $preloaded = $("noscript[data-path=\"" + path + "\"]");
if ($preloaded.length) {
var text = $preloaded.text();
text = text.match(/<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/);
text = text[1];
text = text.match(/<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/)[1];
this.set('content', text);
} else {
return Discourse.ajax(path, {dataType: 'html'}).then(function (result) {
staticController.set('content', result);
self.set('content', result);
});
}
}

View file

@ -1,3 +1,5 @@
{{view Discourse.HtmlView key="top"}}
<div class='list-controls'>
<div class="container">
@ -33,4 +35,4 @@
</div>
</div>
{{view Discourse.HtmlView key="bottom"}}

View file

@ -1,3 +1,5 @@
{{view Discourse.HtmlView key="top"}}
{{#if postStream.loaded}}
{{#if postStream.firstPostLoaded}}
@ -136,3 +138,4 @@
{{render topicAdminMenu content}}
{{/if}}
{{view Discourse.HtmlView key="bottom"}}

View file

@ -0,0 +1,15 @@
Discourse.HtmlView = Ember.View.extend({
render: function(buffer) {
var key = this.get("key"),
noscript = $("noscript").text();
if (noscript.length) {
var regexp = new RegExp("<!-- " + key + ": -->((?:.|[\\n\\r])*)<!-- :" + key + " -->"),
content = noscript.match(regexp)[1];
buffer.push(content);
}
}
});

View file

@ -20,6 +20,8 @@ class SiteContent < ActiveRecord::Base
add_content_type :login_required_welcome_message, default_18n_key: 'login_required.welcome_message'
add_content_type :privacy_policy, allow_blank: true
add_content_type :faq, allow_blank: true
add_content_type :top, allow_blank: true
add_content_type :bottom, allow_blank: true
def site_content_type

View file

@ -75,11 +75,17 @@
</div>
</div>
</header>
<!-- top: -->
<%= raw SiteContent.content_for(:top) %>
<!-- :top -->
<div id="main-outlet" class="container">
<!-- preload-content: -->
<%= yield %>
<!-- :preload-content -->
</div>
<!-- bottom: -->
<%= raw SiteContent.content_for(:bottom) %>
<!-- :bottom -->
</noscript>
<!-- Discourse Version: <%= Discourse::VERSION::STRING %> -->
<!-- Git Version: <%= Discourse.git_version %> -->

View file

@ -476,6 +476,12 @@ en:
login_required:
title: "Login Required: Homepage"
description: "The text displayed for unauthorized users when login is required on the site."
top:
title: "Top of the pages"
description: "HTML that will be added at the top of every pages (after the header, before the navigation or the topic title)"
bottom:
title: "Bottom of the pages"
description: "HTML that will be added at the bottom of every pages"
site_settings:
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"