Module: RedminefluxIconCompat::Helper

Defined in:
lib/redmineflux_icon_compat/helper.rb

Overview

View helper methods for rendering icon links that work on both Redmine 5 (legacy CSS icons) and Redmine 6 (SVG sprite icons).

Constant Summary collapse

RF_ICON_MAP =
{
  delete: { legacy: 'del', sprite: 'del' },
  add:    { legacy: 'add', sprite: 'add' },
  edit:   { legacy: 'edit', sprite: 'edit' },
  copy:   { legacy: 'copy', sprite: 'copy' },
  save:   { legacy: 'save', sprite: 'save' }
}.freeze

Instance Method Summary collapse

Instance Method Details

Builds a link with icon markup compatible with Redmine 5/6.

Parameters:

  • icon (Symbol, String)

    icon key (for example: :add, :edit, :delete)

  • label (String)

    human readable label text

  • href (String) (defaults to: '#')

    target URL

  • html_options (Hash) (defaults to: {})

    HTML options passed to link_to

Returns:

  • (String)

    HTML link markup



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/redmineflux_icon_compat/helper.rb', line 22

def rf_icon_link(icon, label, href = '#', html_options = {})
  icon_names = rf_icon_names(icon)
  options = (html_options || {}).dup
  use_sprite = rf_sprite_icons_available?
  options[:class] = rf_icon_classes(options[:class], icon_names[:legacy], use_sprite)

  content = if use_sprite
              rf_sprite_icon_markup(icon_names[:sprite], label)
            else
              label
            end

  link_to(content, href, options)
end

#rf_sprite_icons_available?Boolean

Detects whether SVG sprite rendering is currently available.

Returns:

  • (Boolean)


40
41
42
# File 'lib/redmineflux_icon_compat/helper.rb', line 40

def rf_sprite_icons_available?
  respond_to?(:sprite_icon, true) || rf_global_sprite_helper_available?
end