address_picker-rails 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.document +5 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +155 -0
  4. data/Guardfile +37 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +212 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/address_picker-rails.gemspec +115 -0
  10. data/lib/address_picker-rails.rb +4 -0
  11. data/lib/address_picker-rails/engine.rb +11 -0
  12. data/spec/dummy/README.rdoc +261 -0
  13. data/spec/dummy/Rakefile +7 -0
  14. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  17. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  18. data/spec/dummy/app/mailers/.gitkeep +0 -0
  19. data/spec/dummy/app/models/.gitkeep +0 -0
  20. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/spec/dummy/config.ru +4 -0
  22. data/spec/dummy/config/application.rb +65 -0
  23. data/spec/dummy/config/boot.rb +10 -0
  24. data/spec/dummy/config/database.yml +25 -0
  25. data/spec/dummy/config/environment.rb +5 -0
  26. data/spec/dummy/config/environments/development.rb +37 -0
  27. data/spec/dummy/config/environments/production.rb +67 -0
  28. data/spec/dummy/config/environments/test.rb +37 -0
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  30. data/spec/dummy/config/initializers/inflections.rb +15 -0
  31. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  32. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  33. data/spec/dummy/config/initializers/session_store.rb +8 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +5 -0
  36. data/spec/dummy/config/routes.rb +58 -0
  37. data/spec/dummy/lib/assets/.gitkeep +0 -0
  38. data/spec/dummy/log/.gitignore +1 -0
  39. data/spec/dummy/log/.gitkeep +0 -0
  40. data/spec/dummy/public/404.html +26 -0
  41. data/spec/dummy/public/422.html +26 -0
  42. data/spec/dummy/public/500.html +25 -0
  43. data/spec/dummy/public/favicon.ico +0 -0
  44. data/spec/dummy/script/rails +6 -0
  45. data/spec/spec_helper.rb +79 -0
  46. data/vendor/assets/javascripts/address_picker-rails.js +189 -0
  47. data/vendor/assets/javascripts/address_picker.js +209 -0
  48. data/vendor/assets/javascripts/address_picker_gmaps.js +130 -0
  49. data/vendor/assets/stylesheets/address_picker-rails.css +0 -0
  50. metadata +260 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # ------------------------------------------------------------------------------
4
+ # Dependencies required to use the gem.
5
+ gem 'rails', '~> 3.2.0'
6
+
7
+
8
+
9
+ # ------------------------------------------------------------------------------
10
+ # Dependencies to develop the gem.
11
+ # Everything needed to run rake, tests, features, etc.
12
+ group :development do
13
+ gem 'bundler', '~> 1.1.0'
14
+ gem 'capybara', '~> 1.1.0'
15
+ gem 'guard', '~> 1.3.0'
16
+ gem 'guard-rspec', '~> 1.2.0'
17
+ gem 'guard-spork', '~> 1.1.0'
18
+ gem 'jeweler', '~> 1.8.4'
19
+ #gem 'rcov', '>= 0'
20
+ gem 'rdoc', '~> 3.12'
21
+ gem 'rspec-rails', '~> 2.11.0'
22
+ gem 'sqlite3', '~> 1.3.0'
23
+ end
@@ -0,0 +1,155 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.8)
18
+ activesupport (= 3.2.8)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.8)
21
+ activemodel (= 3.2.8)
22
+ activesupport (= 3.2.8)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.8)
26
+ activemodel (= 3.2.8)
27
+ activesupport (= 3.2.8)
28
+ activesupport (3.2.8)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ addressable (2.3.2)
32
+ arel (3.0.2)
33
+ builder (3.0.0)
34
+ capybara (1.1.2)
35
+ mime-types (>= 1.16)
36
+ nokogiri (>= 1.3.3)
37
+ rack (>= 1.0.0)
38
+ rack-test (>= 0.5.4)
39
+ selenium-webdriver (~> 2.0)
40
+ xpath (~> 0.1.4)
41
+ childprocess (0.3.5)
42
+ ffi (~> 1.0, >= 1.0.6)
43
+ diff-lcs (1.1.3)
44
+ erubis (2.7.0)
45
+ ffi (1.1.5)
46
+ git (1.2.5)
47
+ guard (1.3.2)
48
+ listen (>= 0.4.2)
49
+ thor (>= 0.14.6)
50
+ guard-rspec (1.2.1)
51
+ guard (>= 1.1)
52
+ guard-spork (1.1.0)
53
+ guard (>= 1.1)
54
+ spork (>= 0.8.4)
55
+ hike (1.2.1)
56
+ i18n (0.6.0)
57
+ jeweler (1.8.4)
58
+ bundler (~> 1.0)
59
+ git (>= 1.2.5)
60
+ rake
61
+ rdoc
62
+ journey (1.0.4)
63
+ json (1.7.5)
64
+ libwebsocket (0.1.5)
65
+ addressable
66
+ listen (0.4.7)
67
+ rb-fchange (~> 0.0.5)
68
+ rb-fsevent (~> 0.9.1)
69
+ rb-inotify (~> 0.8.8)
70
+ mail (2.4.4)
71
+ i18n (>= 0.4.0)
72
+ mime-types (~> 1.16)
73
+ treetop (~> 1.4.8)
74
+ mime-types (1.19)
75
+ multi_json (1.3.6)
76
+ nokogiri (1.5.5)
77
+ polyglot (0.3.3)
78
+ rack (1.4.1)
79
+ rack-cache (1.2)
80
+ rack (>= 0.4)
81
+ rack-ssl (1.3.2)
82
+ rack
83
+ rack-test (0.6.1)
84
+ rack (>= 1.0)
85
+ rails (3.2.8)
86
+ actionmailer (= 3.2.8)
87
+ actionpack (= 3.2.8)
88
+ activerecord (= 3.2.8)
89
+ activeresource (= 3.2.8)
90
+ activesupport (= 3.2.8)
91
+ bundler (~> 1.0)
92
+ railties (= 3.2.8)
93
+ railties (3.2.8)
94
+ actionpack (= 3.2.8)
95
+ activesupport (= 3.2.8)
96
+ rack-ssl (~> 1.3.2)
97
+ rake (>= 0.8.7)
98
+ rdoc (~> 3.4)
99
+ thor (>= 0.14.6, < 2.0)
100
+ rake (0.9.2.2)
101
+ rb-fchange (0.0.5)
102
+ ffi
103
+ rb-fsevent (0.9.1)
104
+ rb-inotify (0.8.8)
105
+ ffi (>= 0.5.0)
106
+ rdoc (3.12)
107
+ json (~> 1.4)
108
+ rspec (2.11.0)
109
+ rspec-core (~> 2.11.0)
110
+ rspec-expectations (~> 2.11.0)
111
+ rspec-mocks (~> 2.11.0)
112
+ rspec-core (2.11.1)
113
+ rspec-expectations (2.11.2)
114
+ diff-lcs (~> 1.1.3)
115
+ rspec-mocks (2.11.2)
116
+ rspec-rails (2.11.0)
117
+ actionpack (>= 3.0)
118
+ activesupport (>= 3.0)
119
+ railties (>= 3.0)
120
+ rspec (~> 2.11.0)
121
+ rubyzip (0.9.9)
122
+ selenium-webdriver (2.25.0)
123
+ childprocess (>= 0.2.5)
124
+ libwebsocket (~> 0.1.3)
125
+ multi_json (~> 1.0)
126
+ rubyzip
127
+ spork (0.9.2)
128
+ sprockets (2.1.3)
129
+ hike (~> 1.2)
130
+ rack (~> 1.0)
131
+ tilt (~> 1.1, != 1.3.0)
132
+ sqlite3 (1.3.6)
133
+ thor (0.16.0)
134
+ tilt (1.3.3)
135
+ treetop (1.4.10)
136
+ polyglot
137
+ polyglot (>= 0.3.1)
138
+ tzinfo (0.3.33)
139
+ xpath (0.1.4)
140
+ nokogiri (~> 1.3)
141
+
142
+ PLATFORMS
143
+ ruby
144
+
145
+ DEPENDENCIES
146
+ bundler (~> 1.1.0)
147
+ capybara (~> 1.1.0)
148
+ guard (~> 1.3.0)
149
+ guard-rspec (~> 1.2.0)
150
+ guard-spork (~> 1.1.0)
151
+ jeweler (~> 1.8.4)
152
+ rails (~> 3.2.0)
153
+ rdoc (~> 3.12)
154
+ rspec-rails (~> 2.11.0)
155
+ sqlite3 (~> 1.3.0)
@@ -0,0 +1,37 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
5
+ watch('config/application.rb')
6
+ watch('config/environment.rb')
7
+ watch('config/environments/test.rb')
8
+ watch(%r{^config/initializers/.+\.rb$})
9
+ watch('Gemfile')
10
+ watch('Gemfile.lock')
11
+ watch('spec/spec_helper.rb') { :rspec }
12
+ watch('test/test_helper.rb') { :test_unit }
13
+ watch(%r{features/support/}) { :cucumber }
14
+ end
15
+
16
+ #guard 'rspec', :version => 2 do
17
+ guard 'rspec', :cli => "--color --drb", :version => 2 do
18
+ watch(%r{^spec/.+_spec\.rb$})
19
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
20
+ watch('spec/spec_helper.rb') { "spec" }
21
+
22
+ # Rails example
23
+ watch(%r{^spec/dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
24
+ watch(%r{^spec/dummy/app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
25
+ watch(%r{^spec/dummy/app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
26
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
27
+ watch('config/routes.rb') { "spec/routing" }
28
+ watch('spec/dummy/app/controllers/application_controller.rb') { "spec/controllers" }
29
+
30
+ # Capybara request specs
31
+ watch(%r{^spec/dummy/app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
32
+
33
+ # Turnip features and steps
34
+ watch(%r{^spec/acceptance/(.+)\.feature$})
35
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
36
+ end
37
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 David DIDIER
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,212 @@
1
+ # address_picker-rails
2
+
3
+ An address picker for Rails with autocompletion and map picking.
4
+ This library is built upon [jquery-addresspicker](https://github.com/sgruhier/jquery-addresspicker) and adds convenient features such as:
5
+
6
+ * integration with the assets pipeline
7
+ * auto loading of the Google Maps API
8
+ * auto discovery of the address picker fields
9
+ * JavaScript object wrappers
10
+ * (TODO) form builders
11
+
12
+ ## Installation
13
+
14
+ Add it to your Gemfile:
15
+
16
+ `gem 'address_picker-rails'`
17
+
18
+ Run the following command to install it:
19
+
20
+ `bundle install`
21
+
22
+ In your JavaScript manifest `application.js` add:
23
+
24
+ `//= require address_picker-rails`
25
+
26
+ Since `jquery-addresspicker` uses jQuery-UI themes, you may use [jquery-ui-themes-rails](https://github.com/fatdude/jquery-ui-themes-rails) instead of defining your own theme:
27
+
28
+ * add to your Gemfile: `gem 'jquery-ui-themes'`
29
+ * add to you CSS manifest `application.css`: ` *= require jquery-ui/<theme_name>`
30
+
31
+ ## Usage
32
+
33
+ You may also refer to this little [demo application](http://address-picker-rails-demo.herokuapp.com) on Heroku.
34
+
35
+ ### Model
36
+
37
+ In your migration:
38
+
39
+ class CreatePonds < ActiveRecord::Migration
40
+ def change
41
+
42
+ create_table :ponds do |t|
43
+
44
+ t.string :address
45
+ t.string :address_latitude
46
+ t.string :address_longitude
47
+ t.string :address_locality
48
+ t.string :address_country
49
+
50
+ t.timestamps
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ In your model:
57
+
58
+ class Pond < ActiveRecord::Base
59
+ attr_accessible :address, :address_latitude, :address_longitude, :address_locality, :address_country
60
+ end
61
+
62
+ ### View
63
+
64
+ Consider the following example:
65
+
66
+ <div class="field">
67
+ <%= f.label :address %><br />
68
+ <%= f.text_field :address, :class => 'address-picker-input' %>
69
+ </div>
70
+
71
+ <div class="field">
72
+ <%= f.label :address_latitude %><br />
73
+ <%= f.text_field :address_latitude, :readonly => true, :class => 'address-picker-latitude' %> </div>
74
+
75
+ <div class="field">
76
+ <%= f.label :address_longitude %><br />
77
+ <%= f.text_field :address_longitude, :readonly => true, :class => 'address-picker-longitude' %>
78
+ </div>
79
+
80
+ <div class="field">
81
+ <%= f.label :address_locality %><br />
82
+ <%= f.text_field :address_locality, :readonly => true, :class => 'address-picker-locality' %>
83
+ </div>
84
+
85
+ <div class="field">
86
+ <%= f.label :address_country %><br />
87
+ <%= f.text_field :address_country, :readonly => true, :class => 'address-picker-country' %>
88
+ </div>
89
+
90
+ <div class="field">
91
+ <%= f.label :address_map %><br />
92
+
93
+ <!-- *** Pay attention to the IDs *** -->
94
+ <div id="pond_address_map_wrapper" class="address-picker-map-wrapper">
95
+ <div class="address-picker-legend">You can drag and drop the marker to the correct location</div>
96
+ <div id="pond_address_map" class="address-picker-map"></div>
97
+ </div>
98
+ </div>
99
+
100
+ #### IDs
101
+
102
+ Pay attention to the IDs of the fields: all related fields must have an ID beginning with the same prefix (here that's `pond_address` since we are using a form builder). The default prefix is `address`.
103
+
104
+ <table>
105
+ <tr>
106
+ <th>ID</th>
107
+ <th>Required</th>
108
+ <th>Read only</th>
109
+ </tr>
110
+ <tr>
111
+ <td>[prefix]</td>
112
+ <td>X</td>
113
+ <td></td>
114
+ </tr>
115
+ <tr>
116
+ <td>[prefix]_latitude</td>
117
+ <td></td>
118
+ <td>X</td>
119
+ </tr>
120
+ <tr>
121
+ <td>[prefix]_longitude</td>
122
+ <td></td>
123
+ <td>X</td>
124
+ </tr>
125
+ <tr>
126
+ <td>[prefix]_locality</td>
127
+ <td></td>
128
+ <td>X</td>
129
+ </tr>
130
+ <tr>
131
+ <td>[prefix]_country</td>
132
+ <td></td>
133
+ <td>X</td>
134
+ </tr>
135
+ <tr>
136
+ <td>[prefix]_map</td>
137
+ <td></td>
138
+ <td>X</td>
139
+ </tr>
140
+ </table>
141
+
142
+ NB: In the above example, the ID of the map field is `pond_address_map` since it's not set by a builder.
143
+
144
+ #### CSS
145
+
146
+ The CSS classes are optional unless you're planning to use the auto-discovery feature (see below).
147
+ If you do, the address field must have the `address-picker-input` class.
148
+
149
+ ### Scripts
150
+
151
+ There are several ways to initialize the address pickers.
152
+
153
+ #### Auto discovery
154
+
155
+ The simplest one is to use auto discovery which:
156
+
157
+ * (optionally) waits for the DOM to be loaded, then
158
+ * searches for all fields having the `address-picker-input` CSS class, then
159
+ * uses each ID of these fields as a prefix to apply an address picker
160
+
161
+ So you can just add to your `application.js` or to your view:
162
+
163
+ AddressPickerRails.Pickers.applyOnReady();
164
+
165
+ You can provide a callback which will be called after each address picker has been applied:
166
+
167
+ AddressPickerRails.Pickers.applyOnReady({
168
+ 'onLoad':function (picker) {
169
+ console.debug("callback for a single pond with ID '%s'", picker.getIdPrefix());
170
+ }
171
+ });
172
+
173
+ The not deferred version:
174
+
175
+ AddressPickerRails.Pickers.apply();
176
+
177
+ #### Manual
178
+
179
+ The ID prefix default is `address`:
180
+
181
+ new AddressPickerRails.Picker().apply();
182
+
183
+ You can use a custom ID prefix:
184
+
185
+ new AddressPickerRails.Picker({idPrefix:"pond_address"}).apply();
186
+
187
+ You can provide a callback which will be called after the address picker has been applied:
188
+
189
+ var picker = new AddressPickerRails.Picker({idPrefix:"pond_address"});
190
+ picker.apply(function (railsPicker) {
191
+ console.debug("callback for a single pond with ID '%s'", railsPicker.getIdPrefix());
192
+ });
193
+
194
+ ## Requirements
195
+
196
+ Tested with Rails 3.2 but it should work with Rails 3.1, or anything that uses the asset pipeline.
197
+
198
+ ## Contributing to address_picker-rails
199
+
200
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
201
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
202
+ * Fork the project.
203
+ * Start a feature/bugfix branch.
204
+ * Commit and push until you are happy with your contribution.
205
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
206
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
207
+
208
+ ## Copyright
209
+
210
+ Copyright (c) 2012 David DIDIER. See LICENSE.txt for further details.
211
+
212
+ [Sébastien Gruhier@https://github.com/sgruhier/jquery-addresspicker](https://github.com/sgruhier/jquery-addresspicker)