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) || "" DiscoursePluginRegistry.build_html(name, controller) || ""
end 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) def theme_lookup(name)
lookup = Theme.lookup_field(theme_key, mobile_view? ? :mobile : :desktop, name) lookup = Theme.lookup_field(theme_key, mobile_view? ? :mobile : :desktop, name)
lookup.html_safe if lookup lookup.html_safe if lookup

View File

@ -1,22 +1,24 @@
<header class="d-header"> <%= replace_plugin_html('server:simple-header') do %>
<div class="wrap"> <header class="d-header">
<div class="contents"> <div class="wrap">
<div class="row"> <div class="contents">
<div class="title span13"> <div class="row">
<a href="<%= path "/" %>"> <div class="title span13">
<%- if application_logo_url.present? %> <a href="<%= path "/" %>">
<img src="<%= application_logo_url %>" alt="<%= SiteSetting.title %>" id="site-logo"> <%- if application_logo_url.present? %>
<%- else %> <img src="<%= application_logo_url %>" alt="<%= SiteSetting.title %>" id="site-logo">
<h2 id='site-text-logo'><%= SiteSetting.title %></h2> <%- else %>
<%- end %> <h2 id='site-text-logo'><%= SiteSetting.title %></h2>
</a> <%- end %>
</a>
</div>
<% unless current_user %>
<div class='panel clearfix'>
<a href="<%= path "/login"%>" class='btn btn-primary btn-small login-button'><i class="fa fa-user"></i> <%= I18n.t('log_in') %></a>
</div>
<% end %>
</div> </div>
<% unless current_user %>
<div class='panel clearfix'>
<a href="<%= path "/login"%>" class='btn btn-primary btn-small login-button'><i class="fa fa-user"></i> <%= I18n.t('log_in') %></a>
</div>
<% end %>
</div> </div>
</div> </div>
</div> </header>
</header> <% end %>

View File

@ -1,6 +1,6 @@
<h1 class="page-not-found"><%= t 'page_not_found.title' %></h1> <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? %> <% unless SiteSetting.login_required? && current_user.nil? %>
<div class="row page-not-found-topics"> <div class="row page-not-found-topics">

View File

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

View File

@ -11,11 +11,11 @@
<%= theme_lookup("head_tag") %> <%= theme_lookup("head_tag") %>
<%= yield(:no_ember_head) %> <%= yield(:no_ember_head) %>
<%= raw build_plugin_html 'server:before-head-close' %> <%= build_plugin_html 'server:before-head-close' %>
</head> </head>
<body <% if @custom_body_class %>class="<%= @custom_body_class %>"<% end %>> <body <% if @custom_body_class %>class="<%= @custom_body_class %>"<% end %>>
<%= theme_lookup("header") %> <%= theme_lookup("header") %>
<%= raw build_plugin_html 'server:header' %> <%= build_plugin_html 'server:header' %>
<section id='main'> <section id='main'>
<%= render partial: 'header' %> <%= render partial: 'header' %>
<div id="main-outlet" class="<%= @container_class ? @container_class : 'wrap' %>"> <div id="main-outlet" class="<%= @container_class ? @container_class : 'wrap' %>">
@ -23,7 +23,7 @@
</div> </div>
</section> </section>
<%= theme_lookup("footer") %> <%= theme_lookup("footer") %>
<%= raw build_plugin_html 'no-client:footer' %> <%= build_plugin_html 'no-client:footer' %>
<%= raw build_plugin_html 'server:before-body-close' %> <%= build_plugin_html 'server:before-body-close' %>
</body> </body>
</html> </html>

View File

@ -143,7 +143,7 @@ class DiscoursePluginRegistry
def self.build_html(name, ctx = nil) def self.build_html(name, ctx = nil)
builders = html_builders[name] || [] builders = html_builders[name] || []
builders.map { |b| b.call(ctx) }.join("\n") builders.map { |b| b.call(ctx) }.join("\n").html_safe
end end
def javascripts def javascripts