Patch #31302

Customizable wiki assets in plugin

Added by Masato NODA 2 months ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Plugin API
Target version:-

Description

Hi.

If we want to customize assets used in wiki from our plugin, we will override heads_for_wiki_formatter directly.

ex:
https://github.com/pinzolo/redmine_persist_wfmt/blob/master/lib/patches/helper/markdown_helper_patch.rb#L8
https://github.com/wate/graphviz/blob/master/lib/graphviz_helper_patch.rb#L19

But this means that only the last plugins loaded will be reflected.

So, I created a patch to separate the definitions of assets.
Please check this.

customizable-wiki-assets.patch Magnifier (3.22 KB) Masato NODA, 2019-05-05 14:57

customizable-wiki-assets-fix.patch Magnifier (3.22 KB) Masato NODA, 2019-05-05 18:38

History

#1 Updated by Go MAEDA 2 months ago

Please let me know the following points:

1. How do you rewrite your plugin if the patch is merged?
2. Sorry for the basic question but what does the word "renderigns" in the method name mean?

#2 Updated by Masato NODA 2 months ago

1. How do you rewrite your plugin if the patch is merged?

My plugin is redmine_persist_wfmt.
I will rewrite as follows.

module Pwfmt::MarkdownHelperPatch
  include Pwfmt::Helper

  def wikitoolbar_for(field_id, preview_url = preview_text_path)
    super(field_id, preview_url) + javascript_tag(pwfmt_select_script(field_id, 'markdown'))
  end

  def asset_renderigns_for_wiki_formatter
    base = super
    base[:script_format_adapter] = Proc.new { javascript_include_tag('toolbar', plugin: 'redmine_persist_wfmt') }
    base
  end
end

Redmine::WikiFormatting::Markdown::Helper.prepend(Pwfmt::MarkdownHelperPatch)

If this patch is merged, partial correction of wiki assets is possible.
For example, wiki toolbar can be modified by multiple plugins.
Current heads_for_wiki_formatter returns no value related rendering asset tag of wiki, it's a problem for plugin that extends wiki toolbar .

2. Sorry for the basic question but what does the word "renderigns" in the method name mean?

Sorry, "renderigns" is a miss spell, correctly "renderings".
I reattach a fixed patch.

#3 Updated by Go MAEDA 2 months ago

  • Target version set to Candidate for next major release

#4 Updated by Go MAEDA 2 months ago

  • Category changed from Wiki to Plugin API
  • Target version changed from Candidate for next major release to 4.1.0

Setting the target version to 4.1.0.

#5 Updated by Seiei Miyagi about 1 month ago

But this means that only the last plugins loaded will be reflected.

If `script_format_adapter` is updated by some plugins, will only the plugin loaded last be reflected?

#6 Updated by Masato NODA about 1 month ago

If `script_format_adapter` is updated by some plugins, will only the plugin loaded last be reflected?

Of course there may be so.
But for plugins that add buttons to the toolbar with additional scripts, this change allows them to co-exist.
Under the current, it can not even do it.

#7 Updated by vzvu 3k6k about 1 month ago

But for plugins that add buttons to the toolbar with additional scripts, this change allows them to co-exist.
Under the current, it can not even do it.

Maybe I miss the point, but in this case, can't we solve conflicts just by appending plugin's assets like this?

# ref. https://github.com/pinzolo/redmine_persist_wfmt/pull/15

module Pwfmt::MarkdownHelperPatch
  # snip

  def heads_for_wiki_formatter
    # loads all default assets and possibly other plugins' assets
    super

    unless @pwfmt_heads_for_wiki_formatter_included
      content_for :header_tags do
        # overwrites default toolbar buttons
        javascript_include_tag('toolbar', plugin: 'redmine_persist_wfmt')
      end
      @pwfmt_heads_for_wiki_formatter_included = true
    end
  end
end

#8 Updated by Masato NODA about 1 month ago

Thanks to your pull request.
I merged it.
It solved my problem.

#9 Updated by Go MAEDA about 1 month ago

Masato NODA wrote:

It solved my problem.

Can we remove this issue from 4.1.0?

#10 Updated by Masato NODA about 1 month ago

Can we remove this issue from 4.1.0?

Yes, OK.
If I wil have a problem, I will propose again.

#11 Updated by Go MAEDA about 1 month ago

  • Status changed from New to Closed
  • Target version deleted (4.1.0)

Masato NODA wrote:

Can we remove this issue from 4.1.0?

Yes, OK.
If I wil have a problem, I will propose again.

Thank you for the feedback. Closing.

Also available in: Atom PDF