Module: FlagIcon
- Defined in:
- lib/flag_icon.rb,
lib/flag_icon/rails.rb,
lib/flag_icon/helpers.rb,
lib/flag_icon/railtie.rb,
lib/flag_icon/rails/engine.rb,
lib/flag_icon/rails/version.rb
Defined Under Namespace
Modules: Countries, Rails Classes: Railtie
Class Method Summary collapse
-
.available_languages ⇒ Object
Define in your application_helper to override the available languages.
-
.country_icon(code, title: "Available in #{country_name(code)}") ⇒ Object
It returns HTML element with country icon and title.
-
.country_name(code) ⇒ Object
It returns the country name.
-
.grouped_select_language(popular: 'Popular', available: 'Available') ⇒ Object
It returns an hash of arrays that can be used in the select tag.
-
.language_flag(code) ⇒ Object
It returns the country iso code.
-
.language_icon(code, title: "Audio language - #{language_name(code)}") ⇒ Object
It returns HTML element with country icon and title.
-
.language_name(code) ⇒ Object
It returns the language name.
-
.popular_languages ⇒ Object
Define in your application_helper to override the popular languages Default: [[‘English’, :en], [‘Spanish’, :es]].
-
.select_language ⇒ Object
It returns an array that can be used in the select tag.
Class Method Details
.available_languages ⇒ Object
Define in your application_helper to override the available languages
87 88 89 |
# File 'lib/flag_icon/helpers.rb', line 87 def available_languages @languages ||= FlagIcon::Countries::LANGUAGES.keys end |
.country_icon(code, title: "Available in #{country_name(code)}") ⇒ Object
It returns HTML element with country icon and title
64 65 66 |
# File 'lib/flag_icon/helpers.rb', line 64 def country_icon(code, title: "Available in #{country_name(code)}") "<span class='flag-icon flag-icon-#{code}' title='#{title}'></span>" end |
.country_name(code) ⇒ Object
It returns the country name
16 17 18 |
# File 'lib/flag_icon/helpers.rb', line 16 def country_name(code) FlagIcon::Countries::NAMES[code.to_sym] end |
.grouped_select_language(popular: 'Popular', available: 'Available') ⇒ Object
It returns an hash of arrays that can be used in the select tag
43 44 45 46 47 48 |
# File 'lib/flag_icon/helpers.rb', line 43 def grouped_select_language(popular: 'Popular', available: 'Available') { popular => popular_languages, available => available_languages.map { |lang| [language_name(lang), lang] } } end |
.language_flag(code) ⇒ Object
It returns the country iso code
25 26 27 |
# File 'lib/flag_icon/helpers.rb', line 25 def language_flag(code) FlagIcon::Countries::LANGUAGE_FLAGS[code.to_sym] || 'xx' end |
.language_icon(code, title: "Audio language - #{language_name(code)}") ⇒ Object
It returns HTML element with country icon and title
55 56 57 |
# File 'lib/flag_icon/helpers.rb', line 55 def language_icon(code, title: "Audio language - #{language_name(code)}") "<span class='flag-icon flag-icon-#{language_flag(code)}' title='#{title}'></span>" end |
.language_name(code) ⇒ Object
It returns the language name
7 8 9 |
# File 'lib/flag_icon/helpers.rb', line 7 def language_name(code) FlagIcon::Countries::LANGUAGES[code.to_sym] end |
.popular_languages ⇒ Object
Define in your application_helper to override the popular languages Default: [[‘English’, :en], [‘Spanish’, :es]]
76 77 78 |
# File 'lib/flag_icon/helpers.rb', line 76 def popular_languages [['English', :en], ['Spanish', :es]] end |
.select_language ⇒ Object
It returns an array that can be used in the select tag
33 34 35 |
# File 'lib/flag_icon/helpers.rb', line 33 def select_language available_languages.map { |lang| [language_name(lang), lang] } end |