world-flags 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0
data/lib/world-flags.rb CHANGED
@@ -37,7 +37,7 @@ module WorldFlags
37
37
 
38
38
  # see core_ext
39
39
  def flag_locale_map
40
- locale_flag_map.hash_revert
40
+ @flag_locale_map ||= keys_to_sym(locale_flag_map.hash_revert)
41
41
  end
42
42
 
43
43
  protected
@@ -25,17 +25,19 @@ module WorldFlags
25
25
  end
26
26
 
27
27
  def self.flag_options code, title, name, options = {}
28
- locale = WorldFlags.locale(code)
28
+ locale = I18n.locale
29
29
  extra_options = title ? {:title => title } : {}
30
30
  selected = flag_selected?(code, options) ? ' selected' : ''
31
31
 
32
- language_name = WorldFlags.language(locale, code)
33
- country_name = WorldFlags.country(locale, code)
32
+ language_name = WorldFlags.language(code, locale)
33
+ country_name = WorldFlags.country(code, locale)
34
34
 
35
35
  # add semi class if not selected
36
36
  semi = (selected.blank? ? ' semi' : '') if options[:with_semi]
37
37
 
38
- {:class => "flag #{code}#{selected}#{semi}", :'data-country_name' => country_name, :'data-language_name' => language_name, :'data-cc' => code, :'data-locale' => locale}.merge(options[:html] || {}).merge(extra_options)
38
+ flag_locale = WorldFlags.locale(code)
39
+
40
+ {:class => "flag #{code}#{selected}#{semi}", :'data-country_name' => country_name, :'data-language_name' => language_name, :'data-cc' => code, :'data-locale' => flag_locale}.merge(options[:html] || {}).merge(extra_options)
39
41
  end
40
42
 
41
43
  def self.flag_selected? code, options = {}
@@ -13,6 +13,7 @@ module WorldFlags
13
13
 
14
14
  def country code = :us, locale = :en
15
15
  locale ||= default_locale_used
16
+ locale = WorldFlags.locale(locale).to_sym
16
17
 
17
18
  locale_countries_map = countries_map[locale] || countries_map[default_locale_used]
18
19
  locale_countries_map = countries_map[:en] if locale_countries_map.blank?
@@ -4,11 +4,12 @@ module WorldFlags
4
4
  attr_writer :languages_map
5
5
 
6
6
  def language_label code, locale
7
- WorldFlags.language code, locale
7
+ language code, locale
8
8
  end
9
9
 
10
10
  def language code = :us, locale = :en
11
11
  locale ||= default_locale_used
12
+ locale = WorldFlags.locale(locale).to_sym
12
13
 
13
14
  locale_languages_map = languages_map[locale] || languages_map[default_locale_used]
14
15
  locale_languages_map = languages_map[:en] if locale_languages_map.blank?
@@ -16,7 +17,7 @@ module WorldFlags
16
17
  raise "No language-locale map defined for locale: #{locale} or :en in #{languages.inspect}" if locale_languages_map.blank?
17
18
 
18
19
  # raise("No language map defined for language code: #{code} in #{locale_languages_map[code]}")
19
- locale_languages_map[code] ? locale_languages_map[code] : locale_languages_map[default_code_used]
20
+ locale_languages_map[code] ? locale_languages_map[code] : locale_languages_map[default_code_used]
20
21
  rescue Exception => e
21
22
  raise e if WorldFlags.raise_error?
22
23
  "Undefined"
@@ -12,6 +12,10 @@ describe WorldFlags::Helper::View do
12
12
  WorldFlags.raise_error!
13
13
  end
14
14
 
15
+ it 'should translate flag code to locale' do
16
+ WorldFlags.locale('dk').to_s.should == 'da'
17
+ end
18
+
15
19
  it "should be empty, with an empty block" do
16
20
  output = flags_list do
17
21
  end
@@ -71,7 +75,7 @@ describe WorldFlags::Helper::View do
71
75
  output = flags_list 32 do
72
76
  flags :dk, :se, :no, :with_semi => true, :country => :da
73
77
  end
74
- output.should == "<ul class=\"f32\"><li class=\"flag dk selected\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"dk\">&nbsp;</li><li class=\"flag se semi\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svensk\" data-locale=\"se\">&nbsp;</li><li class=\"flag no semi\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"no\">&nbsp;</li></ul>"
78
+ output.should == "<ul class=\"f32\"><li class=\"flag dk selected\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"da\">&nbsp;</li><li class=\"flag se semi\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svensk\" data-locale=\"sv\">&nbsp;</li><li class=\"flag no semi\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"nb\">&nbsp;</li></ul>"
75
79
  end
76
80
  end
77
81
 
@@ -84,7 +88,7 @@ describe WorldFlags::Helper::View do
84
88
  output = flags_list 32 do
85
89
  flags :dk, :se, :no, :with_semi => true, :country => :da
86
90
  end
87
- output.should == "<ul class=\"f32\"><li class=\"flag dk semi\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"dk\">&nbsp;</li><li class=\"flag se selected\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svenska\" data-locale=\"se\">&nbsp;</li><li class=\"flag no semi\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"no\">&nbsp;</li></ul>"
91
+ output.should == "<ul class=\"f32\"><li class=\"flag dk semi\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"da\">&nbsp;</li><li class=\"flag se selected\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svenska\" data-locale=\"sv\">&nbsp;</li><li class=\"flag no semi\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"nb\">&nbsp;</li></ul>"
88
92
  end
89
93
  end
90
94
 
@@ -97,7 +101,7 @@ describe WorldFlags::Helper::View do
97
101
  output = flags_list 32 do
98
102
  flags :dk, :se, :no, :with_semi => true, :country => :da
99
103
  end
100
- output.should == "<ul class=\"f32\"><li class=\"flag dk semi\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"dk\">&nbsp;</li><li class=\"flag se semi\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svensk\" data-locale=\"se\">&nbsp;</li><li class=\"flag no selected\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"no\">&nbsp;</li></ul>"
104
+ output.should == "<ul class=\"f32\"><li class=\"flag dk semi\" data-cc=\"dk\" data-country_name=\"Danmark\" data-language_name=\"Dansk\" data-locale=\"da\">&nbsp;</li><li class=\"flag se semi\" data-cc=\"se\" data-country_name=\"Sverige\" data-language_name=\"Svensk\" data-locale=\"sv\">&nbsp;</li><li class=\"flag no selected\" data-cc=\"no\" data-country_name=\"Norge\" data-language_name=\"Norsk\" data-locale=\"nb\">&nbsp;</li></ul>"
101
105
  end
102
106
  end
103
107
  end
data/world-flags.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "world-flags"
8
- s.version = "0.3.6"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = "2012-05-13"
12
+ s.date = "2012-05-14"
13
13
  s.description = "Use world flag icons in your Rails app"
14
14
  s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: world-flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  segments:
196
196
  - 0
197
- hash: -558446436876807119
197
+ hash: -1443906191312410055
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  none: false
200
200
  requirements: