Project

General

Profile

Actions

Patch #31302

closed

Customizable wiki assets in plugin

Added by Masato NODA almost 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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.


Files

Actions #1

Updated by Go MAEDA almost 5 years 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?

Actions #2

Updated by Masato NODA almost 5 years 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.

Actions #3

Updated by Go MAEDA almost 5 years ago

  • Target version set to Candidate for next major release
Actions #4

Updated by Go MAEDA almost 5 years 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.

Actions #5

Updated by Seiei Miyagi almost 5 years 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?

Actions #6

Updated by Masato NODA almost 5 years 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.

Actions #7

Updated by vzvu 3k6k almost 5 years 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
Actions #8

Updated by Masato NODA almost 5 years ago

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

Actions #9

Updated by Go MAEDA almost 5 years ago

Masato NODA wrote:

It solved my problem.

Can we remove this issue from 4.1.0?

Actions #10

Updated by Masato NODA almost 5 years ago

Can we remove this issue from 4.1.0?

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

Actions #11

Updated by Go MAEDA almost 5 years 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.

Actions

Also available in: Atom PDF