scaffold_plus 1.4.16 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +2 -2
- data/README.md +22 -0
- data/lib/generators/scaffold_plus/geocoder/geocoder_generator.rb +60 -0
- data/lib/generators/scaffold_plus/geocoder_init/geocoder_init_generator.rb +18 -0
- data/lib/generators/scaffold_plus/geocoder_init/templates/geocoder.rb +12 -0
- data/lib/scaffold_plus/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68734750146a32a30b34dd4ac662f7e4f8338087
|
4
|
+
data.tar.gz: c0b6a9ec6c80f13618837257cd0b36b6ce88c8f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284a0a8fabf17966663bc38281fedd8f04d6bcd8828eb47303db1b128c22ef6a8f62de0d10a1bf6a50cb2ecc878859d62800d860636ae36b3161018093cc668c
|
7
|
+
data.tar.gz: fbb087f7decee500fa94b2c25012921424cf168eae4a3216c63b01e2c26679884c297b5578760344c15277dcd329dea055a143b8b15f8172ed7e350a2a61bcb9
|
data/Makefile
CHANGED
@@ -9,15 +9,15 @@ all: build
|
|
9
9
|
rel: build
|
10
10
|
vim lib/scaffold_plus/version.rb
|
11
11
|
git commit -a
|
12
|
-
rake release
|
13
12
|
sudo gem uninstall scaffold_plus --all
|
14
|
-
|
13
|
+
rake release
|
15
14
|
|
16
15
|
|
17
16
|
install: build
|
18
17
|
git commit -a
|
19
18
|
sudo gem uninstall scaffold_plus --all
|
20
19
|
sudo rake install
|
20
|
+
sudo rm -rf pkg
|
21
21
|
|
22
22
|
build:
|
23
23
|
git add lib
|
data/README.md
CHANGED
@@ -50,6 +50,28 @@ and accepts_nested_attributes_for in one of the parents.
|
|
50
50
|
This helper scaffolds a has_and_belongs_to_many relationship with migration
|
51
51
|
and updates to the models.
|
52
52
|
|
53
|
+
### Set the autofocus flag on a column
|
54
|
+
rails generate scaffold_plus:autofocus
|
55
|
+
|
56
|
+
This helper adds "autofocus: true" to an input field in the form view.
|
57
|
+
|
58
|
+
### Add geo location to resource
|
59
|
+
rails generate scaffold_plus:geocoder_init
|
60
|
+
rails generate scaffold_plus:geocoder
|
61
|
+
|
62
|
+
These helpers need the [geocoder](http://www.rubygeocoder.com) gem.
|
63
|
+
|
64
|
+
The first helper creates an initializer for geocoder. It supports the
|
65
|
+
language (default 'de'), timeout (default 5) and units (default km)
|
66
|
+
options.
|
67
|
+
|
68
|
+
The second one adds geolocating to a resource. It uses Google geocoding
|
69
|
+
and requires 'lat', 'lng' and 'address' attributes (the names can be
|
70
|
+
changed via options). If a '--country' flag is added, the helper
|
71
|
+
tries to isolate the country from the address and stores the country
|
72
|
+
code (e.g. DE or NL) in a given 'country' attribute. This is currently
|
73
|
+
only implemented for Germany (DE).
|
74
|
+
|
53
75
|
## Testing
|
54
76
|
|
55
77
|
Since I have no experience with test driven development (yet), this is
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ScaffoldPlus
|
4
|
+
module Generators
|
5
|
+
class GeocoderGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Add GeoLocation to resource (requires geocoder gem)"
|
7
|
+
argument :name, type: :string,
|
8
|
+
desc: "The object to be geocoded"
|
9
|
+
class_option :address, type: :string, default: "address",
|
10
|
+
desc: 'Attribute used for geocoding'
|
11
|
+
class_option :latitude, type: :string, default: "lat",
|
12
|
+
desc: 'Attribute used for storing latitude'
|
13
|
+
class_option :longitude, type: :string, default: "lng",
|
14
|
+
desc: 'Attribute used for storing longitude'
|
15
|
+
class_option :country, type: :boolean, default: false,
|
16
|
+
desc: 'Isolate country into separate attribute'
|
17
|
+
class_option :before, type: :boolean, default: false,
|
18
|
+
desc: 'Add a line before generated text in model'
|
19
|
+
class_option :after, type: :boolean, default: false,
|
20
|
+
desc: 'Add a line after generated text in model'
|
21
|
+
source_root File.expand_path('../templates', __FILE__)
|
22
|
+
|
23
|
+
def update_model
|
24
|
+
geocoded = " geocoded_by :#{options.address}"
|
25
|
+
geocoded << ", latitude: :#{options.latitude}"
|
26
|
+
geocoded << ", longitude: :#{options.longitude}"
|
27
|
+
if options.country?
|
28
|
+
geocoded << " do |obj,results|"
|
29
|
+
country = [
|
30
|
+
" if geo = results.first",
|
31
|
+
" # puts JSON.pretty_generate(geo.as_json)",
|
32
|
+
" if geo.country_code.upcase == 'DE'",
|
33
|
+
" obj.country = 'DE'",
|
34
|
+
" obj.address = geo.address.gsub(/, Deutschland/, '')",
|
35
|
+
" obj.#{options.latitude} = geo.latitude",
|
36
|
+
" obj.#{options.longitude} = geo.longitude",
|
37
|
+
" end",
|
38
|
+
" end",
|
39
|
+
" end"
|
40
|
+
]
|
41
|
+
else
|
42
|
+
country = []
|
43
|
+
end
|
44
|
+
lines = options.before? ? [ "\n" ] : []
|
45
|
+
lines << [
|
46
|
+
geocoded,
|
47
|
+
country,
|
48
|
+
" after_validation :geocode" +
|
49
|
+
", if: ->(obj){ obj.#{options.address}.present?" +
|
50
|
+
" and obj.#{options.address}_changed? }",
|
51
|
+
""
|
52
|
+
]
|
53
|
+
lines << "\n" if options.after?
|
54
|
+
inject_into_class "app/models/#{name}.rb", class_name do
|
55
|
+
lines.flatten.join("\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ScaffoldPlus
|
2
|
+
module Generators
|
3
|
+
class GeocoderInitGenerator < Rails::Generators::Base
|
4
|
+
desc "Generate an initializer for the geocoder gem"
|
5
|
+
class_option :language, type: :string, default: "de",
|
6
|
+
desc: 'Language of the interface'
|
7
|
+
class_option :timeout, type: :string, default: "5",
|
8
|
+
desc: 'Lookup timeout in seconds'
|
9
|
+
class_option :units, type: :string, default: "km",
|
10
|
+
desc: 'Define distance units (miles, km)'
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
def add_initializer
|
14
|
+
template "geocoder.rb", "config/initializers/geocoder.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Geocoder.configure(
|
2
|
+
# geocoding options
|
3
|
+
:lookup => :google,
|
4
|
+
:language => :<%= options.language %>,
|
5
|
+
:timeout => <%= options.timeout %>,
|
6
|
+
# :cache => Redis.new,
|
7
|
+
# :cache_prefix => 'geocoder:',
|
8
|
+
|
9
|
+
# calculation options
|
10
|
+
:units => :<%= options.units %>,
|
11
|
+
:distances => :spherical
|
12
|
+
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffold_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -85,6 +85,9 @@ files:
|
|
85
85
|
- lib/generators/scaffold_plus/collection/collection_generator.rb
|
86
86
|
- lib/generators/scaffold_plus/collection/templates/view.html.erb
|
87
87
|
- lib/generators/scaffold_plus/force_ssl/force_ssl_generator.rb
|
88
|
+
- lib/generators/scaffold_plus/geocoder/geocoder_generator.rb
|
89
|
+
- lib/generators/scaffold_plus/geocoder_init/geocoder_init_generator.rb
|
90
|
+
- lib/generators/scaffold_plus/geocoder_init/templates/geocoder.rb
|
88
91
|
- lib/generators/scaffold_plus/habtm/habtm_generator.rb
|
89
92
|
- lib/generators/scaffold_plus/habtm/templates/habtm_migration.rb
|
90
93
|
- lib/generators/scaffold_plus/has_many/has_many_generator.rb
|
@@ -117,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
120
|
version: '0'
|
118
121
|
requirements: []
|
119
122
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.4.
|
123
|
+
rubygems_version: 2.4.2
|
121
124
|
signing_key:
|
122
125
|
specification_version: 4
|
123
126
|
summary: A collection of little helpers for Rails scaffolding
|