Module: DsfrLinkHelper

Defined in:
app/helpers/dsfr_link_helper.rb

Constant Summary collapse

ICON_POSITIONS =
%w(left right).freeze
SIZES =
%w(sm md lg).freeze

Instance Method Summary collapse

Instance Method Details

Allows generating a link via plain parameters or the block-style form, just like Rails’s link_to. In addition, it accepts some custom options in extra_options (or options if using block-style) specific to the DSFR :

  • icon_left [String]: name of an icon to put on the left side

  • icon_right [String]: name of an icon to put on the right side

  • size [String]: one of the size available in SIZES.

Parameters:

  • name (String) (defaults to: nil)

    name of the link, same as link_to

  • options (Hash) (defaults to: nil)

    hash of options, same as link_to

  • extra_options (Hash) (defaults to: nil)

    hash of HTML options, same as link_to



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/dsfr_link_helper.rb', line 15

def dsfr_link_to(name = nil, options = nil, extra_options = nil, &block)
  extra_options = options if block_given?

  extra_options = extra_options
                  .then { |opts| add_default_class(opts) }
                  .then { |opts| add_icons(opts) }
                  .then { |opts| add_size(opts) }

  if block_given?
    link_to(name, extra_options, &block)
  else
    link_to(name, options, extra_options)
  end
end