rails_country_select 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG +8 -0
- data/README.md +56 -7
- data/lib/rails_country_select.rb +13 -1
- data/lib/rails_country_select/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWM3MGFiZmM4Yjk3NGZkNTZmZTE4ZDdkYzljMDM1NTlkNmQzYzkwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzVmMGIzYzc1NWY2MmY4MDdhN2ExYmQwNTEwMTYzODExYzc2YjI4Mg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGEyNThiNDg2YjUwNDBmMWEzZGY2NjVlODkyYjVlZmQxODMyYzUyMDg1ZWYw
|
10
|
+
ZmUyM2JmMjkwNTFiMzMzOGQyMjdmOTE2YmY0ZGJjZDdlMDg3NGM3ZTA2ZmMx
|
11
|
+
MThhZTIxMzY4NmFmNjI1YmU4YzNjZGQ0YWIyYjIyMjMzM2RkOTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mjg5Y2MxZTYxYWExNjA0MTdlYzZiMWU3MzA4ZGIwNGFhZjI5YTk1ODI2ODI3
|
14
|
+
YzM2Y2IyZTQ3MWYyMzJkNTgwNjMwN2IxM2Y1NGU2Y2EyYzg5NmI0ZDgxYTE2
|
15
|
+
YjM3ZTE1NjU1NjM0Mjg0N2UxZjE1OWNjNWY5NjczMzAyODhlZjk=
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# RailsCountrySelect
|
2
2
|
This project is based on Rails 2 plugin created by LukeCarrier [rails-country-select](https://github.com/rderoldan1/rails-country-select/blob/master/lib/country_definitions.rb)
|
3
|
+
|
3
4
|
Select tag in order to choose a country in your forms, provides 4 options.
|
5
|
+
|
4
6
|
1. Country Name.
|
5
7
|
2. Cod
|
6
8
|
3. ISO cod 2 chars ('CO', 'AF', 'AX', 'AL')
|
7
9
|
4. ISO cod 3 chars ('COL', 'AFG', 'ALA', ALB')
|
8
10
|
|
11
|
+
Also includes a Helper method in order to get all country info.
|
12
|
+
|
9
13
|
## Installation
|
10
14
|
|
11
15
|
Add this line to your application's Gemfile:
|
@@ -25,7 +29,7 @@ Or install it yourself as:
|
|
25
29
|
### Basic
|
26
30
|
value : country cod number
|
27
31
|
text : country name
|
28
|
-
```
|
32
|
+
```rails
|
29
33
|
<%= form_for @user do |f| %>
|
30
34
|
<%= f.country_select :country %>
|
31
35
|
<% end %>
|
@@ -38,26 +42,71 @@ HTML generated
|
|
38
42
|
<option value="248">Albania</option>
|
39
43
|
<option value="8">Ã
land Islands</option>
|
40
44
|
<option value="12">Algeria</option>
|
41
|
-
|
45
|
+
```
|
42
46
|
|
43
47
|
### Advanced
|
44
|
-
values, keys : [:names, :nums, :alpha2s, :alpha3s]
|
45
|
-
selected : set default value
|
46
|
-
prompt : message
|
47
|
-
|
48
|
+
* values, keys : [:names, :nums, :alpha2s, :alpha3s]
|
49
|
+
* selected : set default value
|
50
|
+
* prompt : message
|
51
|
+
|
52
|
+
```rails
|
48
53
|
<%= form_for @user do |f| %>
|
49
54
|
<%= f.country_select :country, {:keys => :names, :values => :alpha2s, :selected => "CO"}, :prompt => "Choose a country"
|
50
55
|
<% end %>
|
51
56
|
```
|
52
57
|
|
53
58
|
HTML generated
|
59
|
+
|
54
60
|
```html
|
55
61
|
<select id="cliente_nacionalidad" name="user[country]" prompt="Choose a country" value="CO">
|
56
62
|
<option value="AF">Afghanistan</option>
|
57
63
|
<option value="AL">Albania</option>
|
58
64
|
<option value="AX">Ã
land Islands</option>
|
59
65
|
<option value="DZ">Algeria</option>
|
60
|
-
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
### Show country info
|
70
|
+
A helper method is available to get all the country info in the views, it return an array, the usage is.
|
71
|
+
|
72
|
+
Find by name
|
73
|
+
```ruby
|
74
|
+
country(:name => "Colombia")
|
75
|
+
[170, "Colombia", "CO", "COL"]
|
76
|
+
```
|
77
|
+
|
78
|
+
Find by Cod
|
79
|
+
```ruby
|
80
|
+
country(:num => 12)
|
81
|
+
[12, "Algeria", "DZ", "DZA"]
|
82
|
+
```
|
83
|
+
|
84
|
+
Find by Alpha2s
|
85
|
+
```ruby
|
86
|
+
country(:alpha2s => "AR")
|
87
|
+
[32, "Argentina", "AR", "ARG"]
|
88
|
+
```
|
89
|
+
|
90
|
+
Find by Alpha3s
|
91
|
+
```ruby
|
92
|
+
country(:alpha3s => "USA")
|
93
|
+
[840, "United States", "US", "USA"]
|
94
|
+
```
|
95
|
+
|
96
|
+
Also you can mix all the options hash, example
|
97
|
+
```ruby
|
98
|
+
country(:alpha3s => "USA", :alpha2s => "US", :num => 840, :name => "United States")
|
99
|
+
[840, "United States", "US", "USA"]
|
100
|
+
```
|
101
|
+
|
102
|
+
|
103
|
+
```html
|
104
|
+
<p>Country Cod: <%= country(:num => @user.country_num)[0] %><p>
|
105
|
+
<p>Country Name: <%= country(:num => @user.country_num)[1] %><p>
|
106
|
+
<p>Country Apha2s: <%= country(:num => @user.country_num)[2] %><p>
|
107
|
+
<p>Country Apha3s: <%= country(:num => @user.country_num)[3] %><p>
|
108
|
+
```
|
109
|
+
|
61
110
|
## Contributing
|
62
111
|
|
63
112
|
1. Fork it
|
data/lib/rails_country_select.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "rails_country_select/version"
|
3
|
-
|
4
3
|
require File.expand_path('../country_definitions', __FILE__)
|
4
|
+
|
5
5
|
if defined?(Rails) && defined?(ActionView)
|
6
6
|
module ActionView
|
7
7
|
module Helpers
|
8
|
+
autoload :CountryHelper, 'rails_country_select/helpers/rails_country_select'
|
8
9
|
module FormOptionsHelper
|
9
10
|
def country_select(object, method, options = {}, html_options = {})
|
10
11
|
options[:keys] = :names unless options.has_key?(:keys)
|
@@ -27,6 +28,17 @@ if defined?(Rails) && defined?(ActionView)
|
|
27
28
|
@template.country_select(@object_name, method, options.merge({:object => @object}), html_options)
|
28
29
|
end
|
29
30
|
end
|
31
|
+
|
32
|
+
# get country info given some params
|
33
|
+
def country(options = {:name => "", :num =>"", :alpha2s => "", :alpha3s => ""})
|
34
|
+
result = []
|
35
|
+
COUNTRY_NUMS.zip(COUNTRY_NAMES, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country|
|
36
|
+
if options[:nums].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3])
|
37
|
+
result = country
|
38
|
+
end
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_country_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruben Espinosa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
|
+
- CHANGELOG
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|