Extract current text formatting helper into separate helper

pull/6015/head
Oliver Günther 7 years ago
parent b155e1f199
commit ae6cda2340
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 8
      app/helpers/application_helper.rb
  2. 19
      app/helpers/text_formatting_helper.rb
  3. 1
      app/views/wiki/edit.html.erb
  4. 4
      lib/open_project/text_formatting/formatters/markdown/helper.rb
  5. 7
      lib/open_project/text_formatting/formatters/plain/helper.rb
  6. 4
      lib/open_project/text_formatting/formatters/textile/helper.rb

@ -42,9 +42,6 @@ module ApplicationHelper
include IconsHelper
include AdditionalUrlHelpers
extend Forwardable
def_delegators :wiki_helper, :text_formatting_js_includes, :wikitoolbar_for, :heads_for_wiki_formatter
# Return true if user is authorized for controller/action, otherwise false
def authorize_for(controller, action, project: @project)
User.current.allowed_to?({ controller: controller, action: action }, project)
@ -599,11 +596,6 @@ module ApplicationHelper
private
def wiki_helper
helper = OpenProject::TextFormatting::Formatters.helper_for(Setting.text_formatting)
extend helper
self
end
def link_to_content_update(text, url_params = {}, html_options = {})
link_to(text, url_params, html_options)

@ -27,8 +27,17 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
module PreviewsHelper
module TextFormattingHelper
extend Forwardable
def_delegators :current_formatting_helper,
:text_formatting_has_preview?,
:text_formatting_js_includes,
:wikitoolbar_for,
:heads_for_wiki_formatter
def preview_link(path, link_id, options = {})
return '' unless text_formatting_has_preview?
options = {
accesskey: accesskey(:preview),
id: link_id,
@ -42,4 +51,12 @@ module PreviewsHelper
l(:label_preview)
end
end
private
def current_formatting_helper
helper = OpenProject::TextFormatting::Formatters.helper_for(Setting.text_formatting)
extend helper
self
end
end

@ -48,6 +48,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= link_to t(:button_cancel),
{ controller: '/wiki', action: 'show', project_id: @project, id: @page },
class: 'button' %>
<%= preview_link preview_project_wiki_path(@project, @page), 'wiki_form-preview' %>
<% end %>
<div id="preview"></div>
<% content_for :header_tags do %>

@ -34,6 +34,10 @@ module OpenProject::TextFormatting::Formatters
javascript_include_tag 'vendor/ckeditor/openproject-ckeditor.js', async: true
end
def text_formatting_has_preview?
false
end
def wikitoolbar_for(field_id)
tag 'op-ckeditor-form', 'textarea-selector': "##{field_id}"
end

@ -33,6 +33,13 @@ module OpenProject::TextFormatting::Formatters
def wikitoolbar_for(_field_id)
end
def text_formatting_has_preview?
false
end
def text_formatting_js_includes
end
def heads_for_wiki_formatter
end

@ -34,6 +34,10 @@ module OpenProject::TextFormatting::Formatters
# TODO Nothing to do here yet, since the js_toolbar is still part of application
end
def text_formatting_has_preview?
true
end
def wikitoolbar_for(field_id)
heads_for_wiki_formatter
url = url_for(controller: '/help', action: 'wiki_syntax')

Loading…
Cancel
Save