Feature #30986 » 0001-Add-toolbar-button-to-insert-wiki-macros-30986.patch
| app/assets/images/jstoolbar/braces.svg | ||
|---|---|---|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-braces"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 4a2 2 0 0 0 -2 2v3a2 3 0 0 1 -2 3a2 3 0 0 1 2 3v3a2 2 0 0 0 2 2" /><path d="M17 4a2 2 0 0 1 2 2v3a2 3 0 0 0 2 3a2 3 0 0 0 -2 3v3a2 2 0 0 1 -2 2" /></svg>
|
||
| app/assets/stylesheets/jstoolbar.css | ||
|---|---|---|
|
line-height: normal;
|
||
|
}
|
||
|
.jstMacroMenu {
|
||
|
max-inline-size: 360px;
|
||
|
}
|
||
|
.jstMacroMenu button.dropdown-item {
|
||
|
flex-direction: column;
|
||
|
align-items: flex-start;
|
||
|
gap: 2px;
|
||
|
}
|
||
|
.jstMacroMenu .macro-signature {
|
||
|
font-family: var(--fonts-monospace);
|
||
|
}
|
||
|
.jstMacroMenu .macro-args {
|
||
|
color: var(--oc-gray-7);
|
||
|
}
|
||
|
.jstMacroMenu .macro-description {
|
||
|
color: var(--color-text-muted);
|
||
|
font-size: 0.9em;
|
||
|
white-space: normal;
|
||
|
}
|
||
|
/* Buttons
|
||
|
-------------------------------------------------------- */
|
||
|
.jstb_strong {
|
||
| ... | ... | |
|
.jstb_precode {
|
||
|
background-image: url(/jstoolbar/code.svg);
|
||
|
}
|
||
|
.jstb_macro {
|
||
|
background-image: url(/jstoolbar/braces.svg);
|
||
|
}
|
||
|
.jstb_link {
|
||
|
background-image: url(/jstoolbar/wiki_link.svg);
|
||
|
}
|
||
| app/javascript/controllers/wiki_toolbar_controller.js | ||
|---|---|---|
|
this.syntax?.table?.(this, cols, rows)
|
||
|
}
|
||
|
insertMacro({ params: { name, args = true, block = false } }) {
|
||
|
if (block) {
|
||
|
const open = args ? `{{${name}()\n` : `{{${name}\n`
|
||
|
this.wrapLines(open, '\n}}')
|
||
|
} else if (args) {
|
||
|
this.wrap(`{{${name}(`, ')}}')
|
||
|
} else {
|
||
|
this.wrap(`{{${name}}}`, '')
|
||
|
}
|
||
|
}
|
||
|
help() {
|
||
|
window.open(this.helpUrlValue, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes')
|
||
|
}
|
||
| app/views/wiki_toolbar/_menus.html.erb | ||
|---|---|---|
|
<% languages = User.current.pref.toolbar_language_options.to_s.split(',') %>
|
||
|
<% cache ['wiki_toolbar_menus', languages] do %>
|
||
|
<% macros = Redmine::WikiToolbar.macros %>
|
||
|
<% cache ['wiki_toolbar_menus', languages, macros] do %>
|
||
|
<template data-wiki-toolbar-menu="precode">
|
||
|
<ul class="jstMenu dropdown-content" role="menu" popover="auto"
|
||
|
data-action="click->wiki-toolbar#closeMenu keydown->wiki-toolbar#navigateMenu">
|
||
| ... | ... | |
|
<% end %>
|
||
|
</table>
|
||
|
</template>
|
||
|
<template data-wiki-toolbar-menu="macro">
|
||
|
<ul class="jstMenu jstMacroMenu dropdown-content" role="menu" popover="auto"
|
||
|
data-action="click->wiki-toolbar#closeMenu keydown->wiki-toolbar#navigateMenu">
|
||
|
<% macros.each do |macro| %>
|
||
|
<li role="none">
|
||
|
<%= tag.button type: 'button', class: 'dropdown-item', role: 'menuitem', tabindex: -1,
|
||
|
title: macro[:description].presence,
|
||
|
data: {
|
||
|
action: 'wiki-toolbar#insertMacro',
|
||
|
wiki_toolbar_name_param: macro[:name],
|
||
|
wiki_toolbar_args_param: macro[:has_args],
|
||
|
wiki_toolbar_block_param: macro[:block]
|
||
|
} do %>
|
||
|
<span class="macro-signature">
|
||
|
<strong class="macro-name"><%= macro[:name] %></strong><% if macro[:args].present? %><span class="macro-args">(<%= macro[:args] %>)</span><% end %>
|
||
|
</span>
|
||
|
<% if macro[:summary].present? %>
|
||
|
<span class="macro-description"><%= macro[:summary] %></span>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
</template>
|
||
|
<% end %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
label_wiki_toolbar_table: Table
|
||
|
label_wiki_toolbar_preformatted_text: Preformatted text
|
||
|
label_wiki_toolbar_preformatted_code: Highlighted code
|
||
|
label_wiki_toolbar_macro: Macro
|
||
|
label_wiki_toolbar_wiki_link: Link to a Wiki page
|
||
|
label_wiki_toolbar_image: Image
|
||
|
label_wiki_toolbar_help: Help
|
||
| lib/redmine/wiki_formatting/common_mark/helper.rb | ||
|---|---|---|
|
%w[h1 h2 h3],
|
||
|
%w[ul ol tl],
|
||
|
%w[bq unbq table pre precode],
|
||
|
%w[link img],
|
||
|
%w[macro link img],
|
||
|
%w[help]
|
||
|
].freeze
|
||
| lib/redmine/wiki_formatting/textile/helper.rb | ||
|---|---|---|
|
%w[h1 h2 h3],
|
||
|
%w[ul ol],
|
||
|
%w[bq unbq table pre precode],
|
||
|
%w[link img],
|
||
|
%w[macro link img],
|
||
|
%w[help]
|
||
|
].freeze
|
||
| lib/redmine/wiki_toolbar.rb | ||
|---|---|---|
|
'table' => :label_wiki_toolbar_table,
|
||
|
'pre' => :label_wiki_toolbar_preformatted_text,
|
||
|
'precode' => :label_wiki_toolbar_preformatted_code,
|
||
|
'macro' => :label_wiki_toolbar_macro,
|
||
|
'link' => :label_wiki_toolbar_wiki_link,
|
||
|
'img' => :label_wiki_toolbar_image,
|
||
|
'help' => :label_wiki_toolbar_help
|
||
|
}.freeze
|
||
|
SHORTCUTS = {'strong' => 'b', 'em' => 'i', 'ins' => 'u'}.freeze
|
||
|
MENUS = %w[table precode].freeze
|
||
|
MENUS = %w[table precode macro].freeze
|
||
|
TABLE_MENU_ROWS = 5
|
||
|
TABLE_MENU_COLS = 10
|
||
|
EXCLUDED_MACROS = %i[hello_world].freeze
|
||
|
MACRO_ARGS = {
|
||
|
:child_pages => 'page, depth=2, parent=1',
|
||
|
:collapse => 'title',
|
||
|
:include => 'page',
|
||
|
:issue => 'id, project=true, tracker=false, subject=false',
|
||
|
:macro_list => nil,
|
||
|
:recent_pages => 'days=7, limit=5, time=true, project=id, include_subprojects=true',
|
||
|
:thumbnail => 'filename, size=200, title=...'
|
||
|
}.freeze
|
||
|
# Returns the groups of buttons of the given text formatter, or nil if it
|
||
|
# does not use the toolbar
|
||
| ... | ... | |
|
MENUS
|
||
|
end
|
||
|
# Returns metadata for the wiki macros shown in the toolbar macro menu
|
||
|
def self.macros
|
||
|
Redmine::WikiFormatting::Macros.available_macros.
|
||
|
except(*EXCLUDED_MACROS).
|
||
|
sort_by {|name, _| name.to_s}.
|
||
|
map do |name, options|
|
||
|
description = options[:desc].to_s.strip
|
||
|
summary = description.lines.first.to_s.strip.sub(/\.\s.*/, '.')
|
||
|
method_name = "macro_#{name}"
|
||
|
block =
|
||
|
Redmine::WikiFormatting::Macros::Definitions.method_defined?(method_name) &&
|
||
|
Redmine::WikiFormatting::Macros::Definitions.instance_method(method_name).arity == 3
|
||
|
has_args = !MACRO_ARGS.key?(name) || !MACRO_ARGS[name].nil?
|
||
|
{
|
||
|
name: name.to_s,
|
||
|
args: MACRO_ARGS[name],
|
||
|
has_args: has_args,
|
||
|
block: block,
|
||
|
summary: summary,
|
||
|
description: description
|
||
|
}
|
||
|
end
|
||
|
end
|
||
|
# Returns the I18n key for the given button name
|
||
|
def self.label_for(name)
|
||
|
LABELS.fetch(name) {:"label_wiki_toolbar_#{name}"}
|
||
| test/helpers/wiki_toolbar_helper_test.rb | ||
|---|---|---|
|
html = render_erb("<%= wiki_textarea_tag('notes') %>")
|
||
|
assert_select_in html, 'div.jstElements' do
|
||
|
assert_select 'button', 19
|
||
|
assert_select 'button', 20
|
||
|
assert_select 'span.jstSpacer', 5
|
||
|
assert_select 'button.jstb_strong[title=?][data-action=?][data-wiki-toolbar-button-param=strong][data-wiki-toolbar-shortcut=b]:not([aria-haspopup])',
|
||
|
'Strong', 'wiki-toolbar#apply'
|
||
|
assert_select 'button.jstb_tl[data-wiki-toolbar-button-param=tl]'
|
||
|
assert_select 'button.jstb_table[aria-haspopup=true][aria-expanded=false][data-action=?][data-wiki-toolbar-menu-param=table]', 'wiki-toolbar#toggleMenu'
|
||
|
assert_select 'button.jstb_precode[aria-haspopup=true][aria-expanded=false][data-action=?][data-wiki-toolbar-menu-param=precode]', 'wiki-toolbar#toggleMenu'
|
||
|
assert_select 'button.jstb_macro[aria-haspopup=true][aria-expanded=false][data-action=?][data-wiki-toolbar-menu-param=macro]', 'wiki-toolbar#toggleMenu'
|
||
|
assert_select 'button.jstb_help[data-action=?]', 'wiki-toolbar#help'
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
assert_select_in html, 'div.jstBlock[data-wiki-toolbar-format-value=textile]'
|
||
|
assert_select_in html, 'div.jstElements' do
|
||
|
assert_select 'button', 18
|
||
|
assert_select 'button', 19
|
||
|
assert_select 'button.jstb_tl', 0
|
||
|
assert_select 'button.jstb_macro[data-wiki-toolbar-menu-param=macro]'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_macro_menu
|
||
|
with_settings :text_formatting => 'common_mark' do
|
||
|
html = render_erb("<%= wiki_textarea_tag('notes') %>")
|
||
|
assert_select_in html, 'template[data-wiki-toolbar-menu=macro] ul.jstMenu.jstMacroMenu.dropdown-content[role=menu][popover=auto]' do
|
||
|
assert_select 'button[data-wiki-toolbar-name-param=hello_world]', 0
|
||
|
assert_select 'button.dropdown-item[role=menuitem][tabindex="-1"][data-action=?]' \
|
||
|
'[data-wiki-toolbar-name-param=collapse][data-wiki-toolbar-args-param=true][data-wiki-toolbar-block-param=true][title]',
|
||
|
'wiki-toolbar#insertMacro' do
|
||
|
assert_select 'strong.macro-name', :text => 'collapse'
|
||
|
assert_select 'span.macro-args', :text => '(title)'
|
||
|
assert_select 'span.macro-description', :text => /collapsed block/
|
||
|
end
|
||
|
assert_select 'button.dropdown-item[data-wiki-toolbar-name-param=thumbnail]' \
|
||
|
'[data-wiki-toolbar-args-param=true][data-wiki-toolbar-block-param=false]' do
|
||
|
assert_select 'strong.macro-name', :text => 'thumbnail'
|
||
|
assert_select 'span.macro-args', :text => '(filename, size=200, title=...)'
|
||
|
end
|
||
|
assert_select 'button.dropdown-item[data-wiki-toolbar-name-param=macro_list]' \
|
||
|
'[data-wiki-toolbar-args-param=false][data-wiki-toolbar-block-param=false]' do
|
||
|
assert_select 'strong.macro-name', :text => 'macro_list'
|
||
|
assert_select 'span.macro-args', 0
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_plugin_can_add_custom_button_and_menu
|
||
|
with_settings :text_formatting => 'common_mark' do
|
||
|
buttons = Redmine::WikiToolbar.buttons('common_mark') + [%w[custom custom_menu]]
|
||
| test/system/wiki_toolbar_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_insert_macro
|
||
|
with_settings :text_formatting => 'common_mark' do
|
||
|
log_user('jsmith', 'jsmith')
|
||
|
visit '/projects/ecookbook/issues/new'
|
||
|
find('button.jstb_macro').click
|
||
|
within('ul.jstMacroMenu') {find('button[data-wiki-toolbar-name-param=include]').click}
|
||
|
assert_no_selector 'ul.jstMacroMenu'
|
||
|
assert_equal '{{include()}}', find('#issue_description').value
|
||
|
fill_in 'Description', :with => 'image.png'
|
||
|
select_text 'issue_description', 0, 9
|
||
|
find('button.jstb_macro').click
|
||
|
within('ul.jstMacroMenu') {find('button[data-wiki-toolbar-name-param=thumbnail]').click}
|
||
|
assert_equal '{{thumbnail(image.png)}}', find('#issue_description').value
|
||
|
fill_in 'Description', :with => ''
|
||
|
find('button.jstb_macro').click
|
||
|
within('ul.jstMacroMenu') {find('button[data-wiki-toolbar-name-param=macro_list]').click}
|
||
|
assert_equal '{{macro_list}}', find('#issue_description').value
|
||
|
fill_in 'Description', :with => 'details'
|
||
|
find('button.jstb_macro').click
|
||
|
within('ul.jstMacroMenu') {find('button[data-wiki-toolbar-name-param=collapse]').click}
|
||
|
assert_equal "{{collapse()\ndetails\n}}", find('#issue_description').value
|
||
|
end
|
||
|
end
|
||
|
def test_menus_should_close_with_escape_outside_click_or_toggle
|
||
|
log_user('jsmith', 'jsmith')
|
||
|
visit '/projects/ecookbook/issues/new'
|
||
- « Previous
- 1
- …
- 4
- 5
- 6
- Next »