geofsh 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/geofsh.gemspec +2 -2
- data/lib/geofsh/version.rb +1 -1
- data/testapp/.rspec +1 -0
- data/testapp/Gemfile +7 -1
- data/testapp/app/assets/stylesheets/main.css +4 -0
- data/testapp/app/views/home/index.html.erb +5 -0
- data/testapp/spec/controllers/home_controller_spec.rb +12 -0
- data/testapp/spec/requests/home_spec.rb +22 -0
- data/testapp/spec/spec_helper.rb +38 -0
- data/vendor/assets/javascripts/geofsh.js +34 -10
- metadata +12 -13
- data/testapp/test/fixtures/.gitkeep +0 -0
- data/testapp/test/functional/.gitkeep +0 -0
- data/testapp/test/integration/.gitkeep +0 -0
- data/testapp/test/performance/browsing_test.rb +0 -12
- data/testapp/test/test_helper.rb +0 -13
- data/testapp/test/unit/.gitkeep +0 -0
- data/vendor/assets/javascripts/geofsh.js.coffee +0 -22
data/README.md
CHANGED
@@ -29,6 +29,19 @@ An example of using Geofsh with simple_form:
|
|
29
29
|
= f.input :geolat, label: "Latitude", input_html: { id: "latitude", class: "geoloc-hide" }
|
30
30
|
= f.input :geolng, label: "Longitude", input_html: { id: "longitude", class: "geoloc-hide" }
|
31
31
|
|
32
|
+
|
33
|
+
Google maps can easily be incorporated into your rails app using geofsh gem. First, you must include google's javascript api:
|
34
|
+
|
35
|
+
= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&sensor=false"
|
36
|
+
|
37
|
+
For instructions on how to recieve a google map's API key, visit [Google's api tutorial](https://developers.google.com/maps/documentation/javascript/tutorial#api_key).
|
38
|
+
|
39
|
+
To enable google maps in your rails app, simply add a div to your view with the element id 'google-map':
|
40
|
+
|
41
|
+
<div id='google-map'/>
|
42
|
+
|
43
|
+
Geofsh gem will automatically populate this div with a google map centered on your current latitude and longitude.
|
44
|
+
|
32
45
|
Before deploying to production, you must also add 'geofsh.js' to the precompile list in your config/application.rb:
|
33
46
|
|
34
47
|
config.assets.precompile += %w(foo bar geofsh.js)
|
data/geofsh.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Geofsh::VERSION
|
9
9
|
gem.authors = ["Jon Pagano"]
|
10
10
|
gem.email = ["jonathanpagano@gmail.com"]
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{Provides latitude and longitude from HTML5 API}
|
11
|
+
gem.description = %q{Geolocation Form Submission Helper}
|
12
|
+
gem.summary = %q{Provides latitude and longitude from HTML5 geolocation API and automatically places them in corresponding form fields}
|
13
13
|
gem.homepage = "https://github.com/joofsh/geofsh"
|
14
14
|
|
15
15
|
gem.add_dependency "railties", "~> 3.1"
|
data/lib/geofsh/version.rb
CHANGED
data/testapp/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/testapp/Gemfile
CHANGED
@@ -6,7 +6,7 @@ gem 'rails', '3.2.8'
|
|
6
6
|
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
7
|
|
8
8
|
gem 'sqlite3'
|
9
|
-
gem 'geofsh'
|
9
|
+
gem 'geofsh', path: '..'
|
10
10
|
|
11
11
|
# Gems used only for assets and not required
|
12
12
|
# in production environments by default.
|
@@ -22,6 +22,12 @@ end
|
|
22
22
|
|
23
23
|
gem 'jquery-rails'
|
24
24
|
|
25
|
+
|
26
|
+
group :test, :development do
|
27
|
+
gem 'capybara'
|
28
|
+
gem 'rspec-rails'
|
29
|
+
end
|
30
|
+
|
25
31
|
# To use ActiveModel has_secure_password
|
26
32
|
# gem 'bcrypt-ruby', '~> 3.0.0'
|
27
33
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=AIzaSyDBmbRrJZrO5IExRamjDLBgyWzTLs1Ohx8&sensor=false" %>
|
1
2
|
<%= javascript_include_tag 'geofsh' %>
|
2
3
|
|
3
4
|
<p> This is your latitude and longitude input fields. Are they working? </p>
|
@@ -5,3 +6,7 @@
|
|
5
6
|
<%= text_field_tag 'latitude', nil, :class => 'geoloc-hide' %>
|
6
7
|
<%= label_tag :Longitude %>
|
7
8
|
<%= text_field_tag 'longitude', nil, :class => 'geoloc-hide' %>
|
9
|
+
|
10
|
+
<p> This is your google map of the above coordinates </p>
|
11
|
+
|
12
|
+
<div id='google-map'/>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
@javascript
|
3
|
+
|
4
|
+
describe 'Home Requests' do
|
5
|
+
before :each do
|
6
|
+
visit '/'
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
it 'loads geofsh lat/lng data into fields', js: true do
|
11
|
+
find_field('latitude').value.should_not be_blank
|
12
|
+
find_field('longitude').value.should_not be_blank
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'loads a google map', js: true do
|
16
|
+
page.should have_selector "div#google-map"
|
17
|
+
page.should have_selector "div", text: "Satellite"
|
18
|
+
page.should have_selector "img", src: "https://maps.gstatic.com/mapfiles/google_white.png"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# ## Mock Framework
|
13
|
+
#
|
14
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
15
|
+
#
|
16
|
+
# config.mock_with :mocha
|
17
|
+
# config.mock_with :flexmock
|
18
|
+
# config.mock_with :rr
|
19
|
+
|
20
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
21
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
22
|
+
|
23
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
24
|
+
# examples within a transaction, remove the following line or assign false
|
25
|
+
# instead of true.
|
26
|
+
config.use_transactional_fixtures = true
|
27
|
+
|
28
|
+
# If true, the base class of anonymous controllers will be inferred
|
29
|
+
# automatically. This will be the default behavior in future versions of
|
30
|
+
# rspec-rails.
|
31
|
+
config.infer_base_class_for_anonymous_controllers = false
|
32
|
+
|
33
|
+
# Run specs in random order to surface order dependencies. If you find an
|
34
|
+
# order dependency and want to debug it, you can fix the order by providing
|
35
|
+
# the seed, which is printed after each run.
|
36
|
+
# --seed 1234
|
37
|
+
config.order = "random"
|
38
|
+
end
|
@@ -1,8 +1,32 @@
|
|
1
|
-
var geolocError, getPosition, hideAddressAndZip, hideGeoLoc, geolocSuccess;
|
1
|
+
var geolocError, addMarker, getPosition, hideAddressAndZip, hideGeoLoc, geolocSuccess, googleMap, mapOptions, map, marker, geolat, geolng, geoCoords;
|
2
|
+
|
3
|
+
googleMap = function(geolat, geolng) {
|
4
|
+
if(document.getElementById("google-map")){
|
5
|
+
geoCoords = new google.maps.LatLng(geolat, geolng);
|
6
|
+
mapOptions = {
|
7
|
+
zoom: 16,
|
8
|
+
center: geoCoords,
|
9
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP
|
10
|
+
};
|
11
|
+
|
12
|
+
map = new google.maps.Map(document.getElementById("google-map"), mapOptions);
|
13
|
+
addMarker(geoCoords, "You are here!");
|
14
|
+
}
|
15
|
+
};
|
2
16
|
|
17
|
+
addMarker = function(position, title) {
|
18
|
+
marker = new google.maps.Marker({
|
19
|
+
position: position,
|
20
|
+
map: map,
|
21
|
+
title: title
|
22
|
+
});
|
23
|
+
}
|
3
24
|
geolocSuccess = function(position) {
|
4
|
-
|
5
|
-
|
25
|
+
geolat = position.coords.latitude;
|
26
|
+
geolng = position.coords.longitude;
|
27
|
+
$('input#latitude').val(geolat);
|
28
|
+
$('input#longitude').val(geolng);
|
29
|
+
return googleMap(geolat, geolng);
|
6
30
|
};
|
7
31
|
|
8
32
|
geolocError = function() {
|
@@ -16,16 +40,16 @@ return $('.geoloc-hide').parent().hide();
|
|
16
40
|
};
|
17
41
|
|
18
42
|
getPosition = function() {
|
19
|
-
if (navigator.geolocation) {
|
20
|
-
return navigator.geolocation.getCurrentPosition(geolocSuccess, geolocError);
|
21
|
-
} else {
|
22
|
-
hideGeoLoc();
|
23
|
-
return "Geolocation not supported";
|
24
|
-
}
|
43
|
+
if (navigator.geolocation) {
|
44
|
+
return navigator.geolocation.getCurrentPosition(geolocSuccess, geolocError);
|
45
|
+
} else {
|
46
|
+
hideGeoLoc();
|
47
|
+
return "Geolocation not supported";
|
48
|
+
}
|
25
49
|
};
|
26
50
|
|
27
51
|
|
28
52
|
$(function() {
|
29
|
-
|
53
|
+
return getPosition();
|
30
54
|
});
|
31
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geofsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.1'
|
30
|
-
description:
|
30
|
+
description: Geolocation Form Submission Helper
|
31
31
|
email:
|
32
32
|
- jonathanpagano@gmail.com
|
33
33
|
executables: []
|
@@ -43,12 +43,14 @@ files:
|
|
43
43
|
- lib/geofsh.rb
|
44
44
|
- lib/geofsh/version.rb
|
45
45
|
- testapp/.gitignore
|
46
|
+
- testapp/.rspec
|
46
47
|
- testapp/Gemfile
|
47
48
|
- testapp/README.rdoc
|
48
49
|
- testapp/Rakefile
|
49
50
|
- testapp/app/assets/images/rails.png
|
50
51
|
- testapp/app/assets/javascripts/application.js
|
51
52
|
- testapp/app/assets/stylesheets/application.css
|
53
|
+
- testapp/app/assets/stylesheets/main.css
|
52
54
|
- testapp/app/controllers/application_controller.rb
|
53
55
|
- testapp/app/controllers/home_controller.rb
|
54
56
|
- testapp/app/helpers/application_helper.rb
|
@@ -83,17 +85,13 @@ files:
|
|
83
85
|
- testapp/public/favicon.ico
|
84
86
|
- testapp/public/robots.txt
|
85
87
|
- testapp/script/rails
|
86
|
-
- testapp/
|
87
|
-
- testapp/
|
88
|
-
- testapp/
|
89
|
-
- testapp/test/performance/browsing_test.rb
|
90
|
-
- testapp/test/test_helper.rb
|
91
|
-
- testapp/test/unit/.gitkeep
|
88
|
+
- testapp/spec/controllers/home_controller_spec.rb
|
89
|
+
- testapp/spec/requests/home_spec.rb
|
90
|
+
- testapp/spec/spec_helper.rb
|
92
91
|
- testapp/vendor/assets/javascripts/.gitkeep
|
93
92
|
- testapp/vendor/assets/stylesheets/.gitkeep
|
94
93
|
- testapp/vendor/plugins/.gitkeep
|
95
94
|
- vendor/assets/javascripts/geofsh.js
|
96
|
-
- vendor/assets/javascripts/geofsh.js.coffee
|
97
95
|
homepage: https://github.com/joofsh/geofsh
|
98
96
|
licenses: []
|
99
97
|
post_install_message:
|
@@ -108,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
106
|
version: '0'
|
109
107
|
segments:
|
110
108
|
- 0
|
111
|
-
hash:
|
109
|
+
hash: 3450935956358020349
|
112
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
111
|
none: false
|
114
112
|
requirements:
|
@@ -117,11 +115,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
115
|
version: '0'
|
118
116
|
segments:
|
119
117
|
- 0
|
120
|
-
hash:
|
118
|
+
hash: 3450935956358020349
|
121
119
|
requirements: []
|
122
120
|
rubyforge_project:
|
123
121
|
rubygems_version: 1.8.24
|
124
122
|
signing_key:
|
125
123
|
specification_version: 3
|
126
|
-
summary: Provides latitude and longitude from HTML5 API
|
124
|
+
summary: Provides latitude and longitude from HTML5 geolocation API and automatically
|
125
|
+
places them in corresponding form fields
|
127
126
|
test_files: []
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rails/performance_test_help'
|
3
|
-
|
4
|
-
class BrowsingTest < ActionDispatch::PerformanceTest
|
5
|
-
# Refer to the documentation for all available options
|
6
|
-
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
7
|
-
# :output => 'tmp/performance', :formats => [:flat] }
|
8
|
-
|
9
|
-
def test_homepage
|
10
|
-
get '/'
|
11
|
-
end
|
12
|
-
end
|
data/testapp/test/test_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path('../../config/environment', __FILE__)
|
3
|
-
require 'rails/test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
-
#
|
8
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
-
# -- they do not yet inherit this setting
|
10
|
-
fixtures :all
|
11
|
-
|
12
|
-
# Add more helper methods to be used by all tests here...
|
13
|
-
end
|
data/testapp/test/unit/.gitkeep
DELETED
File without changes
|
@@ -1,22 +0,0 @@
|
|
1
|
-
geolocSuccess = (position) ->
|
2
|
-
geolat = position.coords.latitude
|
3
|
-
geolng = position.coords.longitude
|
4
|
-
$("input#latitude").val geolat
|
5
|
-
$("input#longitude").val geolng
|
6
|
-
|
7
|
-
geolocError = ->
|
8
|
-
hideGeoLoc()
|
9
|
-
"Geolocation Unsuccessful"
|
10
|
-
|
11
|
-
hideGeoLoc = ->
|
12
|
-
$(".geoloc-hide").parent().hide()
|
13
|
-
|
14
|
-
getPosition = ->
|
15
|
-
if navigator.geolocation
|
16
|
-
navigator.geolocation.getCurrentPosition geolocSuccess, geolocError
|
17
|
-
else
|
18
|
-
hideGeoLoc()
|
19
|
-
"Geolocation not supported"
|
20
|
-
|
21
|
-
$ ->
|
22
|
-
getPosition()
|