Sha256: efb0b2161ced9de769dda64ff7bf6f25d2b56841683d64827152c5e182d803d4
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
module WorldFlags module ViewHelper def self.flag_sizes [16, 32, 64] end # define more mappings by setting WorldFlags.locale_flag_map to a Hash map # http://en.wikipedia.org/wiki/ISO_639-1_language_matrix def flag_code code WorldFlags.flag_code code end def flags_list size = 16, &block raise "Missing block" unless block_given? raise "Supported sizes are only #{WorldFlags::ViewHelper.flag_sizes}" unless WorldFlags::ViewHelper.flag_sizes.include?(size.to_i) content = capture(&block) content_tag :ul, content, :class => "f#{size}" end alias_method :flag_list, :flags_list # http://en.wikipedia.org/wiki/ISO_639-1_language_matrix # should look up translation for each code def flags flags_arr, options = {} flags_arr.inject("") do |res, elem| case elem when Array code = elem.first name = elem.last when String, Symbol code = elem name = WorldFlags.label(code, options) else raise ArgumentError, "Bad argument: #{flags_arr}, must be Hash or Array" end res << flag(code, name, options) end.html_safe end def flags_title flags_arr, options = {} flags flags_arr, options.merge(:title => true) end def flag code, name, options = {} label = options[:content] ? name : ' ' extra_options = options[:title] ? {:title => name } : {} selected = flag_selected?(code, options) ? 'selected' : '' content_tag :li, label.html_safe, {:class => "flag #{code} #{selected}", :'data-country' => name, :'data-cc' => code}.merge(options[:html] || {}).merge(extra_options) end def flag_selected? code, options = {} selected = options[:selected] || options[code.to_sym] selected ||= (flag_code(I18n.locale.to_sym) == code.to_sym) if WorldFlags.auto_select? end def flag_title code, name, options = {} flag code, name, options.merge(:title => true) end def use_flags size = 16 stylesheet_link_tag "flags/flags#{size}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
world-flags-0.2.0 | lib/world_flags/view_helper.rb |