world-flags 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -187,6 +187,22 @@ You must set up valid locales for use with WorldFlags in some initializer:
187
187
  # fx [:da, :en] or even ['da', 'en']
188
188
  WorldFlags::Locale.locales = my_valid_locales_list
189
189
 
190
+ h2. Post flag selection
191
+
192
+ Here an example of setting up a flag click handler in order to call the server with the country/locale/language selection of the flag.
193
+
194
+ $("li.flag").click(function() {
195
+ country = $(this).data('locale');
196
+
197
+ // full page reload
198
+ // window.location.href = "/locale/select/" + country;
199
+
200
+ // async post
201
+ $.post("/locale/select", { "country": country }, function(data) {
202
+ console.log(data);
203
+ });
204
+ });
205
+
190
206
  h2. Nice effects
191
207
 
192
208
  CSS config:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/world-flags.rb CHANGED
@@ -5,6 +5,14 @@ require 'world_flags/rails/engine' if defined?(::Rails::Engine)
5
5
  require "world_flags/languages"
6
6
  require "world_flags/countries"
7
7
 
8
+ class Hash
9
+ def hash_revert
10
+ r = Hash.new
11
+ each {|k,v| r[v] = k}
12
+ r
13
+ end
14
+ end
15
+
8
16
  module WorldFlags
9
17
  class << self
10
18
  attr_accessor :auto_select
@@ -30,16 +38,26 @@ module WorldFlags
30
38
  locale_flag_map[code.to_sym] || code
31
39
  end
32
40
 
41
+ def locale code
42
+ flag_locale_map[code.to_sym] || code
43
+ end
44
+
33
45
  attr_accessor :locale_flag_map
34
46
 
35
47
  # translate locales to flag code: ISO_3166-1_alpha-2
36
48
  def locale_flag_map
37
49
  @locale_map ||= {
38
- :en => :gb,
39
- :da => :dk
50
+ :en => :us,
51
+ :da => :dk,
52
+ :'en_UK' => :gb,
53
+ :'en_US' => :us
40
54
  }
41
55
  end
42
56
 
57
+ def flag_locale_map
58
+ locale_flag_map.hash_revert
59
+ end
60
+
43
61
  # Language helper macros
44
62
 
45
63
  def language locale = :en, code = :en
@@ -59,10 +59,10 @@ module WorldFlags
59
59
  else
60
60
  nil
61
61
  end
62
-
62
+ locale = WorldFlags.locale(code)
63
63
  extra_options = title ? {:title => title } : {}
64
64
  selected = flag_selected?(code, options) ? 'selected' : ''
65
- content_tag :li, label.html_safe, {:class => "flag #{code} #{selected}", :'data-country' => name, :'data-cc' => code}.merge(options[:html] || {}).merge(extra_options)
65
+ content_tag :li, label.html_safe, {:class => "flag #{code} #{selected}", :'data-country' => name, :'data-cc' => code, :'data-locale' => locale}.merge(options[:html] || {}).merge(extra_options)
66
66
  end
67
67
 
68
68
  def flag_selected? code, options = {}
@@ -29,35 +29,35 @@ describe WorldFlags::ViewHelper do
29
29
 
30
30
  it "should list flags using Hash arg" do
31
31
  output = flags_list 32 do
32
- flags :ar => 'Argentina', :gb => 'England'
32
+ flags :ar => 'Argentina', :gb => 'England', :dk => 'Denmark'
33
33
  end
34
- output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"England\">&nbsp;</li></ul>"
34
+ output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"England\" data-locale=\"en_UK\">&nbsp;</li><li class=\"flag dk \" data-cc=\"dk\" data-country=\"Denmark\" data-locale=\"da\">&nbsp;</li></ul>"
35
35
  end
36
36
 
37
37
  it "should list flags using Array" do
38
38
  output = flags_list 32 do
39
39
  flags [:ar, :gb]
40
40
  end
41
- output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentinian Spanish\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"British English\">&nbsp;</li></ul>"
41
+ output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentinian Spanish\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"British English\" data-locale=\"en_UK\">&nbsp;</li></ul>"
42
42
  end
43
43
 
44
44
  it "should list flags" do
45
45
  output = flag_title :ar, 'Argentina'
46
- output.should == "<li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" title=\"Argentina\">&nbsp;</li>"
46
+ output.should == "<li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" data-locale=\"ar\" title=\"Argentina\">&nbsp;</li>"
47
47
  end
48
48
 
49
49
  it "should list flags" do
50
50
  output = flags_list 32 do
51
51
  flags_title :ar => 'Argentina'
52
52
  end
53
- output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" title=\"Argentina\">&nbsp;</li></ul>"
53
+ output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" data-locale=\"ar\" title=\"Argentina\">&nbsp;</li></ul>"
54
54
  end
55
55
 
56
56
  it "should list flags combined" do
57
57
  output = flags_list 32 do
58
58
  [flags(:ar => 'Argentina', :gb => 'England'), flag(:br, 'Brazil')].join.html_safe
59
59
  end
60
- output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"England\">&nbsp;</li><li class=\"flag br \" data-cc=\"br\" data-country=\"Brazil\">&nbsp;</li></ul>"
60
+ output.should == "<ul class=\"f32\"><li class=\"flag ar \" data-cc=\"ar\" data-country=\"Argentina\" data-locale=\"ar\">&nbsp;</li><li class=\"flag gb \" data-cc=\"gb\" data-country=\"England\" data-locale=\"en_UK\">&nbsp;</li><li class=\"flag br \" data-cc=\"br\" data-country=\"Brazil\" data-locale=\"br\">&nbsp;</li></ul>"
61
61
  end
62
62
  end
63
63
 
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.2.2"
8
+ s.version = "0.2.3"
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-04-17"
12
+ s.date = "2012-04-18"
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.2.2
4
+ version: 0.2.3
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-04-17 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: 1820002462427377461
175
+ hash: 4049711410867555584
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements: