list_select 0.0.1

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.
@@ -0,0 +1 @@
1
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in list_select.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2011 Dmitry Naumov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ == ListSelect
2
+
3
+ Localiazed select lists helper.
4
+
5
+ Provides a simple helper to get an HTML select list of any lists defined in your locales files.
6
+ Has builtin lists for selecting countries, languages and more.
7
+ Adds country_select helper to integrate with SimpleForm and Formtastic.
8
+
9
+
10
+ == Requirements
11
+
12
+ Tested with Rails 3. Might work with other versions, too.
13
+
14
+
15
+ == Installation
16
+
17
+ Install a gem:
18
+
19
+ gem install list_select
20
+
21
+ Or add it to your Gemfile:
22
+
23
+ gem 'list_select'
24
+
25
+ Also you can install as a plugin:
26
+
27
+ rails plugin install git@github.com:bitzesty/list_select.git
28
+
29
+
30
+ == Example
31
+
32
+ Define any list in your locale file RAILS_ROOT/config/locales/en.rb:
33
+
34
+ { :en => { :animals => {
35
+ :dog => 'A Dog',
36
+ :cat => 'A Cat',
37
+ :cow => 'A Cow',
38
+ :pig => 'A Pig'
39
+ }}}
40
+
41
+ Make a select list in your view(examples of different usage):
42
+
43
+ <%= f.list_select(:pet, :animals) %>
44
+
45
+ <%= list_select("user", "pet", :animals) %>
46
+
47
+ <%= list_select_tag("user_pet", :animals) %>
48
+
49
+
50
+ == Options
51
+
52
+ The only List Select specific option is a :priority_items option.
53
+ All other options are the same as for other Rails form helpers.
54
+
55
+ <%= f.list_select(:pet, :animals, :priority_items => [ :dog, :cat ]) %>
56
+ <%= f.list_select(:pet, :animals, :default => :dog) %>
57
+ <%= f.list_select(:pet, :animals, :include_blank => 'Select your pet...') %>
58
+
59
+
60
+ == Built in lists
61
+
62
+ There are built in lists. They are:
63
+
64
+ * countries_cldr.en
65
+ * countries_iso3166_1_alpha_2.en # Recommended for Chargify API
66
+ * languages_cldr.en
67
+ * google_adwords_countries.en
68
+ * google_search_languages.en
69
+ * google_adwords_languages.en
70
+ * google_interface_languages.en
71
+
72
+ You need to install list you need before you can use it.
73
+
74
+ You can do this wth list_select generator.
75
+
76
+ Example:
77
+ rails generate list_select --help # See avalable lists
78
+ rails generate list_select countries_cldr.en # Install one you need
79
+
80
+ Notice:
81
+ You might need to restart your server for installed list to be available.
82
+
83
+
84
+ == Integration with 3rd party gems
85
+
86
+ ListSelect works with SimpleForm and Formtastic.
87
+ It adds country_select helper campatible with them.
88
+ You can also customize the countries list you use.
89
+ Default country list is :countries_cldr.
90
+
91
+ See examples:
92
+
93
+ <%= f.input :country %> # will use countries_cldr list (you should install it first)
94
+ <%= f.input :country, :list => :my_country_list %> # use :my_country_list defined in your locale files
95
+ <%= f.input :country, :priority => [:US,:BY] %> # set priority options
96
+ <%= f.input :country, :prompt => 'Select one...' %> # set the prompt
97
+ <%= f.input :country, :include_blank => true %> # include blank option
98
+
99
+
100
+ == TODO
101
+
102
+ * Add tests
103
+ * Add rake tasks to refetch lists
104
+ * Add more lists and locales
105
+
106
+ Copyright (c) 2010-2011 Dmitry Naumov, released under the MIT license
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+ include Rake::DSL
3
+ Bundler::GemHelper.install_tasks
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'list_select'
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Install one of ListSelect built in lists. Available lists:
3
+ countries_cldr.en
4
+ countries_iso3166_1_alpha_2.en
5
+ languages_cldr.en
6
+ google_adwords_countries.en
7
+ google_search_languages.en
8
+ google_adwords_languages.en
9
+ google_interface_languages.en
10
+
11
+ Example:
12
+ rails generate list_select LIST_NAME
13
+
14
+ This will create:
15
+ locales/list_name.rb
@@ -0,0 +1,7 @@
1
+ class ListSelectGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_list_file
5
+ copy_file "#{file_name}.rb", "config/locales/#{file_name}.rb"
6
+ end
7
+ end
@@ -0,0 +1,280 @@
1
+ #
2
+ # The Unicode Consortium CLDR territories
3
+ #
4
+ # http://unicode.org/repos/cldr-tmp/trunk/diff/summary/en.html
5
+ #
6
+
7
+ { :en => {
8
+
9
+ :countries_cldr => {
10
+ :AD => "Andorra",
11
+ :AE => "United Arab Emirates",
12
+ :AF => "Afghanistan",
13
+ :AG => "Antigua and Barbuda",
14
+ :AI => "Anguilla",
15
+ :AL => "Albania",
16
+ :AM => "Armenia",
17
+ :AN => "Netherlands Antilles",
18
+ :AO => "Angola",
19
+ :AQ => "Antarctica",
20
+ :AR => "Argentina",
21
+ :AS => "American Samoa",
22
+ :AT => "Austria",
23
+ :AU => "Australia",
24
+ :AW => "Aruba",
25
+ :AX => "Aland Islands",
26
+ :AZ => "Azerbaijan",
27
+ :BA => "Bosnia and Herzegovina",
28
+ :BB => "Barbados",
29
+ :BD => "Bangladesh",
30
+ :BE => "Belgium",
31
+ :BF => "Burkina Faso",
32
+ :BG => "Bulgaria",
33
+ :BH => "Bahrain",
34
+ :BI => "Burundi",
35
+ :BJ => "Benin",
36
+ :BL => "Saint Barthélemy",
37
+ :BM => "Bermuda",
38
+ :BN => "Brunei",
39
+ :BO => "Bolivia",
40
+ :BQ => "British Antarctic Territory",
41
+ :BR => "Brazil",
42
+ :BS => "Bahamas",
43
+ :BT => "Bhutan",
44
+ :BV => "Bouvet Island",
45
+ :BW => "Botswana",
46
+ :BY => "Belarus",
47
+ :BZ => "Belize",
48
+ :CA => "Canada",
49
+ :CC => "Cocos Islands",
50
+ :CD => "Congo - Kinshasa",
51
+ :CF => "Central African Republic",
52
+ :CG => "Congo - Brazzaville",
53
+ :CH => "Switzerland",
54
+ :CI => "Ivory Coast",
55
+ :CK => "Cook Islands",
56
+ :CL => "Chile",
57
+ :CM => "Cameroon",
58
+ :CN => "China",
59
+ :CO => "Colombia",
60
+ :CR => "Costa Rica",
61
+ :CS => "Serbia and Montenegro",
62
+ :CT => "Canton and Enderbury Islands",
63
+ :CU => "Cuba",
64
+ :CV => "Cape Verde",
65
+ :CX => "Christmas Island",
66
+ :CY => "Cyprus",
67
+ :CZ => "Czech Republic",
68
+ :DD => "East Germany",
69
+ :DE => "Germany",
70
+ :DJ => "Djibouti",
71
+ :DK => "Denmark",
72
+ :DM => "Dominica",
73
+ :DO => "Dominican Republic",
74
+ :DZ => "Algeria",
75
+ :EC => "Ecuador",
76
+ :EE => "Estonia",
77
+ :EG => "Egypt",
78
+ :EH => "Western Sahara",
79
+ :ER => "Eritrea",
80
+ :ES => "Spain",
81
+ :ET => "Ethiopia",
82
+ :FI => "Finland",
83
+ :FJ => "Fiji",
84
+ :FK => "Falkland Islands",
85
+ :FM => "Micronesia",
86
+ :FO => "Faroe Islands",
87
+ :FQ => "French Southern and Antarctic Territories",
88
+ :FR => "France",
89
+ :FX => "Metropolitan France",
90
+ :GA => "Gabon",
91
+ :GB => "United Kingdom",
92
+ :GD => "Grenada",
93
+ :GE => "Georgia",
94
+ :GF => "French Guiana",
95
+ :GG => "Guernsey",
96
+ :GH => "Ghana",
97
+ :GI => "Gibraltar",
98
+ :GL => "Greenland",
99
+ :GM => "Gambia",
100
+ :GN => "Guinea",
101
+ :GP => "Guadeloupe",
102
+ :GQ => "Equatorial Guinea",
103
+ :GR => "Greece",
104
+ :GS => "South Georgia and the South Sandwich Islands",
105
+ :GT => "Guatemala",
106
+ :GU => "Guam",
107
+ :GW => "Guinea-Bissau",
108
+ :GY => "Guyana",
109
+ :HK => "Hong Kong SAR China",
110
+ :HK => "Hong Kong",
111
+ :HM => "Heard Island and McDonald Islands",
112
+ :HN => "Honduras",
113
+ :HR => "Croatia",
114
+ :HT => "Haiti",
115
+ :HU => "Hungary",
116
+ :ID => "Indonesia",
117
+ :IE => "Ireland",
118
+ :IL => "Israel",
119
+ :IM => "Isle of Man",
120
+ :IN => "India",
121
+ :IO => "British Indian Ocean Territory",
122
+ :IQ => "Iraq",
123
+ :IR => "Iran",
124
+ :IS => "Iceland",
125
+ :IT => "Italy",
126
+ :JE => "Jersey",
127
+ :JM => "Jamaica",
128
+ :JO => "Jordan",
129
+ :JP => "Japan",
130
+ :JT => "Johnston Island",
131
+ :KE => "Kenya",
132
+ :KG => "Kyrgyzstan",
133
+ :KH => "Cambodia",
134
+ :KI => "Kiribati",
135
+ :KM => "Comoros",
136
+ :KN => "Saint Kitts and Nevis",
137
+ :KP => "North Korea",
138
+ :KR => "South Korea",
139
+ :KW => "Kuwait",
140
+ :KY => "Cayman Islands",
141
+ :KZ => "Kazakhstan",
142
+ :LA => "Laos",
143
+ :LB => "Lebanon",
144
+ :LC => "Saint Lucia",
145
+ :LI => "Liechtenstein",
146
+ :LK => "Sri Lanka",
147
+ :LR => "Liberia",
148
+ :LS => "Lesotho",
149
+ :LT => "Lithuania",
150
+ :LU => "Luxembourg",
151
+ :LV => "Latvia",
152
+ :LY => "Libya",
153
+ :MA => "Morocco",
154
+ :MC => "Monaco",
155
+ :MD => "Moldova",
156
+ :ME => "Montenegro",
157
+ :MF => "Saint Martin",
158
+ :MG => "Madagascar",
159
+ :MH => "Marshall Islands",
160
+ :MI => "Midway Islands",
161
+ :MK => "Macedonia",
162
+ :ML => "Mali",
163
+ :MM => "Myanmar",
164
+ :MN => "Mongolia",
165
+ :MO => "Macau SAR China",
166
+ :MO => "Macau",
167
+ :MP => "Northern Mariana Islands",
168
+ :MQ => "Martinique",
169
+ :MR => "Mauritania",
170
+ :MS => "Montserrat",
171
+ :MT => "Malta",
172
+ :MU => "Mauritius",
173
+ :MV => "Maldives",
174
+ :MW => "Malawi",
175
+ :MX => "Mexico",
176
+ :MY => "Malaysia",
177
+ :MZ => "Mozambique",
178
+ :NA => "Namibia",
179
+ :NC => "New Caledonia",
180
+ :NE => "Niger",
181
+ :NF => "Norfolk Island",
182
+ :NG => "Nigeria",
183
+ :NI => "Nicaragua",
184
+ :NL => "Netherlands",
185
+ :NO => "Norway",
186
+ :NP => "Nepal",
187
+ :NQ => "Dronning Maud Land",
188
+ :NR => "Nauru",
189
+ :NT => "Neutral Zone",
190
+ :NU => "Niue",
191
+ :NZ => "New Zealand",
192
+ :OM => "Oman",
193
+ :PA => "Panama",
194
+ :PC => "Pacific Islands Trust Territory",
195
+ :PE => "Peru",
196
+ :PF => "French Polynesia",
197
+ :PG => "Papua New Guinea",
198
+ :PH => "Philippines",
199
+ :PK => "Pakistan",
200
+ :PL => "Poland",
201
+ :PM => "Saint Pierre and Miquelon",
202
+ :PN => "Pitcairn",
203
+ :PR => "Puerto Rico",
204
+ :PS => "Palestinian Territory",
205
+ :PT => "Portugal",
206
+ :PU => "U.S. Miscellaneous Pacific Islands",
207
+ :PW => "Palau",
208
+ :PY => "Paraguay",
209
+ :PZ => "Panama Canal Zone",
210
+ :QA => "Qatar",
211
+ :QO => "Outlying Oceania",
212
+ :QU => "European Union",
213
+ :RE => "Reunion",
214
+ :RO => "Romania",
215
+ :RS => "Serbia",
216
+ :RU => "Russia",
217
+ :RW => "Rwanda",
218
+ :SA => "Saudi Arabia",
219
+ :SB => "Solomon Islands",
220
+ :SC => "Seychelles",
221
+ :SD => "Sudan",
222
+ :SE => "Sweden",
223
+ :SG => "Singapore",
224
+ :SH => "Saint Helena",
225
+ :SI => "Slovenia",
226
+ :SJ => "Svalbard and Jan Mayen",
227
+ :SK => "Slovakia",
228
+ :SL => "Sierra Leone",
229
+ :SM => "San Marino",
230
+ :SN => "Senegal",
231
+ :SO => "Somalia",
232
+ :SR => "Suriname",
233
+ :ST => "Sao Tome and Principe",
234
+ :SU => "Union of Soviet Socialist Republics",
235
+ :SV => "El Salvador",
236
+ :SY => "Syria",
237
+ :SZ => "Swaziland",
238
+ :TC => "Turks and Caicos Islands",
239
+ :TD => "Chad",
240
+ :TF => "French Southern Territories",
241
+ :TG => "Togo",
242
+ :TH => "Thailand",
243
+ :TJ => "Tajikistan",
244
+ :TK => "Tokelau",
245
+ :TL => "East Timor",
246
+ :TM => "Turkmenistan",
247
+ :TN => "Tunisia",
248
+ :TO => "Tonga",
249
+ :TR => "Turkey",
250
+ :TT => "Trinidad and Tobago",
251
+ :TV => "Tuvalu",
252
+ :TW => "Taiwan",
253
+ :TZ => "Tanzania",
254
+ :UA => "Ukraine",
255
+ :UG => "Uganda",
256
+ :UM => "United States Minor Outlying Islands",
257
+ :US => "United States",
258
+ :UY => "Uruguay",
259
+ :UZ => "Uzbekistan",
260
+ :VA => "Vatican",
261
+ :VC => "Saint Vincent and the Grenadines",
262
+ :VD => "North Vietnam",
263
+ :VE => "Venezuela",
264
+ :VG => "British Virgin Islands",
265
+ :VI => "U.S. Virgin Islands",
266
+ :VN => "Vietnam",
267
+ :VU => "Vanuatu",
268
+ :WF => "Wallis and Futuna",
269
+ :WK => "Wake Island",
270
+ :WS => "Samoa",
271
+ :YD => "People's Democratic Republic of Yemen",
272
+ :YE => "Yemen",
273
+ :YT => "Mayotte",
274
+ :ZA => "South Africa",
275
+ :ZM => "Zambia",
276
+ :ZW => "Zimbabwe",
277
+ :ZZ => "Unknown or Invalid Region",
278
+ }
279
+
280
+ }}