Module: FlagIconsRails::Rails::ViewHelpers

Defined in:
lib/flag-icons-rails/rails/helpers.rb

Instance Method Summary collapse

Instance Method Details

#flag_icon(country_code, squared: false, element: :span, **html_options) ⇒ String

Helper to render flag icon as single HTML element

Parameters:

  • country_code (Symbol|String) —

    ISO 3166-1 alpha-2 country code, see: https://www.iso.org/obp/ui/#search

  • squared (true, false) (defaults to: false) —

    Optional. It is used to determine if square or rectangular version of flag will be rendered, defaults to false

  • element (Symbol|String) (defaults to: :span) —

    Optional. HTML element to generate and apply classes to, defaults to :span

  • html_options (Hash) —

    Optional. HTML options applied to rendered span, defaults to {}

Returns:

  • (String) —

    element with requested HTML options to display country flag



17
18
19
20
21
# File 'lib/flag-icons-rails/rails/helpers.rb', line 17

def flag_icon(country_code, squared: false, element: :span, **html_options)
  html_options[:class] = flag_icon_content_class(country_code, squared, html_options[:class])

  (element, nil, html_options)
end