mobit 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +1 -0
- data/lib/mobit.rb +23 -0
- data/lib/mobit/core/country.rb +60 -0
- data/lib/mobit/core/ip_country_code.rb +18 -0
- data/lib/mobit/data/country_codes.csv +238 -0
- data/lib/mobit/data/operators/ua.csv +15 -0
- data/lib/mobit/engine.rb +25 -0
- data/lib/mobit/helpers/form_builder.rb +15 -0
- data/lib/mobit/helpers/formtastic/country_phone.rb +7 -0
- data/lib/mobit/helpers/simple_form/country_phone_input.rb +13 -0
- data/lib/mobit/helpers/view_helper.rb +34 -0
- data/lib/mobit/version.rb +4 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ea83d9b9241023bf96398ba52791ad35ea0b644
|
4
|
+
data.tar.gz: c70aa807b50ccd4b22348b7c441dc512b81612d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85ee11ed947f42ace96c10eefbdf4f6df9cfed840d96251b8c3ebf32fff8aa0935d2f0fbf0b4f7d84c3255077d4f299c9bab9dda7b0e5e557859ab117b48224d
|
7
|
+
data.tar.gz: 13f10ea55c2ec76bd2fc8de78460277b537c53e6a9515ee718523944261156f11c77e839ffad2c8cb90324bc632fad350155be54f597a588afc81c14b41a357b
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Alex Mercury
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Mobit [![Gem Version](https://badge.fury.io/rb/mobit.svg)](http://badge.fury.io/rb/mobit)
|
2
|
+
|
3
|
+
```html
|
4
|
+
<div>
|
5
|
+
<select name="phone_country_code">
|
6
|
+
<option value="93" data-trunk-code="0">Afghanistan (+93)</option>
|
7
|
+
<option value="355" data-trunk-code="0">Albania (+355)</option>
|
8
|
+
<option value="213" data-trunk-code="0">Algeria (+213)</option>
|
9
|
+
...
|
10
|
+
<option value="263" data-trunk-code="0">Zimbabwe (+263)</option>
|
11
|
+
</select>
|
12
|
+
<input type="phone" name="phone" required="required">
|
13
|
+
</div>
|
14
|
+
```
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'mobit'
|
22
|
+
```
|
23
|
+
|
24
|
+
or
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'mobit', :git => 'git://github.com/rubybeast/mobit.git'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install mobit
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Simple Helper 'rails_phone_tag'
|
41
|
+
|
42
|
+
```erb
|
43
|
+
<%= rails_phone_tag :phone, '', required: true %>
|
44
|
+
```
|
45
|
+
|
46
|
+
Form For 'form.rails_phone_field'
|
47
|
+
|
48
|
+
```erb
|
49
|
+
<%= form_for @example do |f|%>
|
50
|
+
<%= f.rails_phone_field :phone, required: true %>
|
51
|
+
<%= f.submit %>
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
|
55
|
+
Simple_Form_For 'form.rails_phone'
|
56
|
+
|
57
|
+
```erb
|
58
|
+
<%= simple_form_for @example do |f|%>
|
59
|
+
<%= f.input :phone, as: :country_phone, required: true %>
|
60
|
+
<%= f.submit %>
|
61
|
+
<% end %>
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
Formtastic 'form.country_phone'
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<%= semantic_form_for @example do |form| %>
|
69
|
+
<%= form.country_phone :phone, required: true %>
|
70
|
+
<%= form.submit %>
|
71
|
+
<% end %>
|
72
|
+
```
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/mobit/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/mobit.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'mobit/version'
|
3
|
+
require 'mobit/engine'
|
4
|
+
|
5
|
+
autoload :CountryPhoneInput, 'mobit/helpers/simple_form/country_phone_input'
|
6
|
+
|
7
|
+
module Formtastic
|
8
|
+
autoload :CountryPhone, 'mobit/helpers/formtastic/country_phone'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Mobit
|
12
|
+
|
13
|
+
module Core
|
14
|
+
autoload :IpCountryCode, 'mobit/core/ip_country_code'
|
15
|
+
autoload :Country, 'mobit/core/country'
|
16
|
+
end
|
17
|
+
|
18
|
+
module Helpers
|
19
|
+
autoload :ViewHelper, 'mobit/helpers/view_helper'
|
20
|
+
autoload :FormBuilder, 'mobit/helpers/form_builder'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Mobit
|
5
|
+
module Core
|
6
|
+
class Country
|
7
|
+
|
8
|
+
# Initialize country from csv file row (Array)
|
9
|
+
def initialize(row = [])
|
10
|
+
# "Name", "A2 (ISO)", "A3 (UN)", "Dialing code", "Trunk code"
|
11
|
+
@name = row[0] rescue nil
|
12
|
+
@iso_a2 = row[1] rescue nil
|
13
|
+
@un_a3 = row[2] rescue nil
|
14
|
+
@code = row[3] rescue nil
|
15
|
+
@trunk_code = row[4] rescue nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@name
|
20
|
+
end
|
21
|
+
|
22
|
+
def iso_a2
|
23
|
+
@iso_a2
|
24
|
+
end
|
25
|
+
|
26
|
+
def un_a3
|
27
|
+
@un_a3
|
28
|
+
end
|
29
|
+
|
30
|
+
def code
|
31
|
+
@code
|
32
|
+
end
|
33
|
+
|
34
|
+
def trunk_code
|
35
|
+
@trunk_code
|
36
|
+
end
|
37
|
+
|
38
|
+
# Country class methods
|
39
|
+
class << self
|
40
|
+
|
41
|
+
# Return Array of Mobit::Core::Country objects
|
42
|
+
def all_codes
|
43
|
+
countries_csv.map do |row|
|
44
|
+
Mobit::Core::Country.new(row)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Read csv file & create Array
|
50
|
+
def countries_csv
|
51
|
+
path = __dir__.sub(/core\Z/i, 'data')
|
52
|
+
path += '/country_codes.csv'
|
53
|
+
CSV.read(path)[1..-1] rescue []
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
Name,A2 (ISO),A3 (UN),Dialing code,Trunk code
|
2
|
+
"Afghanistan",AF,AFG,93,0
|
3
|
+
"Albania",AL,ALB,355,0
|
4
|
+
"Algeria",DZ,DZA,213,0
|
5
|
+
"American Samoa",AS,ASM,1684,1
|
6
|
+
"Andorra",AD,AND,376,
|
7
|
+
"Angola",AO,AGO,244,
|
8
|
+
"Anguilla",AI,AIA,1264,1
|
9
|
+
"Antarctica",AQ,ATA,672,
|
10
|
+
"Antigua and Barbuda",AG,ATG,1268,1
|
11
|
+
"Argentina",AR,ARG,54,0
|
12
|
+
"Armenia",AM,ARM,374,0
|
13
|
+
"Aruba",AW,ABW,297,
|
14
|
+
"Australia",AU,AUS,61,0
|
15
|
+
"Austria",AT,AUT,43,0
|
16
|
+
"Azerbaijan",AZ,AZE,994,0
|
17
|
+
"Bahamas",BS,BHS,1242,1
|
18
|
+
"Bahrain",BH,BHR,973,
|
19
|
+
"Bangladesh",BD,BGD,880,0
|
20
|
+
"Barbados",BB,BRB,1246,1
|
21
|
+
"Belarus",BY,BLR,375,80
|
22
|
+
"Belgium",BE,BEL,32,0
|
23
|
+
"Belize",BZ,BLZ,501,
|
24
|
+
"Benin",BJ,BEN,229,
|
25
|
+
"Bermuda",BM,BMU,1441,1
|
26
|
+
"Bhutan",BT,BTN,975,
|
27
|
+
"Bolivia",BO,BOL,591,0
|
28
|
+
"Bosnia and Herzegovina",BA,BIH,387,0
|
29
|
+
"Botswana",BW,BWA,267,
|
30
|
+
"Brazil",BR,BRA,55,0
|
31
|
+
"British Virgin Islands",VG,VGB,1284,1
|
32
|
+
"Brunei",BN,BRN,673,
|
33
|
+
"Bulgaria",BG,BGR,359,0
|
34
|
+
"Burkina Faso",BF,BFA,226,
|
35
|
+
"Burma(Myanmar)",MM,MMR,95,
|
36
|
+
"Burundi",BI,BDI,257,
|
37
|
+
"Cambodia",KH,KHM,855,0
|
38
|
+
"Cameroon",CM,CMR,237,
|
39
|
+
"Canada",CA,CAN,1,1
|
40
|
+
"Cape Verde",CV,CPV,238,
|
41
|
+
"Cayman Islands",KY,CYM,1345,1
|
42
|
+
"Central African Republic",CF,CAF,236,
|
43
|
+
"Chad",TD,TCD,235,
|
44
|
+
"Chile",CL,CHL,56,0
|
45
|
+
"China",CN,CHN,86,0
|
46
|
+
"Christmas Island",CX,CXR,61,
|
47
|
+
"Cocos(Keeling)Islands",CC,CCK,61,
|
48
|
+
"Colombia",CO,COL,57,0
|
49
|
+
"Comoros",KM,COM,269,
|
50
|
+
"Cook Islands",CK,COK,682,
|
51
|
+
"Costa Rica",CR,CRC,506,
|
52
|
+
"Croatia",HR,HRV,385,0
|
53
|
+
"Cuba",CU,CUB,53,0
|
54
|
+
"Cyprus",CY,CYP,357,
|
55
|
+
"Czech Republic",CZ,CZE,420,
|
56
|
+
"Democratic Republic of the Congo",CD,COD,243,0
|
57
|
+
"Denmark",DK,DNK,45,
|
58
|
+
"Djibouti",DJ,DJI,253,
|
59
|
+
"Dominica",DM,DMA,1767,1
|
60
|
+
"Dominican Republic",DO,DOM,1809,1
|
61
|
+
"Ecuador",EC,ECU,593,0
|
62
|
+
"Egypt",EG,EGY,20,0
|
63
|
+
"El Salvador",SV,SLV,503,
|
64
|
+
"Equatorial Guinea",GQ,GNQ,240,
|
65
|
+
"Eritrea",ER,ERI,291,0
|
66
|
+
"Estonia",EE,EST,372,
|
67
|
+
"Ethiopia",ET,ETH,251,0
|
68
|
+
"Falkland Islands",FK,FLK,500,
|
69
|
+
"Faroe Islands",FO,FRO,298,
|
70
|
+
"Fiji",FJ,FJI,679,
|
71
|
+
"Finland",FI,FIN,358,0
|
72
|
+
"France",FR,FRA,33,0
|
73
|
+
"French Guiana",,,594,0
|
74
|
+
"French Polynesia",PF,PYF,689,
|
75
|
+
"Gabon",GA,GAB,241,
|
76
|
+
"Gambia",GM,GMB,220,
|
77
|
+
"Gaza Strip",,,970,
|
78
|
+
"Georgia",GE,GEO,995,0
|
79
|
+
"Germany",DE,DEU,49,0
|
80
|
+
"Ghana",GH,GHA,233,0
|
81
|
+
"Gibraltar",GI,GIB,350,
|
82
|
+
"Greece",GR,GRC,30,
|
83
|
+
"Greenland",GL,GRL,299,
|
84
|
+
"Grenada",GD,GRD,1473,1
|
85
|
+
"Guam",GU,GUM,1671,1
|
86
|
+
"Guatemala",GT,GTM,502,
|
87
|
+
"Guinea",GN,GIN,224,
|
88
|
+
"Guinea-Bissau",GW,GNB,245,
|
89
|
+
"Guyana",GY,GUY,592,
|
90
|
+
"Haiti",HT,HTI,509,
|
91
|
+
"Holy See (Vatican City)",VA,VAT,39,
|
92
|
+
"Honduras",HN,HND,504,
|
93
|
+
"Hong Kong",HK,HKG,852,
|
94
|
+
"Hungary",HU,HUN,36,06
|
95
|
+
"Iceland",IS,IS,354,
|
96
|
+
"India",IN,IND,91,0
|
97
|
+
"Indonesia",ID,IDN,62,0
|
98
|
+
"Iran",IR,IRN,98,0
|
99
|
+
"Iraq",IQ,IRQ,964,
|
100
|
+
"Ireland",IE,IRL,353,0
|
101
|
+
"Isle of Man",IM,IMN,44,
|
102
|
+
"Israel",IL,ISR,972,0
|
103
|
+
"Italy",IT,ITA,39,
|
104
|
+
"Ivory Coast",CI,CIV,225,
|
105
|
+
"Jamaica",JM,JAM,1876,1
|
106
|
+
"Japan",JP,JPN,81,0
|
107
|
+
Jersey,JE,JEY,44,
|
108
|
+
"Jordan",JO,JOR,962,0
|
109
|
+
"Kazakhstan",KZ,KAZ,7,8
|
110
|
+
"Kenya",KE,KEN,254,0
|
111
|
+
"Kiribati",KI,KIR,686,
|
112
|
+
"Kosovo",,,381,
|
113
|
+
"Kuwait",KW,KWT,965,
|
114
|
+
"Kyrgyzstan",KG,KGZ,996,0
|
115
|
+
"Laos",LA,LAO,856,0
|
116
|
+
"Latvia",LV,LVA,371,
|
117
|
+
"Lebanon",LB,LBN,961,0
|
118
|
+
"Lesotho",LS,LSO,266,
|
119
|
+
"Liberia",LR,LBR,231,
|
120
|
+
"Libya",LY,LBY,218,0
|
121
|
+
"Liechtenstein",LI,LIE,423,
|
122
|
+
"Lithuania",LT,LTU,370,8
|
123
|
+
"Luxembourg",LU,LUX,352,
|
124
|
+
"Macau",MO,MAC,853,
|
125
|
+
"Macedonia",MK,MKD,389,0
|
126
|
+
"Madagascar",MG,MDG,261,0
|
127
|
+
"Malawi",MW,MWI,265,
|
128
|
+
"Malaysia",MY,MYS,60,0
|
129
|
+
"Maldives",MV,MDV,960,
|
130
|
+
"Mali",ML,MLI,223,
|
131
|
+
"Malta",MT,MLT,356,
|
132
|
+
"Marshall Islands",MH,MHL,692,1
|
133
|
+
"Mauritania",MR,MRT,222,
|
134
|
+
"Mauritius",MU,MUS,230,
|
135
|
+
"Mayotte",YT,MYT,262,0
|
136
|
+
"Mexico",MX,MEX,52,01|044|045
|
137
|
+
"Micronesia",FM,FSM,691,1
|
138
|
+
"Moldova",MD,MDA,373,0
|
139
|
+
"Monaco",MC,MCO,377,
|
140
|
+
"Mongolia",MN,MNG,976,0
|
141
|
+
"Montenegro",ME,MNE,382,0
|
142
|
+
"Montserrat",MS,MSR,1664,1
|
143
|
+
"Morocco",MA,MAR,212,0
|
144
|
+
"Mozambique",MZ,MOZ,258,
|
145
|
+
"Namibia",NA,NAM,264,0
|
146
|
+
"Nauru",NR,NRU,674,
|
147
|
+
"Nepal",NP,NPL,977,0
|
148
|
+
"Netherlands",NL,NLD,31,0
|
149
|
+
"Netherlands Antilles",AN,ANT,599,0
|
150
|
+
"New Caledonia",NC,NCL,687,
|
151
|
+
"New Zealand",NZ,NZL,64,0
|
152
|
+
"Nicaragua",NI,NIC,505,
|
153
|
+
"Niger",NE,NER,227,
|
154
|
+
"Nigeria",NG,NGA,234,0
|
155
|
+
"Niue",NU,NIU,683,
|
156
|
+
"Norfolk Island",,NFK,672
|
157
|
+
"North Korea",KP,PRK,850,
|
158
|
+
"Northern Mariana Islands",MP,MNP,1670,1
|
159
|
+
"Norway",NO,NOR,47,
|
160
|
+
"Oman",OM,OMN,968,
|
161
|
+
"Pakistan",PK,PAK,92,0
|
162
|
+
"Palau",PW,PLW,680,
|
163
|
+
"Panama",PA,PAN,507,
|
164
|
+
"Papua New Guinea",PG,PNG,675,
|
165
|
+
"Paraguay",PY,PRY,595,0
|
166
|
+
"Peru",PE,PER,51,0
|
167
|
+
"Philippines",PH,PHL,63,0
|
168
|
+
"Pitcairn Islands",PN,PCN,870,
|
169
|
+
"Poland",PL,POL,48,
|
170
|
+
"Portugal",PT,PRT,351,
|
171
|
+
"Puerto Rico",PR,PRI,1,1
|
172
|
+
"Qatar",QA,QAT,974,
|
173
|
+
"Republic of the Congo",CG,COG,242,
|
174
|
+
"Romania",RO,ROU,40,0
|
175
|
+
"Russia",RU,RUS,7,8
|
176
|
+
"Rwanda",RW,RWA,250,
|
177
|
+
"Saint Barthelemy",BL,BLM,590,
|
178
|
+
"Saint Helena",SH,SHN,290,
|
179
|
+
"Saint Kitts and Nevis",KN,KNA,1869,1
|
180
|
+
"Saint Lucia",LC,LCA,1758,1
|
181
|
+
"Saint Martin",MF,MAF,1599,0
|
182
|
+
"Saint Pierre and Miquelon",PM,SPM,508,
|
183
|
+
"Saint Vincent and the Grenadines",VC,VCT,1784,1
|
184
|
+
"Samoa",WS,WSM,685,
|
185
|
+
"San Marino",SM,SMR,378,
|
186
|
+
"Sao Tome and Principe",ST,STP,239,
|
187
|
+
"Saudi Arabia",SA,SAU,966,0
|
188
|
+
"Senegal",SN,SEN,221,
|
189
|
+
"Serbia",RS,SRB,381,0
|
190
|
+
"Seychelles",SC,SYC,248,
|
191
|
+
"Sierra Leone",SL,SLE,232,0
|
192
|
+
"Singapore",SG,SGP,65,
|
193
|
+
"Slovakia",SK,SVK,421,0
|
194
|
+
"Slovenia",SI,SVN,386,0
|
195
|
+
"Solomon Islands",SB,SLB,677,
|
196
|
+
"Somalia",SO,SOM,252,
|
197
|
+
"South Africa",ZA,ZAF,27,0
|
198
|
+
"South Korea",KR,KOR,82,0
|
199
|
+
"Spain",ES,ESP,34,
|
200
|
+
"Sri Lanka",LK,LKA,94,0
|
201
|
+
"Sudan",SD,SDN,249,0
|
202
|
+
"Suriname",SR,SUR,597,0
|
203
|
+
Svalbard,SJ,SJM,4779,
|
204
|
+
"Swaziland",SZ,SWZ,268,
|
205
|
+
"Sweden",SE,SWE,46,0
|
206
|
+
"Switzerland",CH,CHE,41,0
|
207
|
+
"Syria",SY,SYR,963,0
|
208
|
+
"Taiwan",TW,TWN,886,0
|
209
|
+
"Tajikistan",TJ,TJK,992,8
|
210
|
+
"Tanzania",TZ,TZA,255,0
|
211
|
+
"Thailand",TH,THA,66,0
|
212
|
+
"Timor-Leste",TL,TLS,670,
|
213
|
+
"Togo",TG,TGO,228,
|
214
|
+
"Tokelau",TK,TKL,690,
|
215
|
+
"Tonga",TO,TON,676,
|
216
|
+
"Trinidad and Tobago",TT,TTO,1868,1
|
217
|
+
"Tunisia",TN,TUN,216,
|
218
|
+
"Turkey",TR,TUR,90,0
|
219
|
+
"Turkmenistan",TM,TKM,993,8
|
220
|
+
"Turks and Caicos Islands",TC,TCA,1649,1
|
221
|
+
"Tuvalu",TV,TUV,688,
|
222
|
+
"Uganda",UG,UGA,256,0
|
223
|
+
"Ukraine",UA,UKR,380,0
|
224
|
+
"United Arab Emirates",AE,ARE,971,0
|
225
|
+
"United Kingdom",GB,GBR,44,0
|
226
|
+
"United States",US,USA,1,1
|
227
|
+
"Uruguay",UY,URY,598,0
|
228
|
+
"US Virgin Islands",VI,VIR,1340,
|
229
|
+
"Uzbekistan",UZ,UZB,998,0
|
230
|
+
"Vanuatu",VU,VUT,678,
|
231
|
+
"Venezuela",VE,VEN,58,0
|
232
|
+
"Vietnam",VN,VNM,84,0
|
233
|
+
"Wallis and Futuna",WF,WLF,681,
|
234
|
+
"West Bank",,,970,
|
235
|
+
"Western Sahara",EH,ESH,212528,
|
236
|
+
"Yemen",YE,YEM,967,0
|
237
|
+
"Zambia",ZM,ZMB,260,0
|
238
|
+
"Zimbabwe",ZW,ZWE,263,0
|
data/lib/mobit/engine.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mobit
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
|
6
|
+
isolate_namespace Mobit
|
7
|
+
|
8
|
+
initializer 'mobit.helpers' do
|
9
|
+
|
10
|
+
ActiveSupport.on_load :action_view do
|
11
|
+
ActionView::Base.send :include, Mobit::Helpers::ViewHelper
|
12
|
+
ActionView::Helpers::FormBuilder.send :include, Mobit::Helpers::FormBuilder
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer 'formtastic.helpers' do
|
18
|
+
ActiveSupport.on_load :action_view do
|
19
|
+
Formtastic::FormBuilder.send :include, Formtastic::CountryPhone
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mobit
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
module FormBuilder
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def rails_phone_field(method, options = {})
|
9
|
+
@template.send("rails_phone_tag", @object_name, method, objectify_options(options))
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#
|
2
|
+
# при попытке вложить CountryPhoneInput в модули возникали ошибки в строке ( ```error``` )
|
3
|
+
# f.input :phone, ```as: :country_phone```
|
4
|
+
#
|
5
|
+
|
6
|
+
class CountryPhoneInput < SimpleForm::Inputs::Base
|
7
|
+
|
8
|
+
def input(wrapper_options = nil)
|
9
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
10
|
+
@builder.rails_phone_field(attribute_name, merged_input_options)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mobit
|
3
|
+
module Helpers
|
4
|
+
module ViewHelper
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def rails_phone_tag(name, content = nil, options = {})
|
8
|
+
|
9
|
+
# ip = request.remote_ip # Rails => Get User IP address
|
10
|
+
# cc = Mobit::Core::IpCountryCode.cc_from_ip(ip) # Get country code from IP address
|
11
|
+
|
12
|
+
html = '<div>'
|
13
|
+
|
14
|
+
html += '<select name="' + name.to_s + '_country_code">'
|
15
|
+
|
16
|
+
Mobit::Core::Country::all_codes.each do |c|
|
17
|
+
html += "<option value='#{c.code}' data-trunk-code='#{c.trunk_code}'>"
|
18
|
+
# html += " #{'selected="selected"' if c.iso_a2 == cc}>"
|
19
|
+
html += "#{c.name} (+#{c.code})</option>"
|
20
|
+
end
|
21
|
+
|
22
|
+
html += '</select>'
|
23
|
+
|
24
|
+
html += '<input type="phone" name="' + name.to_s + '" ' + "#{'required="required"' if options.key?(:required) or options.key?('required')}" + '/>'
|
25
|
+
|
26
|
+
|
27
|
+
html += '</div>'
|
28
|
+
|
29
|
+
html.html_safe
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alexmercury
|
8
|
+
- b8in
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: actionpack
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '4.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '4.0'
|
56
|
+
description: Write a longer description. Optional.
|
57
|
+
email:
|
58
|
+
- rubybeastua@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/mobit.rb
|
67
|
+
- lib/mobit/core/country.rb
|
68
|
+
- lib/mobit/core/ip_country_code.rb
|
69
|
+
- lib/mobit/data/country_codes.csv
|
70
|
+
- lib/mobit/data/operators/ua.csv
|
71
|
+
- lib/mobit/engine.rb
|
72
|
+
- lib/mobit/helpers/form_builder.rb
|
73
|
+
- lib/mobit/helpers/formtastic/country_phone.rb
|
74
|
+
- lib/mobit/helpers/simple_form/country_phone_input.rb
|
75
|
+
- lib/mobit/helpers/view_helper.rb
|
76
|
+
- lib/mobit/version.rb
|
77
|
+
homepage: https://github.com/rubybeast/mobit
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Write a short summary. Required.
|
101
|
+
test_files: []
|