Sha256: 043fa0cd681094f171731b8ab241a729c977edb3303f9dd93e6bb4cf1d5290ce

Contents?: true

Size: 722 Bytes

Versions: 1

Compression:

Stored size: 722 Bytes

Contents

require 'action_view'

module CountryFlags
  module Helper

    include ActionView::Helpers::AssetUrlHelper
    include ActionView::Helpers::AssetTagHelper

    # returns path to flag image
    # use ISO-3166 Alpha 2 country codes
    # format can be :png or :gif
    def country_flag_path( country_code, format = :png )
      unless [:png, :gif].include?(format)
        raise(ArgumentError, 'format must be :png or :gif')
      end

      path = "country_flags/#{format}/#{country_code.downcase}.#{format}"
      image_path path
    end


    def country_flag( country_code, options = {} )
      options = {format: :png}.merge(options)

      image_tag country_flag_path(country_code, options[:format])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
country_flags-0.1.0 lib/country_flags/helper.rb