administrate-field-lat_lng 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd05f2c706f9d1a5ae17d96579c12b349c4230be
4
+ data.tar.gz: a07039d2a865715cc923912acc850250b05c34ff
5
+ SHA512:
6
+ metadata.gz: f5ab5557ff5a31e1cccff462f9c5b17fb07da9f06780b9ddccf1b15f40bc45513e14c749f8054a296302464a248f5a4ae5cfe6468b560539976077a545592dbe
7
+ data.tar.gz: a939b9f777e3c8c53ed6daf77235cf7822a240b9b1a8e3bc008f8f3e0db44a356d5ad625bf3952b1f6a9687642b92122c731a394477db506c5ce79bdf7b56232
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - 2.1.9
6
+ before_install: gem install bundler -v 1.12.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at rich@fishpercolator.co.uk. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in administrate-field-select.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rich Daley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Administrate::Field::LatLng
2
+
3
+ Adds fields for displaying/editing latitude/longitude fields on a map to ThoughtBot's [Administrate](https://github.com/thoughtbot/administrate)
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/administrate-field-lat_lng.svg?style=flat)](https://rubygems.org/gems/administrate-field-lat_lng)
6
+ [![Build Status](https://img.shields.io/travis/fishpercolator/administrate-field-lat_lng/master.svg?style=flat)](https://travis-ci.org/fishpercolator/administrate-field-lat_lng)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'administrate-field-lat_lng'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ **Note for Administrate 0.2.0 users**: This gem depends on Administrate's `content_for :stylesheet` which, at the time of writing, has not yet been released. If 0.2.0 is still the latest version, you'll want to update your Gemfile to point at the bleeding-edge of Administrate:
21
+
22
+ ```ruby
23
+ gem 'administrate', '~> 0.2.0', github: 'thoughtbot/administrate'
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ In your dashboard's `ATRRIBUTE_TYPES`, use the type `Field::LatLng` with options:
29
+
30
+ ```ruby
31
+ ATTRIBUTE_TYPES = {
32
+ lat: Field::LatLng,
33
+ lng: Field::LatLng,
34
+ }
35
+ ```
36
+
37
+ On show pages, you will now see a map directly below the `lng` field, which shows the location on a map. On edit pages, you can click this map to change the values of `lat` and `lng` in the form.
38
+
39
+ **Important**: Your `lat` and `lng` fields must appear in the right order (`lat` first) in `SHOW_PAGE_ATTRIBUTES` and `FORM_ATTRIBUTES`. This is because each field generates a piece of the final javascript so they must be evaluated in the correct order.
40
+
41
+ If your fields are not called `lat` and `lng`, you must specify options to make it clear which is which, e.g.:
42
+
43
+ ```ruby
44
+ ATTRIBUTE_TYPES = {
45
+ latitude: Field::LatLng.with_options({lat: true}),
46
+ longitude: Field::LatLng.with_options({lng: true}),
47
+ }
48
+ ```
49
+
50
+ Additional options that are available:
51
+
52
+ * `initial`: Set to an array like `[53.8003,-1.5519]`. Will cause the center of the map to be this point if the lat/lng have not yet been set (e.g. for new records). Defaults to Leeds, UK (because that's where the author is from).
53
+ * `zoom`: Set the default zoom level for maps drawn (defaults to 11).
54
+
55
+ ## Usage notes
56
+
57
+ This gem depends on being able to access `cdn.leafletjs.com` for the Leaflet JS and CSS. Let me know if you want this to change and be based on the asset pipeline.
58
+
59
+ Currently you can only have one pair of lat/lng per model type. Supporting multiple pairs would not be hard, so let me know if you need that functionality.
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fishpercolator/administrate-field-lat_lng. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
68
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "administrate-field-lat_lng"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["Rich Daley"]
9
+ spec.email = ["rich@fishpercolator.co.uk"]
10
+
11
+ spec.summary = %q{Administrate field for latitude/longitude}
12
+ spec.description = %q{Adds an Administrate::Field::LatLng for viewing & editing latitude/longitude fields on a map}
13
+ spec.homepage = "https://github.com/fishpercolator/administrate-field-lat_lng"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'administrate', '~> 0.2.0'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", "~> 0.10.3"
26
+ end
@@ -0,0 +1,9 @@
1
+ <%= render 'fields/lat_lng/includes' if field.lng? %>
2
+ <div class="field-unit__label">
3
+ <%= f.label field.attribute %>
4
+ </div>
5
+ <div class="field-unit__field">
6
+ <%= f.text_field field.attribute, class: "latlng-#{field.which}" %>
7
+ </div>
8
+ <%= render 'fields/lat_lng/var', field: field %>
9
+ <%= render 'fields/lat_lng/map', edit: true, field: field if field.lng? %>
@@ -0,0 +1,23 @@
1
+ <% content_for :stylesheet do %>
2
+ <link rel="stylesheet" href="<%= Administrate::Field::LatLng::CSS_URL %>" />
3
+ <style text="text/css">
4
+ .field-unit {
5
+ flex-flow: row wrap;
6
+ }
7
+ .map-container {
8
+ clear: both;
9
+ width: 100%;
10
+ }
11
+ #latlngmap {
12
+ margin-top: 1.5em;
13
+ width: 500px;
14
+ height: 500px;
15
+ }
16
+ .field-unit #latlngmap {
17
+ margin-left: 17.0596086%;
18
+ }
19
+ </style>
20
+ <% end %>
21
+ <% content_for :javascript do %>
22
+ <script src="<%= Administrate::Field::LatLng::JS_URL %>"></script>
23
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= field.to_s %>
@@ -0,0 +1,44 @@
1
+ <div class="map-container">
2
+ <div id="latlngmap"></div>
3
+ </div>
4
+ <% content_for :javascript do %>
5
+ <script type="text/javascript">
6
+ // Attach a leaflet.js map to the div above
7
+ var map = L.map('latlngmap');
8
+ var osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
9
+ attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
10
+ });
11
+ map.addLayer(osm);
12
+
13
+ // Get the centre lat/lng from the field or the initial default if the field
14
+ // hasn't been set yet
15
+ var latlng = [];
16
+ if (lng === undefined) {
17
+ latlng = <%= field.initial.to_json %>;
18
+ } else {
19
+ latlng = [lat, lng];
20
+ }
21
+ map.setView(latlng, <%= field.zoom %>);
22
+
23
+ // Add a marker if the field has been set already
24
+ var marker;
25
+ if (lng !== undefined) {
26
+ marker = L.marker(latlng);
27
+ marker.addTo(map);
28
+ }
29
+ <% if edit %>
30
+ // In edit mode, move the marker and update the fields when a user clicks
31
+ // inside the map
32
+ map.on('click', function (e) {
33
+ if (marker === undefined) {
34
+ marker = L.marker(e.latlng);
35
+ marker.addTo(map);
36
+ } else {
37
+ marker.setLatLng(e.latlng);
38
+ }
39
+ $('.latlng-lat').val(e.latlng.lat);
40
+ $('.latlng-lng').val(e.latlng.lng);
41
+ });
42
+ <% end %>
43
+ </script>
44
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <%= render 'fields/lat_lng/includes' if field.lat? %>
2
+ <%= field.to_s %>
3
+ <%= render 'fields/lat_lng/var', field: field %>
4
+ <%= render 'fields/lat_lng/map', edit: false, field: field if field.lng? %>
@@ -0,0 +1,5 @@
1
+ <% content_for :javascript do %>
2
+ <script type="text/javascript">
3
+ var <%= field.which %> = <%= field.data || 'undefined' %>;
4
+ </script>
5
+ <% end %>
@@ -0,0 +1,44 @@
1
+ require 'administrate/field/base'
2
+ require 'rails'
3
+
4
+ module Administrate
5
+ module Field
6
+ class LatLng < Base
7
+ class Engine < ::Rails::Engine
8
+ end
9
+
10
+ JS_URL = "http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"
11
+ CSS_URL = "http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"
12
+
13
+ # True if the :lat option has been provided, or field is called :lat
14
+ def lat?
15
+ options.fetch(:lat, attribute == :lat)
16
+ end
17
+
18
+ # True if the :lng option has been provided, or field is called :lng
19
+ def lng?
20
+ options.fetch(:lng, attribute == :lng)
21
+ end
22
+
23
+ # Returns :lat or :lng depending on which type this is
24
+ def which
25
+ lat? ? :lat : :lng
26
+ end
27
+
28
+ # Returns the initial co-ordinates of blank maps (defaults to Leeds, UK)
29
+ def initial
30
+ options.fetch(:initial, [53.8003,-1.5519])
31
+ end
32
+
33
+ # Returns the initial zoom level for maps (defaults to 11)
34
+ def zoom
35
+ options.fetch(:zoom, 11)
36
+ end
37
+
38
+ def to_s
39
+ data
40
+ end
41
+
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-lat_lng
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rich Daley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: administrate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.3
83
+ description: Adds an Administrate::Field::LatLng for viewing & editing latitude/longitude
84
+ fields on a map
85
+ email:
86
+ - rich@fishpercolator.co.uk
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - administrate-field-lat_lng.gemspec
100
+ - app/views/fields/lat_lng/_form.html.erb
101
+ - app/views/fields/lat_lng/_includes.html.erb
102
+ - app/views/fields/lat_lng/_index.html.erb
103
+ - app/views/fields/lat_lng/_map.html.erb
104
+ - app/views/fields/lat_lng/_show.html.erb
105
+ - app/views/fields/lat_lng/_var.html.erb
106
+ - lib/administrate/field/lat_lng.rb
107
+ homepage: https://github.com/fishpercolator/administrate-field-lat_lng
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Administrate field for latitude/longitude
131
+ test_files: []