use a helper instead of a view for custom HTML content

This commit is contained in:
Régis Hanol 2013-12-17 18:49:22 +01:00
parent 3cc634d37b
commit 94fda12795
5 changed files with 21 additions and 18 deletions

View File

@ -320,3 +320,18 @@ Handlebars.registerHelper('date', function(property, options) {
}
});
/**
Look for custom html content in the preload store.
@method customHTML
@for Handlebars
**/
Handlebars.registerHelper('customHTML', function(property, options) {
var html = PreloadStore.get("customHTML");
if (html && html[property] && html[property].length) {
return new Handlebars.SafeString(html[property]);
}
});

View File

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

View File

@ -1,4 +1,4 @@
{{view Discourse.HtmlView key="top"}}
{{customHTML "top"}}
{{#if postStream.loaded}}
@ -132,4 +132,4 @@
{{render topicAdminMenu content}}
{{/if}}
{{view Discourse.HtmlView key="bottom"}}
{{customHTML "bottom"}}

View File

@ -1,12 +0,0 @@
Discourse.HtmlView = Ember.View.extend({
render: function(buffer) {
var key = this.get("key"),
htmlContent = PreloadStore.get("htmlContent");
if (htmlContent && htmlContent[key] && htmlContent[key].length) {
buffer.push(htmlContent[key]);
}
}
});

View File

@ -191,7 +191,7 @@ class ApplicationController < ActionController::Base
def preload_anonymous_data
store_preloaded("site", Site.cached_json(guardian))
store_preloaded("siteSettings", SiteSetting.client_settings_json)
store_preloaded("htmlContent", html_content_json)
store_preloaded("customHTML", custom_html_json)
end
def preload_current_user_data
@ -200,7 +200,7 @@ class ApplicationController < ActionController::Base
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
end
def html_content_json
def custom_html_json
MultiJson.dump({
top: SiteContent.content_for(:top),
bottom: SiteContent.content_for(:bottom),