geoloc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fdb83e11bfe29c91c9f20ffb1867a7def07ed5be
4
+ data.tar.gz: ca9a72d688bed75d3e7b66976264576978e08c03
5
+ SHA512:
6
+ metadata.gz: 12a33a86a13cd85b39bc3f2859f8118896d15cb345b47e5c70e1be495891039ca1a6a54a0a5f3563353bcf82b9b59fa77b876185def1dfe421caf3634e3cea2b
7
+ data.tar.gz: b71416c6af94c9e32a5d4deb331abcd44dc0fd8e2db4ab606a53e66923c9406a95f49ffb5e8d261aadd89f3e7ba305fa3096ce8774846f5fd7bfa7f41f3b7469
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geoloc.gemspec
4
+ gemspec
@@ -0,0 +1,63 @@
1
+ # Geoloc
2
+
3
+ Geoloc allows you to add HTML5 Geolocation in your views without dealing with javascript. Geoloc offers customizable helper methods to add custom geolocation requests that can later send back the coordinates to your server
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'geoloc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install geoloc
20
+
21
+ ## Usage
22
+
23
+ Simple button with post request
24
+
25
+ ```erb
26
+ <%= get_geoloc_button route, id, message %>
27
+ ```
28
+
29
+ Where route is the route where the javascript will submit the post request with the coordinates,
30
+ id is the id of the html element that is gonna output the server response and message is the button text (id and message are optional).
31
+
32
+
33
+
34
+ ```erb
35
+ <%= get_geoloc_onload route, id %>
36
+ ```
37
+
38
+ Submits a post requests with the coordinates after loading the window, without any user interaction
39
+
40
+ Where route is the route where the javascript will submit the post request with the coordinates,
41
+ id is the id of the html element that is gonna output the server response (id is optional).
42
+
43
+ Add coordinates to form
44
+
45
+ ```erb
46
+ <%= get_geoloc_form %>
47
+ ```
48
+
49
+ This helper adds the coordinates to a form with hidden_fields with ids :geoloc_latitude, and :geoloc_longitude. Those parameters get sent to the server when the user submits the form. Id's of the hidden_fields must match the previous.
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/legendss/geoloc/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
File without changes
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geoloc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geoloc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geoloc"
8
+ spec.version = Geoloc::VERSION
9
+ spec.authors = ["David Lorente, Inga Nikitina"]
10
+ spec.email = ["david.l.castilla@gmail.com"]
11
+ spec.summary = %q{Geoloc allows you to add HTML5 Geolocation in your views without dealing with javascript. }
12
+ spec.description = %q{Geoloc allows you to add HTML5 Geolocation in your views without dealing with javascript. Geoloc offers customizable helper methods to add custom geolocation requests that can later send back the coordinates to your server}
13
+ spec.homepage = "https://github.com/legendss/geoloc"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "geoloc/version"
2
+ require "geoloc/helper"
3
+ require "geoloc/rails" if defined?(Rails)
4
+ require "geoloc/sinatra" if defined?(Sinatra)
5
+
6
+ module Geoloc
7
+
8
+ end
@@ -0,0 +1,14 @@
1
+ module Geoloc
2
+ class Engine < ::Rails::Engine
3
+ initializer "precompile", group: :all do |app|
4
+ # use a proc instead of a string
5
+ app.config.assets.precompile << proc { |path| path == "geoloc.js" }
6
+ end
7
+
8
+ initializer "helper" do
9
+ ActiveSupport.on_load(:action_view) do
10
+ include Helper
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,89 @@
1
+
2
+ module Geoloc
3
+ module Helper
4
+ def get_geoloc_button(route, id=nil, message = "<3 Geoloc")
5
+ html = <<-HTML
6
+ <button onclick="getLocation()">#{message}</button>
7
+
8
+ <script>
9
+ var x = document.getElementById("#{id}");
10
+
11
+ function getLocation() {
12
+ if (navigator.geolocation) {
13
+ navigator.geolocation.getCurrentPosition(showPosition);
14
+ } else {
15
+ x.innerHTML = "Geolocation is not supported by this browser.";
16
+ }
17
+ }
18
+
19
+ function showPosition(position) {
20
+
21
+ $.post( "#{route}", { data: position })
22
+ .done(function( data ) {
23
+ x.innerHTML = data.data;
24
+ });
25
+ }
26
+ </script>
27
+ HTML
28
+ raw html
29
+ end
30
+
31
+
32
+ def get_geoloc_onload(route, id=nil)
33
+ html = <<-HTML
34
+
35
+ <script>
36
+ var x = document.getElementById("#{id}");
37
+
38
+ function getLocation() {
39
+ if (navigator.geolocation) {
40
+ navigator.geolocation.getCurrentPosition(showPosition);
41
+ } else {
42
+ x.innerHTML = "Geolocation is not supported by this browser.";
43
+ }
44
+ }
45
+
46
+ function showPosition(position) {
47
+
48
+ $.post( "#{route}", { data: position })
49
+ .done(function( data ) {
50
+ x.innerHTML = data.data;
51
+ });
52
+ }
53
+ window.onload = getLocation;
54
+
55
+ </script>
56
+ HTML
57
+ raw html
58
+ end
59
+
60
+ def get_geoloc_form
61
+ html = <<-HTML
62
+
63
+ <script>
64
+ var lat = document.getElementById("geoloc_latitude");
65
+ var lng = document.getElementById("geoloc_longitude");
66
+
67
+ function getLocation() {
68
+ if (navigator.geolocation) {
69
+ navigator.geolocation.getCurrentPosition(showPosition);
70
+ } else {
71
+ x.innerHTML = "Geolocation is not supported by this browser.";
72
+ }
73
+ }
74
+
75
+ function showPosition(position) {
76
+ lat.value = position.coords.latitude;
77
+ lng.value = position.coords.longitude;
78
+
79
+ }
80
+ window.onload = getLocation;
81
+
82
+ </script>
83
+ HTML
84
+ raw html
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,5 @@
1
+ if Rails.version >= "3.1"
2
+ require "geoloc/engine"
3
+ else
4
+ ActionView::Base.send :include, Geoloc::Helper
5
+ end
@@ -0,0 +1,5 @@
1
+ require "sinatra/base"
2
+
3
+ class Sinatra::Base
4
+ helpers Geoloc::Helper
5
+ end
@@ -0,0 +1,3 @@
1
+ module Geoloc
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoloc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Lorente, Inga Nikitina
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Geoloc allows you to add HTML5 Geolocation in your views without dealing
42
+ with javascript. Geoloc offers customizable helper methods to add custom geolocation
43
+ requests that can later send back the coordinates to your server
44
+ email:
45
+ - david.l.castilla@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - app/assets/javascripts/geoloc.js
56
+ - bin/console
57
+ - bin/setup
58
+ - geoloc.gemspec
59
+ - lib/geoloc.rb
60
+ - lib/geoloc/engine.rb
61
+ - lib/geoloc/helper.rb
62
+ - lib/geoloc/rails.rb
63
+ - lib/geoloc/sinatra.rb
64
+ - lib/geoloc/version.rb
65
+ homepage: https://github.com/legendss/geoloc
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Geoloc allows you to add HTML5 Geolocation in your views without dealing
89
+ with javascript.
90
+ test_files: []