From d07ebf9d4c5d8935abf2f4ded60b2a35f154ccb3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 14 Nov 2017 16:31:44 -0500 Subject: [PATCH] UX: Support for custom error pages and headers in plugins --- app/helpers/application_helper.rb | 5 ++++ app/views/application/_header.html.erb | 40 +++++++++++++------------ app/views/exceptions/not_found.html.erb | 2 +- app/views/layouts/application.html.erb | 6 ++-- app/views/layouts/no_ember.html.erb | 8 ++--- lib/discourse_plugin_registry.rb | 2 +- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 40bb8244436..63e873d380b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -356,6 +356,11 @@ module ApplicationHelper DiscoursePluginRegistry.build_html(name, controller) || "" end + # If there is plugin HTML return that, otherwise yield to the template + def replace_plugin_html(name) + build_plugin_html(name).presence || yield + end + def theme_lookup(name) lookup = Theme.lookup_field(theme_key, mobile_view? ? :mobile : :desktop, name) lookup.html_safe if lookup diff --git a/app/views/application/_header.html.erb b/app/views/application/_header.html.erb index a179dbc0c82..82305d1eba6 100644 --- a/app/views/application/_header.html.erb +++ b/app/views/application/_header.html.erb @@ -1,22 +1,24 @@ -
-
+ +<% end %> diff --git a/app/views/exceptions/not_found.html.erb b/app/views/exceptions/not_found.html.erb index 0e7e8057cf4..4d61d9d7bc3 100644 --- a/app/views/exceptions/not_found.html.erb +++ b/app/views/exceptions/not_found.html.erb @@ -1,6 +1,6 @@

<%= t 'page_not_found.title' %>

-<%= raw build_plugin_html 'server:not-found-before-topics' %> +<%= build_plugin_html 'server:not-found-before-topics' %> <% unless SiteSetting.login_required? && current_user.nil? %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 83c7bccf1cd..4eb4c3f275e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -56,7 +56,7 @@ <%= yield :head %> - <%= raw build_plugin_html 'server:before-head-close' %> + <%= build_plugin_html 'server:before-head-close' %> @@ -88,7 +88,7 @@ <%- unless customization_disabled? || loading_admin? %> <%= theme_lookup("header") %> - <%= raw build_plugin_html 'server:header' %> + <%= build_plugin_html 'server:header' %> <%- end %>
@@ -124,6 +124,6 @@ <%- unless customization_disabled? %> <%= raw theme_lookup("body_tag") %> <%- end %> - <%= raw build_plugin_html 'server:before-body-close' %> + <%= build_plugin_html 'server:before-body-close' %> diff --git a/app/views/layouts/no_ember.html.erb b/app/views/layouts/no_ember.html.erb index 1a1d8feeb12..eb8c6fabdf8 100644 --- a/app/views/layouts/no_ember.html.erb +++ b/app/views/layouts/no_ember.html.erb @@ -11,11 +11,11 @@ <%= theme_lookup("head_tag") %> <%= yield(:no_ember_head) %> - <%= raw build_plugin_html 'server:before-head-close' %> + <%= build_plugin_html 'server:before-head-close' %> class="<%= @custom_body_class %>"<% end %>> <%= theme_lookup("header") %> - <%= raw build_plugin_html 'server:header' %> + <%= build_plugin_html 'server:header' %>
<%= render partial: 'header' %>
@@ -23,7 +23,7 @@
<%= theme_lookup("footer") %> - <%= raw build_plugin_html 'no-client:footer' %> - <%= raw build_plugin_html 'server:before-body-close' %> + <%= build_plugin_html 'no-client:footer' %> + <%= build_plugin_html 'server:before-body-close' %> diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb index 52ca1df2eda..467e7fc42e8 100644 --- a/lib/discourse_plugin_registry.rb +++ b/lib/discourse_plugin_registry.rb @@ -143,7 +143,7 @@ class DiscoursePluginRegistry def self.build_html(name, ctx = nil) builders = html_builders[name] || [] - builders.map { |b| b.call(ctx) }.join("\n") + builders.map { |b| b.call(ctx) }.join("\n").html_safe end def javascripts