views: add embed_wiki helper.

Also remove options to configure names of wiki notice pages. These names
generally don't need to be changed and we already hardcode links to wiki
pages in other places anyway.
This commit is contained in:
evazion
2020-01-27 13:04:28 -06:00
parent af044c45db
commit 588280c8cc
8 changed files with 11 additions and 36 deletions

View File

@@ -5,7 +5,6 @@ class UploadsController < ApplicationController
def new
@source = Sources::Strategies.find(params[:url], params[:ref]) if params[:url].present?
@upload_notice_wiki = WikiPage.titled(Danbooru.config.upload_notice_wiki_page).first
@upload, @remote_size = UploadService::ControllerHelper.prepare(
url: params[:url], ref: params[:ref]
)

View File

@@ -163,6 +163,12 @@ module ApplicationHelper
html.html_safe
end
def embed_wiki(title, **options)
wiki = WikiPage.find_by(title: title)
text = format_text(wiki&.body)
tag.div(text, class: "prose", **options)
end
def dtext_field(object, name, options = {})
options[:name] ||= name.capitalize
options[:input_id] ||= "#{object}_#{name}"

View File

@@ -1,7 +1,5 @@
<div class="report-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.report_notice_wiki_page).first.try(&:body)) %>
</div>
<%= embed_wiki("help:report_notice") %>
<%# XXX dtext_field expects there to be a `moderation_report` instance variable. %>
<% @moderation_report = moderation_report %>

View File

@@ -1,7 +1,5 @@
<div class="appeal-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.appeal_notice_wiki_page).first.try(&:body)) %>
</div>
<%= embed_wiki("help:appeal_notice") %>
<%# XXX dtext_field expects there to be a `post_appeal` instance variable. %>
<% @post_appeal = post_appeal %>

View File

@@ -1,7 +1,5 @@
<div class="flag-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
</div>
<%= embed_wiki("help:flag_notice") %>
<%# XXX dtext_field expects there to be a `post_flag` instance variable. %>
<% @post_flag = post_flag %>

View File

@@ -1,7 +1,5 @@
<div class="replace-image-dialog-body">
<div class="prose">
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
</div>
<%= embed_wiki("help:replacement_notice") %>
<%= edit_form_for(post_replacement, url: post_replacements_path(post_id: post_replacement.post_id), method: :post, remote: true) do |f| %>
<%= f.input :replacement_file, label: "File", as: :file %>

View File

@@ -3,9 +3,7 @@
<h1>Upload</h1>
<% if CurrentUser.can_upload? %>
<div id="upload-guide-notice" class="prose">
<%= format_text(@upload_notice_wiki.try(&:body)) %>
</div>
<%= embed_wiki("help:upload_notice", id: "upload-guide-notice") %>
<% unless CurrentUser.can_upload_free? %>
<p>Upload limit: <strong><%= CurrentUser.user.presenter.upload_limit(self) %></strong>.</p>