magic-localized_country_select 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
7
+ script: "bundle exec rake test"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rake'
4
4
  require 'rake/testtask'
5
- require 'rake/rdoctask'
5
+ require 'rdoc/task'
6
6
 
7
7
  #load File.join(File.dirname(__FILE__), 'lib', 'tasks', 'localized_country_select_tasks.rake')
8
8
 
@@ -36,7 +36,8 @@ begin
36
36
  gemspec.description = "Localized country select list"
37
37
  gemspec.email = "mail@magiclabs.de"
38
38
  gemspec.homepage = "https://github.com/magiclabs/localized_country_select"
39
- gemspec.authors = ["LIM SAS", "Damien MATHIEU", "Julien SANCHEZ", "Hervé GAUCHER"]
39
+ gemspec.authors = ["LIM SAS", "Damien MATHIEU", "Julien SANCHEZ", "Hervé GAUCHER", "Thomas von Deyen"]
40
+ gemspec.add_dependency "rails", "~> 3"
40
41
  gemspec.add_dependency "hpricot", "~> 0.8"
41
42
  end
42
43
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -23,23 +23,23 @@ load 'tasks/localized_country_select_tasks.rake'
23
23
  #
24
24
  module LocalizedCountrySelect
25
25
  class << self
26
+
26
27
  # Returns array with codes and localized country names (according to <tt>I18n.locale</tt>)
27
28
  # for <tt><option></tt> tags
28
- def localized_countries_array(options={})
29
- if(options[:description]==:abbreviated)
30
- I18n.translate(:countries).map { |key, value| [key.to_s.upcase] }.
31
- sort_by { |country| country.first }
29
+ def localized_countries_array(options = {})
30
+ if options[:description] == :abbreviated
31
+ I18n.translate(:countries).map { |key, value| [key.to_s.upcase] }.sort_by { |country| country.first }
32
32
  else
33
- I18n.translate(:countries).map { |key, value| [value, key.to_s.upcase] }.
34
- sort_by { |country| country.first }
33
+ I18n.translate(:countries).map { |key, value| [value, key.to_s.upcase] }.sort_by { |country| country.first }
35
34
  end
36
35
  end
36
+
37
37
  # Return array with codes and localized country names for array of country codes passed as argument
38
38
  # == Example
39
39
  # priority_countries_array([:TW, :CN])
40
40
  # # => [ ['Taiwan', 'TW'], ['China', 'CN'] ]
41
- def priority_countries_array(country_codes=[],options={})
42
- if(options[:description]==:abbreviated)
41
+ def priority_countries_array(country_codes = [], options = {})
42
+ if options[:description] == :abbreviated
43
43
  country_codes.map { |code| [code.to_s.upcase] }
44
44
  else
45
45
  countries = I18n.translate(:countries)
@@ -59,8 +59,7 @@ module ActionView
59
59
  # Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
60
60
  # TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
61
61
  def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
62
- InstanceTag.new(object, method, self, options.delete(:object)).
63
- to_localized_country_select_tag(priority_countries, options, html_options)
62
+ InstanceTag.new(object, method, self, options.delete(:object)).to_localized_country_select_tag(priority_countries, options, html_options)
64
63
  end
65
64
 
66
65
  # Return "named" select and option tags according to given arguments.
@@ -68,17 +67,17 @@ module ActionView
68
67
  # It behaves likes older object-binded brother +localized_country_select+ otherwise
69
68
  # TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
70
69
  def country_select_tag(name, selected_value = nil, priority_countries = nil, html_options = {})
71
- select_tag name.to_sym, country_options_for_select(selected_value, priority_countries), html_options.stringify_keys
70
+ select_tag(name.to_sym, country_options_for_select(selected_value, priority_countries), html_options.stringify_keys)
72
71
  end
73
72
 
74
73
  # Returns a string of option tags for countries according to locale. Supply the country code in upper-case ('US', 'DE')
75
74
  # as +selected+ to have it marked as the selected option tag.
76
75
  # Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
77
- def country_options_for_select(selected = nil, priority_countries = nil,options={})
78
- country_options = ""
79
- if priority_countries
80
- country_options += options_for_select(LocalizedCountrySelect::priority_countries_array(priority_countries,options), selected)
81
- country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
76
+ def country_options_for_select(selected = nil, priority_countries = nil, options = {})
77
+ country_options = "".html_safe
78
+ if priority_countries.present?
79
+ country_options += options_for_select(LocalizedCountrySelect::priority_countries_array(priority_countries, options), selected)
80
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
82
81
  end
83
82
  return country_options + options_for_select(LocalizedCountrySelect::localized_countries_array(options), selected)
84
83
  end
@@ -90,12 +89,7 @@ module ActionView
90
89
  html_options = html_options.stringify_keys
91
90
  add_default_name_and_id(html_options)
92
91
  value = value(object)
93
- content_tag("select",
94
- add_options(
95
- country_options_for_select(value, priority_countries,options),
96
- options, value
97
- ), html_options
98
- )
92
+ content_tag("select", add_options(country_options_for_select(value, priority_countries,options), options, value), html_options)
99
93
  end
100
94
  end
101
95
 
@@ -5,17 +5,19 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "magic-localized_country_select"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["LIM SAS", "Damien MATHIEU", "Julien SANCHEZ", "Herv\u{e9} GAUCHER"]
12
- s.date = "2012-01-19"
11
+ s.authors = ["LIM SAS", "Damien MATHIEU", "Julien SANCHEZ", "Herv\u{e9} GAUCHER", "Thomas von Deyen"]
12
+ s.date = "2012-03-08"
13
13
  s.description = "Localized country select list"
14
14
  s.email = "mail@magiclabs.de"
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
+ ".travis.yml",
20
+ "Gemfile",
19
21
  "MIT-LICENSE",
20
22
  "README.rdoc",
21
23
  "Rakefile",
@@ -32,18 +34,24 @@ Gem::Specification.new do |s|
32
34
  ]
33
35
  s.homepage = "https://github.com/magiclabs/localized_country_select"
34
36
  s.require_paths = ["lib"]
35
- s.rubygems_version = "1.8.10"
37
+ s.rubygems_version = "1.8.15"
36
38
  s.summary = "Localized country select list"
37
39
 
38
40
  if s.respond_to? :specification_version then
39
41
  s.specification_version = 3
40
42
 
41
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<magic-localized_country_select>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rails>, ["~> 3"])
42
46
  s.add_runtime_dependency(%q<hpricot>, ["~> 0.8"])
43
47
  else
48
+ s.add_dependency(%q<magic-localized_country_select>, [">= 0"])
49
+ s.add_dependency(%q<rails>, ["~> 3"])
44
50
  s.add_dependency(%q<hpricot>, ["~> 0.8"])
45
51
  end
46
52
  else
53
+ s.add_dependency(%q<magic-localized_country_select>, [">= 0"])
54
+ s.add_dependency(%q<rails>, ["~> 3"])
47
55
  s.add_dependency(%q<hpricot>, ["~> 0.8"])
48
56
  end
49
57
  end
@@ -1,23 +1,15 @@
1
- # coding: utf-8
2
- $KCODE = 'u'
1
+ # encoding: utf-8
3
2
 
4
3
  require 'test/unit'
5
4
 
6
5
  require 'rubygems'
7
6
  require 'active_support'
8
7
  require 'action_controller'
9
- # require 'action_controller/test_process'
10
8
  require 'action_view'
11
9
  require 'action_view/helpers'
12
10
  require 'action_view/helpers/tag_helper'
13
11
  require 'i18n'
14
12
 
15
- begin
16
- require 'redgreen'
17
- rescue LoadError
18
- puts "[!] Install redgreen gem for better test output ($ sudo gem install redgreen)"
19
- end unless ENV["TM_FILEPATH"]
20
-
21
13
  require 'localized_country_select'
22
14
 
23
15
  class LocalizedCountrySelectTest < Test::Unit::TestCase
@@ -27,12 +19,12 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
27
19
  include ActionView::Helpers::FormTagHelper
28
20
 
29
21
  def test_action_view_should_include_helper_for_object
30
- assert ActionView::Helpers::FormBuilder.instance_methods.include?('country_select') # WTF not working with 1.9
31
- assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?('country_select')
22
+ assert ActionView::Helpers::FormBuilder.instance_methods.include?(:country_select)
23
+ assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?(:country_select)
32
24
  end
33
25
 
34
26
  def test_action_view_should_include_helper_tag
35
- assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?('country_select_tag') # WTF not working with 1.9
27
+ assert ActionView::Helpers::FormOptionsHelper.instance_methods.include?(:country_select_tag)
36
28
  end
37
29
 
38
30
  def test_should_return_select_tag_with_proper_name_for_object
@@ -43,7 +35,6 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
43
35
  end
44
36
 
45
37
  def test_should_return_select_tag_with_proper_name
46
- # puts country_select_tag( "competition_submission[data][citizenship]", nil)
47
38
  assert country_select_tag( "competition_submission[data][citizenship]", nil) =~
48
39
  Regexp.new(
49
40
  Regexp.escape('<select id="competition_submission_data_citizenship" name="competition_submission[data][citizenship]">') ),
@@ -72,7 +63,6 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
72
63
 
73
64
  def test_localized_countries_array_returns_correctly
74
65
  assert_nothing_raised { LocalizedCountrySelect::localized_countries_array() }
75
- # puts LocalizedCountrySelect::localized_countries_array.inspect
76
66
  I18n.locale = 'en'
77
67
  assert_equal 243, LocalizedCountrySelect::localized_countries_array.size
78
68
  assert_equal 'Afghanistan', LocalizedCountrySelect::localized_countries_array.first[0]
@@ -103,14 +93,20 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
103
93
  assert_match Regexp.new(Regexp.escape(%Q{<option value="BT">Бутан</option>\n<option value="VU">Вануату</option>})), country_select(:user, :country)
104
94
  end
105
95
 
96
+ def test_country_options_for_select_string_is_html_safe
97
+ assert country_options_for_select.html_safe?, "country_options should be html_safe"
98
+ end
99
+
100
+ def test_country_options_for_select_string_with_priority_countries_is_html_safe
101
+ assert country_options_for_select(nil, ['DE']).html_safe?, "country_options with priority countries should be html_safe"
102
+ end
103
+
106
104
  # private
107
105
 
108
106
  def setup
109
107
  ['ru', 'en'].each do |locale|
110
- # I18n.load_translations( File.join(File.dirname(__FILE__), '..', 'locale', "#{locale}.rb") ) # <-- Old style! :)
111
108
  I18n.load_path += Dir[ File.join(File.dirname(__FILE__), '..', 'locale', "#{locale}.rb") ]
112
109
  end
113
- # I18n.locale = I18n.default_locale
114
110
  I18n.locale = 'en'
115
111
  end
116
112
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic-localized_country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,37 @@ authors:
9
9
  - Damien MATHIEU
10
10
  - Julien SANCHEZ
11
11
  - Hervé GAUCHER
12
+ - Thomas von Deyen
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2012-01-19 00:00:00.000000000 Z
16
+ date: 2012-03-08 00:00:00.000000000 Z
16
17
  dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: magic-localized_country_select
20
+ requirement: &70114907122320 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ! '>='
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: *70114907122320
29
+ - !ruby/object:Gem::Dependency
30
+ name: rails
31
+ requirement: &70114907121780 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: *70114907121780
17
40
  - !ruby/object:Gem::Dependency
18
41
  name: hpricot
19
- requirement: &70308313815240 !ruby/object:Gem::Requirement
42
+ requirement: &70114907121260 !ruby/object:Gem::Requirement
20
43
  none: false
21
44
  requirements:
22
45
  - - ~>
@@ -24,7 +47,7 @@ dependencies:
24
47
  version: '0.8'
25
48
  type: :runtime
26
49
  prerelease: false
27
- version_requirements: *70308313815240
50
+ version_requirements: *70114907121260
28
51
  description: Localized country select list
29
52
  email: mail@magiclabs.de
30
53
  executables: []
@@ -32,6 +55,8 @@ extensions: []
32
55
  extra_rdoc_files:
33
56
  - README.rdoc
34
57
  files:
58
+ - .travis.yml
59
+ - Gemfile
35
60
  - MIT-LICENSE
36
61
  - README.rdoc
37
62
  - Rakefile
@@ -65,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
90
  version: '0'
66
91
  requirements: []
67
92
  rubyforge_project:
68
- rubygems_version: 1.8.10
93
+ rubygems_version: 1.8.15
69
94
  signing_key:
70
95
  specification_version: 3
71
96
  summary: Localized country select list