UX: Support for custom error pages and headers in plugins

This commit is contained in:
Robin Ward 2017-11-14 16:31:44 -05:00
parent 1c56e1c063
commit d07ebf9d4c
6 changed files with 35 additions and 28 deletions

View File

@ -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

View File

@ -1,3 +1,4 @@
<%= replace_plugin_html('server:simple-header') do %>
<header class="d-header">
<div class="wrap">
<div class="contents">
@ -20,3 +21,4 @@
</div>
</div>
</header>
<% end %>

View File

@ -1,6 +1,6 @@
<h1 class="page-not-found"><%= t 'page_not_found.title' %></h1>
<%= raw build_plugin_html 'server:not-found-before-topics' %>
<%= build_plugin_html 'server:not-found-before-topics' %>
<% unless SiteSetting.login_required? && current_user.nil? %>
<div class="row page-not-found-topics">

View File

@ -56,7 +56,7 @@
<%= yield :head %>
<%= raw build_plugin_html 'server:before-head-close' %>
<%= build_plugin_html 'server:before-head-close' %>
</head>
<body class="<%= body_classes %>">
@ -88,7 +88,7 @@
<%- unless customization_disabled? || loading_admin? %>
<%= theme_lookup("header") %>
<%= raw build_plugin_html 'server:header' %>
<%= build_plugin_html 'server:header' %>
<%- end %>
<section id='main'>
@ -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' %>
</body>
</html>

View File

@ -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' %>
</head>
<body <% if @custom_body_class %>class="<%= @custom_body_class %>"<% end %>>
<%= theme_lookup("header") %>
<%= raw build_plugin_html 'server:header' %>
<%= build_plugin_html 'server:header' %>
<section id='main'>
<%= render partial: 'header' %>
<div id="main-outlet" class="<%= @container_class ? @container_class : 'wrap' %>">
@ -23,7 +23,7 @@
</div>
</section>
<%= 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' %>
</body>
</html>

View File

@ -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