move arbitrary html content out of noscript and into the preloadstore

This commit is contained in:
Régis Hanol 2013-12-17 18:25:27 +01:00
parent 1b6050bdb0
commit 4c6b535cc0
3 changed files with 11 additions and 12 deletions

View file

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

View file

@ -191,6 +191,7 @@ class ApplicationController < ActionController::Base
def preload_anonymous_data def preload_anonymous_data
store_preloaded("site", Site.cached_json(guardian)) store_preloaded("site", Site.cached_json(guardian))
store_preloaded("siteSettings", SiteSetting.client_settings_json) store_preloaded("siteSettings", SiteSetting.client_settings_json)
store_preloaded("htmlContent", html_content_json)
end end
def preload_current_user_data def preload_current_user_data
@ -199,6 +200,13 @@ class ApplicationController < ActionController::Base
store_preloaded("topicTrackingStates", MultiJson.dump(serializer)) store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
end end
def html_content_json
MultiJson.dump({
top: SiteContent.content_for(:top),
bottom: SiteContent.content_for(:bottom),
})
end
def render_json_error(obj) def render_json_error(obj)
if obj.present? if obj.present?
render json: MultiJson.dump(errors: obj.errors.full_messages), status: 422 render json: MultiJson.dump(errors: obj.errors.full_messages), status: 422

View file

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