world-flags 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -67,7 +67,7 @@ You can run the Rails generator `world_flags:init` in order to create a basic in
67
67
  You can setup WorldFlags to use a localization map for the labels of the flag icons
68
68
 
69
69
  ```ruby
70
- WorldFlags.languages = some_language_hash # fx loaded from a yaml file
70
+ WorldFlags.language_map = some_language_hash # fx loaded from a yaml file
71
71
  WorldFlags.countries = some_country_hash # fx loaded from a yaml file
72
72
  ```
73
73
 
@@ -96,9 +96,11 @@ def countries locale = :en
96
96
  JSON.parse File.read(path)
97
97
  end
98
98
 
99
- WorldFlags.countries = countries(:en)
99
+ WorldFlags.countries = Hashie::Mash.new countries
100
100
  ```
101
101
 
102
+ PS: See the json specs for examples.
103
+
102
104
  ### Languages mappings
103
105
 
104
106
  A country code to languages mappping file (also in json), can be found in `app/config/languages`.
@@ -109,20 +111,22 @@ def languages locale = :en
109
111
  JSON.parse File.read(path)
110
112
  end
111
113
 
112
- WorldFlags.languages = languages(:en)
114
+ WorldFlags.languages = Hashie::Mash.new languages
113
115
  ```
114
116
 
115
- Another approach more suited to adding single files is the following. Note that both `countrieds` and `languages` are instances of classes that inherit from the `Hashie::Mash` class (hash access via method missing).
117
+ PS: See the json specs for examples.
118
+
119
+ Another approach more suited to adding single files is the following. Note that both `countries` and `languages` are instances of classes that inherit from the `Hashie::Mash` class (hash access via method missing).
116
120
 
117
121
  ```
118
122
  WorldFlags.countries.en = countries_en
119
123
  WorldFlags.languages.en = languages_en
120
124
  ```
121
125
 
122
- You can set the active locales using:
126
+ You can set the available locales. By default they are the same as `I18n.available_locales`.
123
127
 
124
128
  ```ruby
125
- WorldFlags.active_locales = [:en, :da]
129
+ WorldFlags.available_locales = [:en, :da]
126
130
  ```
127
131
 
128
132
  ## Locale to country code
@@ -248,7 +252,6 @@ A small helper module is provided that can be inserted into a Controller or wher
248
252
  ```ruby
249
253
  class MainController < ApplicationController
250
254
  def home
251
- @json = Property.all.to_gmaps4rails
252
255
  @country_code = WorldFlags::Helper::Geo.ip_country_code
253
256
  end
254
257
  end
@@ -262,7 +265,6 @@ class MainController < ApplicationController
262
265
  include WorldFlags::Helper::Browser
263
266
 
264
267
  def home
265
- @json = Property.all.to_gmaps4rails
266
268
  @country_code = ip_country_code
267
269
  @locale = browser_locale
268
270
  end
@@ -305,16 +307,7 @@ class MainController < ApplicationController
305
307
  end
306
308
  ```
307
309
 
308
- You can configure valid locales for use with WorldFlags in an initializer, fx `initializers/locales.rb` :
309
-
310
- ```ruby
311
- # fx [:da, :en] or even ['da', 'en']
312
- WorldFlags.valid_locales = my_valid_locales_list
313
- ```
314
-
315
- Note that if not set, this list is preconfigured to: `['en', 'de', 'es', 'ru']`
316
-
317
- Alternatively configure in your `application.rb` file:
310
+ You can define the available locales for your app in your `application.rb` file:
318
311
 
319
312
  ```ruby
320
313
  class Application < Rails::Application
@@ -322,6 +315,8 @@ class Application < Rails::Application
322
315
  config.i18n.available_locales = [:da, :sv, :no]
323
316
  ``
324
317
 
318
+ The perhaps sync i18n `I18n.available_locales = MyCool::Application.i18n.available_locales`
319
+
325
320
  Note: This approach in turn works well with the `i18n-docs` gem ;)
326
321
 
327
322
  ## Post flag selection
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -75,10 +75,10 @@
75
75
  "fm": "Federated States of Micronesia",
76
76
  "fo": "Faroe Islands",
77
77
  "fr": "France",
78
- "ga": "Clipperton Island",
79
- "gb": "Gabon",
80
- "gd": "United Kingdom",
81
- "ge": "Grenada",
78
+ "ga": "Gabon",
79
+ "gb": "United Kingdom",
80
+ "gd": "Grenada",
81
+ "ge": "Georgia",
82
82
  "gf": "French Guiana",
83
83
  "gg": "Guernsey",
84
84
  "gh": "Ghana",
@@ -54,7 +54,7 @@
54
54
  "cv": "Portuguese",
55
55
  "cw": ["Papiamentu", "Dutch"],
56
56
  "cx": "English",
57
- "cy": ["Greek", "Turkish"]
57
+ "cy": ["Greek", "Turkish"],
58
58
  "cz": "Czech",
59
59
  "de": "German",
60
60
  "dj": ["French", "Arabic"],
@@ -75,8 +75,8 @@
75
75
  "fm": "English",
76
76
  "fo": ["Faroese", "Danish"],
77
77
  "fr": "French",
78
- "ga": "English",
79
- "gb": "French",
78
+ "ga": "French",
79
+ "gb": "English",
80
80
  "gd": "English",
81
81
  "ge": "English",
82
82
  "gf": "French",
data/lib/world-flags.rb CHANGED
@@ -1,69 +1,25 @@
1
1
  require 'hashie'
2
- require "world_flags/core_ext"
3
- require "world_flags/helpers"
2
+ require 'world_flags/core_ext'
3
+ require 'world_flags/helpers'
4
4
 
5
5
  require 'world_flags/rails/engine' if defined?(::Rails::Engine)
6
6
 
7
- require "world_flags/languages"
8
- require "world_flags/countries"
9
-
10
- require "world_flags/lang_util"
11
- require "world_flags/country_util"
12
-
7
+ require 'world_flags/languages'
8
+ require 'world_flags/countries'
9
+ require 'world_flags/util'
13
10
 
14
11
  module WorldFlags
15
12
  class << self
16
- attr_accessor :auto_select, :raise_error, :default_code, :default_locale
13
+ include Util
17
14
 
18
- # TODO: Why both active and valid locales? Does this even make sense!?
19
15
  attr_writer :active_locales
20
-
21
- def active_locales
22
- @active_locales ||= I18n.available_locales unless I18n.available_locales.blank?
23
- @active_locales ||= [:en]
24
- end
25
-
26
- # for WorldFlags::Helper::Locale
27
- def valid_locales
28
- @valid_locales ||= ['en', 'de', 'es', 'ru']
29
- end
30
-
31
- def valid_locales= *list
32
- raise ArgumentError, "Must be a list of locales, was #{list}" if list.empty?
33
- @valid_locales ||= list.flatten
34
- end
35
-
36
- def raise_error?
37
- @raise_error
38
- end
39
-
40
- def raise_error!
41
- @raise_error = true
42
- end
43
-
44
- def raise_error_off!
45
- @raise_error = false
46
- end
47
-
48
- def auto_select?
49
- auto_select
50
- end
51
-
52
- def auto_select!
53
- @auto_select = true
54
- end
16
+ attr_writer :locale_flag_map
55
17
 
56
18
  def label code = :us, options = {:language => :en}
57
19
  locale = extract_locale!(options) || default_locale_used || :en
58
20
  options[:country] ? country_label(code, locale) : language_label(code, locale)
59
21
  end
60
22
 
61
- def extract_locale! options
62
- options[:country] ? options.delete(:country) : options.delete(:language)
63
- end
64
-
65
- # Locale translation helper macros
66
-
67
23
  def flag_code code = :us
68
24
  # ensure that 'en_US' becomes simply 'us'
69
25
  code = code.to_s.sub(/^\w+_/, '').downcase
@@ -73,14 +29,19 @@ module WorldFlags
73
29
  def locale code = :us
74
30
  flag_locale_map[code.to_sym] || code
75
31
  end
76
-
77
- attr_writer :locale_flag_map
78
-
32
+
79
33
  # override using fx 'locale_to_country_code.json' file
80
34
  def locale_flag_map
81
35
  @locale_flag_map ||= keys_to_sym(locale_flag_hash)
82
36
  end
83
37
 
38
+ # see core_ext
39
+ def flag_locale_map
40
+ locale_flag_map.hash_revert
41
+ end
42
+
43
+ protected
44
+
84
45
  def keys_to_sym hash
85
46
  hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
86
47
  end
@@ -95,21 +56,10 @@ module WorldFlags
95
56
  :ja => "jp",
96
57
  :uk => "ua"
97
58
  }
98
- end
59
+ end
99
60
 
100
- def flag_locale_map
101
- locale_flag_map.hash_revert
102
- end
103
-
104
- def default_code_used
105
- WorldFlags.default_code || :us
106
- end
107
-
108
- def default_locale_used
109
- WorldFlags.default_locale || I18n.locale
110
- end
111
-
112
- include WorldFlags::LangUtil
113
- include WorldFlags::CountryUtil
61
+ def extract_locale! options
62
+ options[:country] ? options.delete(:country) : options.delete(:language)
63
+ end
114
64
  end
115
65
  end
@@ -1,10 +1,10 @@
1
1
  module WorldFlags
2
2
  class Countries < Hashie::Mash
3
3
  def en
4
- @en ||= {
4
+ {
5
5
  :ar => 'Argentina',
6
6
  :br => 'Brazil',
7
- :gb => 'Great Britain',
7
+ :gb => 'United Kingdom',
8
8
  :us => 'United States',
9
9
  :es => 'Spain',
10
10
  :gr => 'Greece',
@@ -12,39 +12,37 @@ module WorldFlags
12
12
  :nl => 'Netherlands',
13
13
  :de => 'Germany',
14
14
  :dk => 'Denmark',
15
- :sv => 'Sweden',
15
+ :se => 'Sweden',
16
16
  :no => 'Norway',
17
17
  :fi => 'Finland'
18
18
  }
19
19
  end
20
20
 
21
21
  def da
22
- @da ||= {
22
+ {
23
23
  :gb => 'England',
24
24
  :us => 'USA',
25
25
  :es => 'Spanien',
26
26
  :de => 'Tyskland',
27
27
  :dk => 'Danmark',
28
- :sv => 'Sverige',
28
+ :se => 'Sverige',
29
29
  :no => 'Norge',
30
30
  }
31
31
  end
32
- alias_method :dk, :da
33
32
 
34
- def se
33
+ def sv
35
34
  {
36
35
  :gb => 'England',
37
36
  :us => 'USA',
38
37
  :es => 'Spanien',
39
38
  :de => 'Tyskland',
40
39
  :dk => 'Danmark',
41
- :sv => 'Sverige',
40
+ :se => 'Sverige',
42
41
  :no => 'Norge',
43
42
  }
44
43
  end
45
- alias_method :sv, :se
46
44
 
47
- def no
45
+ def nb
48
46
  {
49
47
  :gb => 'England',
50
48
  :us => 'USA',
@@ -55,6 +53,5 @@ module WorldFlags
55
53
  :no => 'Norge'
56
54
  }
57
55
  end
58
- alias_method :nb, :no
59
56
  end
60
57
  end
@@ -1,9 +1,9 @@
1
1
  module WorldFlags
2
2
  class Languages < Hashie::Mash
3
3
  def en
4
- @en ||= {
5
- :ar => 'Argentinian Spanish',
6
- :br => 'Brazilian Portuguese',
4
+ {
5
+ :ar => 'Spanish',
6
+ :br => 'Portuguese',
7
7
  :po => 'Portuguese',
8
8
  :gr => 'Greek',
9
9
  :gb => 'British English',
@@ -14,43 +14,37 @@ module WorldFlags
14
14
  :de => 'German',
15
15
  :dk => 'Danish',
16
16
  :se => 'Swedish',
17
- :sv => 'Swedish',
18
17
  :no => 'Norwegian',
19
- :nb => 'Norwegian',
20
18
  :fi => 'Finnish'
21
19
  }
22
20
  end
23
21
 
24
22
  def da
25
- @da ||= {
23
+ {
26
24
  :gb => 'Engelsk',
27
25
  :us => 'Engelsk',
28
26
  :es => 'Spansk',
29
27
  :de => 'Tysk',
30
28
  :dk => 'Dansk',
31
29
  :se => 'Svensk',
32
- :sv => 'Svensk',
33
30
  :no => 'Norsk'
34
31
  }
35
32
  end
36
- alias_method :dk, :da
37
33
 
38
- def se
39
- @se ||= {
34
+ def sv
35
+ {
40
36
  :gb => 'Engelska',
41
37
  :us => 'Engelska',
42
38
  :es => 'Spansk',
43
39
  :de => 'Tysk',
44
40
  :dk => 'Dansk',
45
41
  :se => 'Svenska',
46
- :sv => 'Svenska',
47
42
  :no => 'Norsk'
48
43
  }
49
44
  end
50
- alias_method :sv, :se
51
45
 
52
- def no
53
- @no ||= {
46
+ def nb
47
+ {
54
48
  :gb => 'Engelsk',
55
49
  :us => 'Engelsk',
56
50
  :es => 'Spansk',
@@ -61,6 +55,5 @@ module WorldFlags
61
55
  :no => 'Norsk'
62
56
  }
63
57
  end
64
- alias_method :nb, :no
65
58
  end
66
59
  end
@@ -0,0 +1,13 @@
1
+ require "world_flags/util/language"
2
+ require "world_flags/util/country"
3
+ require "world_flags/util/config"
4
+
5
+ module WorldFlags
6
+ module Util
7
+ def self.included base
8
+ base.send :include, Language
9
+ base.send :include, Country
10
+ base.send :include, Config
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ module WorldFlags
2
+ module Util
3
+ module Config
4
+ attr_accessor :auto_select, :raise_error
5
+ attr_accessor :default_code, :default_locale
6
+
7
+ def reset!
8
+ raise_error_off!
9
+ auto_select_off!
10
+
11
+ self.countries = nil
12
+ self.countries_map = nil
13
+
14
+ self.languages_map = nil
15
+ self.languages = nil
16
+ end
17
+
18
+ def default_code_used
19
+ WorldFlags.default_code || :us
20
+ end
21
+
22
+ def default_locale_used
23
+ WorldFlags.default_locale || I18n.locale
24
+ end
25
+
26
+ def available_locales
27
+ @available_locales ||= I18n.available_locales unless I18n.available_locales.blank?
28
+ @available_locales ||= default_locales
29
+ end
30
+
31
+ def available_locales= *list
32
+ raise ArgumentError, "Must be a list of locales, was #{list}" if list.empty?
33
+ @available_locales = list.flatten
34
+ end
35
+
36
+ def default_locales
37
+ ['en', 'fr', 'es', 'ru']
38
+ end
39
+
40
+ def auto_select?
41
+ auto_select
42
+ end
43
+
44
+ def auto_select!
45
+ @auto_select = true
46
+ end
47
+
48
+ def auto_select_off!
49
+ @auto_select = true
50
+ end
51
+
52
+ def raise_error?
53
+ @raise_error
54
+ end
55
+
56
+ def raise_error!
57
+ @raise_error = true
58
+ end
59
+
60
+ def raise_error_off!
61
+ @raise_error = false
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,50 @@
1
+ module WorldFlags
2
+ module Util
3
+ module Country
4
+ attr_writer :countries_map
5
+
6
+ def country_label code, locale
7
+ WorldFlags.country code, locale
8
+ end
9
+
10
+ def countries
11
+ @countries ||= Countries.new
12
+ end
13
+
14
+ def country code = :us, locale = :en
15
+ locale ||= default_locale_used
16
+
17
+ locale_countries_map = countries_map[locale] || countries_map[default_locale_used]
18
+ locale_countries_map = countries_map[:en] if locale_countries_map.blank?
19
+
20
+ raise "No country-locale map defined for locale: #{locale} or :en in #{countries.inspect}" if locale_countries_map.blank?
21
+
22
+ # raise("No country map defined for country code: #{code} in #{locale_countries_map[code]}")
23
+ locale_countries_map[code] ? locale_countries_map[code] : locale_countries_map[default_code_used]
24
+ rescue Exception => e
25
+ raise e if WorldFlags.raise_error?
26
+ "Undefined"
27
+ end
28
+
29
+ def countries= countries
30
+ raise ArgumentError, "Must be a hash, was: #{countries}" unless !countries || countries.kind_of?(Hash)
31
+ @countries = countries
32
+ end
33
+
34
+ def countries_map
35
+ @countries_map ||= begin
36
+ available_locales.inject({}) do |res, loc|
37
+ res[loc] = find_country_map(loc)
38
+ res
39
+ end
40
+ end
41
+ end
42
+
43
+ def find_country_map loc
44
+ countries.respond_to?(loc) ? countries.send(loc) : languages.send(locale(loc))
45
+ rescue
46
+ countries.send(default_locale_used)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ module WorldFlags
2
+ module Util
3
+ module Language
4
+ attr_writer :languages_map
5
+
6
+ def language_label code, locale
7
+ WorldFlags.language code, locale
8
+ end
9
+
10
+ def language code = :us, locale = :en
11
+ locale ||= default_locale_used
12
+
13
+ locale_languages_map = languages_map[locale] || languages_map[default_locale_used]
14
+ locale_languages_map = languages_map[:en] if locale_languages_map.blank?
15
+
16
+ raise "No language-locale map defined for locale: #{locale} or :en in #{languages.inspect}" if locale_languages_map.blank?
17
+
18
+ # 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
+ rescue Exception => e
21
+ raise e if WorldFlags.raise_error?
22
+ "Undefined"
23
+ end
24
+
25
+ def languages
26
+ @languages ||= Languages.new
27
+ end
28
+
29
+ def languages= languages
30
+ raise ArgumentError, "Must be a hash, was: #{languages}" unless !languages || languages.kind_of?(Hash)
31
+ @languages = languages
32
+ end
33
+
34
+ def languages_map
35
+ @languages_map ||= begin
36
+ available_locales.inject({}) do |res, loc|
37
+ res[loc] = find_language_map(loc)
38
+ res
39
+ end
40
+ end
41
+ end
42
+
43
+ def find_language_map loc
44
+ languages.respond_to?(loc) ? languages.send(loc) : languages.send(locale(loc))
45
+ rescue
46
+ languages.send(default_locale_used)
47
+ end
48
+ end
49
+ end
50
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,8 @@ require 'world-flags'
13
13
 
14
14
  # WorldFlags::Rails::Engine.add_view_ext
15
15
 
16
+ SPEC_DIR = File.dirname(__FILE__)
17
+
16
18
  module ControllerTestHelpers
17
19
 
18
20
  def self.included(base)
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldFlags::Helper::View do
4
+ include ControllerTestHelpers,
5
+ WorldFlags::Helper::View
6
+
7
+ def countries locale = :en
8
+ path = File.join(SPEC_DIR, "../config/countries/locale_countries.#{locale}.json")
9
+ JSON.parse File.read(path)
10
+ end
11
+
12
+ before do
13
+ WorldFlags.auto_select!
14
+ I18n.locale = :en
15
+ WorldFlags.available_locales = [:da, :sv, :nb, :en]
16
+ WorldFlags.reset!
17
+ WorldFlags.countries = Hashie::Mash.new countries
18
+ WorldFlags.raise_error!
19
+ end
20
+
21
+ it "should list flags using Array" do
22
+ output = flags_list 32 do
23
+ flags [:ar, :gb]
24
+ end
25
+ output.should == "<ul class=\"f32\"><li class=\"flag ar\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldFlags::Helper::View do
4
+ include ControllerTestHelpers,
5
+ WorldFlags::Helper::View
6
+
7
+ def languages locale = :en
8
+ path = File.join(SPEC_DIR, "../config/languages/locale_languages.#{locale}.json")
9
+ JSON.parse(File.read(path))
10
+ end
11
+
12
+ before do
13
+ WorldFlags.auto_select!
14
+ I18n.locale = :en
15
+ WorldFlags.available_locales = [:da, :sv, :nb, :en]
16
+ WorldFlags.reset!
17
+ WorldFlags.languages = Hashie::Mash.new languages
18
+ WorldFlags.raise_error!
19
+ end
20
+
21
+ it "should list flags using Array" do
22
+ output = flags_list 32 do
23
+ flags [:ar, :gb]
24
+ end
25
+ output.should == "<ul class=\"f32\"><li class=\"flag ar\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"English\" data-locale=\"gb\">&nbsp;</li></ul>"
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldFlags::Helper::View do
4
+ include ControllerTestHelpers,
5
+ WorldFlags::Helper::View
6
+
7
+ def locale_flag_map
8
+ path = File.join(SPEC_DIR, "../config/locale_map/locale_to_country_code.json")
9
+ JSON.parse(File.read(path))
10
+ end
11
+
12
+ before do
13
+ WorldFlags.auto_select!
14
+ I18n.locale = :en
15
+ WorldFlags.available_locales = [:da, :sv, :nb, :en]
16
+ WorldFlags.reset!
17
+ WorldFlags.locale_flag_map = Hashie::Mash.new locale_flag_map
18
+
19
+ WorldFlags.raise_error!
20
+ end
21
+
22
+ it "should list flags using Array" do
23
+ output = flags_list 32 do
24
+ flags [:ar, :gb]
25
+ end
26
+ output.should == "<ul class=\"f32\"><li class=\"flag ar\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
27
+ end
28
+ end
@@ -7,8 +7,8 @@ describe WorldFlags::Helper::View do
7
7
  before do
8
8
  WorldFlags.auto_select!
9
9
  I18n.locale = 'ar'
10
- WorldFlags.active_locales = [:da, :sv, :nb, :en, :ar]
11
-
10
+ WorldFlags.available_locales = [:da, :sv, :nb, :en]
11
+ WorldFlags.reset!
12
12
  WorldFlags.raise_error!
13
13
  end
14
14
 
@@ -39,26 +39,26 @@ describe WorldFlags::Helper::View do
39
39
  output = flags_list 32 do
40
40
  flags [:ar, :gb]
41
41
  end
42
- output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Argentinian Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"Great Britain\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
42
+ output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
43
43
  end
44
44
 
45
45
  it "should list flags using args" do
46
46
  output = flags_list 32 do
47
47
  flags :ar, :gb
48
48
  end
49
- output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Argentinian Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"Great Britain\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
49
+ output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
50
50
  end
51
51
 
52
52
  it "should list flags using args and :with_semi" do
53
53
  output = flags_list 32 do
54
54
  flags :ar, :gb, :with_semi => true
55
55
  end
56
- output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Argentinian Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb semi\" data-cc=\"gb\" data-country_name=\"Great Britain\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
56
+ output.should == "<ul class=\"f32\"><li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb semi\" data-cc=\"gb\" data-country_name=\"United Kingdom\" data-language_name=\"British English\" data-locale=\"gb\">&nbsp;</li></ul>"
57
57
  end
58
58
 
59
59
  it "should list flags" do
60
60
  output = flag_title :ar, 'Argentina'
61
- output.should == "<li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Argentinian Spanish\" data-locale=\"ar\" title=\"Argentina\">&nbsp;</li>"
61
+ output.should == "<li class=\"flag ar selected\" data-cc=\"ar\" data-country_name=\"Argentina\" data-language_name=\"Spanish\" data-locale=\"ar\" title=\"Argentina\">&nbsp;</li>"
62
62
  end
63
63
 
64
64
  describe 'Countries' do
@@ -71,7 +71,7 @@ describe WorldFlags::Helper::View do
71
71
  output = flags_list 32 do
72
72
  flags :dk, :se, :no, :with_semi => true, :country => :da
73
73
  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=\"USA\" 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>"
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>"
75
75
  end
76
76
  end
77
77
 
@@ -84,7 +84,7 @@ describe WorldFlags::Helper::View do
84
84
  output = flags_list 32 do
85
85
  flags :dk, :se, :no, :with_semi => true, :country => :da
86
86
  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=\"USA\" 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>"
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>"
88
88
  end
89
89
  end
90
90
 
data/world-flags.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "world-flags"
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
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"]
@@ -34,7 +34,6 @@ Gem::Specification.new do |s|
34
34
  "lib/world-flags.rb",
35
35
  "lib/world_flags/core_ext.rb",
36
36
  "lib/world_flags/countries.rb",
37
- "lib/world_flags/country_util.rb",
38
37
  "lib/world_flags/helper/all.rb",
39
38
  "lib/world_flags/helper/browser.rb",
40
39
  "lib/world_flags/helper/geo.rb",
@@ -42,9 +41,12 @@ Gem::Specification.new do |s|
42
41
  "lib/world_flags/helper/view.rb",
43
42
  "lib/world_flags/helper/view/util.rb",
44
43
  "lib/world_flags/helpers.rb",
45
- "lib/world_flags/lang_util.rb",
46
44
  "lib/world_flags/languages.rb",
47
45
  "lib/world_flags/rails/engine.rb",
46
+ "lib/world_flags/util.rb",
47
+ "lib/world_flags/util/config.rb",
48
+ "lib/world_flags/util/country.rb",
49
+ "lib/world_flags/util/language.rb",
48
50
  "sandbox/country_codes_table.html",
49
51
  "sandbox/extract_codes.rb",
50
52
  "sandbox/languages_country_extract.rb",
@@ -53,8 +55,11 @@ Gem::Specification.new do |s|
53
55
  "sandbox/official_languages.txt",
54
56
  "spec/spec_helper.rb",
55
57
  "spec/world_flags/country_spec.rb",
58
+ "spec/world_flags/helper/locale_helper_spec.rb",
59
+ "spec/world_flags/json/json_countries_spec.rb",
60
+ "spec/world_flags/json/json_languages_spec.rb",
61
+ "spec/world_flags/json/locale_flag_spec.rb",
56
62
  "spec/world_flags/language_spec.rb",
57
- "spec/world_flags/locale_helper_spec.rb",
58
63
  "spec/world_flags/view_helper_spec.rb",
59
64
  "vendor/assets/images/flags/flags16.png",
60
65
  "vendor/assets/images/flags/flags16_semi.png",
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.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -132,7 +132,6 @@ files:
132
132
  - lib/world-flags.rb
133
133
  - lib/world_flags/core_ext.rb
134
134
  - lib/world_flags/countries.rb
135
- - lib/world_flags/country_util.rb
136
135
  - lib/world_flags/helper/all.rb
137
136
  - lib/world_flags/helper/browser.rb
138
137
  - lib/world_flags/helper/geo.rb
@@ -140,9 +139,12 @@ files:
140
139
  - lib/world_flags/helper/view.rb
141
140
  - lib/world_flags/helper/view/util.rb
142
141
  - lib/world_flags/helpers.rb
143
- - lib/world_flags/lang_util.rb
144
142
  - lib/world_flags/languages.rb
145
143
  - lib/world_flags/rails/engine.rb
144
+ - lib/world_flags/util.rb
145
+ - lib/world_flags/util/config.rb
146
+ - lib/world_flags/util/country.rb
147
+ - lib/world_flags/util/language.rb
146
148
  - sandbox/country_codes_table.html
147
149
  - sandbox/extract_codes.rb
148
150
  - sandbox/languages_country_extract.rb
@@ -151,8 +153,11 @@ files:
151
153
  - sandbox/official_languages.txt
152
154
  - spec/spec_helper.rb
153
155
  - spec/world_flags/country_spec.rb
156
+ - spec/world_flags/helper/locale_helper_spec.rb
157
+ - spec/world_flags/json/json_countries_spec.rb
158
+ - spec/world_flags/json/json_languages_spec.rb
159
+ - spec/world_flags/json/locale_flag_spec.rb
154
160
  - spec/world_flags/language_spec.rb
155
- - spec/world_flags/locale_helper_spec.rb
156
161
  - spec/world_flags/view_helper_spec.rb
157
162
  - vendor/assets/images/flags/flags16.png
158
163
  - vendor/assets/images/flags/flags16_semi.png
@@ -189,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
194
  version: '0'
190
195
  segments:
191
196
  - 0
192
- hash: -1213500271519335978
197
+ hash: 240785203955185004
193
198
  required_rubygems_version: !ruby/object:Gem::Requirement
194
199
  none: false
195
200
  requirements:
@@ -1,46 +0,0 @@
1
- module WorldFlags
2
- module CountryUtil
3
- def country_label code, locale
4
- WorldFlags.country code, locale
5
- end
6
-
7
- def countries
8
- @countries ||= Countries.new
9
- end
10
-
11
- def country code = :us, locale = :en
12
- locale ||= default_locale_used
13
-
14
- locale_countries_map = countries_map[locale] || countries_map[default_locale_used]
15
- locale_countries_map = countries_map[:en] if locale_countries_map.blank?
16
-
17
- raise "No country-locale map defined for locale: #{locale} or :en in #{countries.inspect}" if locale_countries_map.blank?
18
-
19
- # raise("No country map defined for country code: #{code} in #{locale_countries_map[code]}")
20
- locale_countries_map[code] ? locale_countries_map[code] : locale_countries_map[default_code_used]
21
- rescue Exception => e
22
- raise e if WorldFlags.raise_error?
23
- "Undefined"
24
- end
25
-
26
- def countries= countries
27
- raise ArgumentError, "Must be a hash, was: #{countries}" unless countries.kind_of?(Hash)
28
- @countries = countries
29
- end
30
-
31
- def countries_map
32
- @countries_map ||= begin
33
- active_locales.inject({}) do |res, loc|
34
- res[loc] = find_country_map(loc)
35
- res
36
- end
37
- end
38
- end
39
-
40
- def find_country_map loc
41
- countries.respond_to?(loc) ? countries.send(loc) : languages.send(locale(loc))
42
- rescue
43
- countries.send(default_locale_used)
44
- end
45
- end
46
- end
@@ -1,46 +0,0 @@
1
- module WorldFlags
2
- module LangUtil
3
- def language_label code, locale
4
- WorldFlags.language code, locale
5
- end
6
-
7
- def language code = :us, locale = :en
8
- locale ||= default_locale_used
9
-
10
- locale_languages_map = languages_map[locale] || languages_map[default_locale_used]
11
- locale_languages_map = languages_map[:en] if locale_languages_map.blank?
12
-
13
- raise "No language-locale map defined for locale: #{locale} or :en in #{languages.inspect}" if locale_languages_map.blank?
14
-
15
- # raise("No language map defined for language code: #{code} in #{locale_languages_map[code]}")
16
- locale_languages_map[code] ? locale_languages_map[code] : locale_languages_map[default_code_used]
17
- rescue Exception => e
18
- raise e if WorldFlags.raise_error?
19
- "Undefined"
20
- end
21
-
22
- def languages
23
- @languages ||= Languages.new
24
- end
25
-
26
- def languages= languages
27
- raise ArgumentError, "Must be a hash, was: #{languages}" unless languages.kind_of?(Hash)
28
- @languages = languages
29
- end
30
-
31
- def languages_map
32
- @languages_map ||= begin
33
- active_locales.inject({}) do |res, loc|
34
- res[loc] = find_language_map(loc)
35
- res
36
- end
37
- end
38
- end
39
-
40
- def find_language_map loc
41
- languages.respond_to?(loc) ? languages.send(loc) : languages.send(locale(loc))
42
- rescue
43
- languages.send(default_locale_used)
44
- end
45
- end
46
- end