maptastic-form 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Matthew Hall
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.
data/README.markdown ADDED
@@ -0,0 +1,54 @@
1
+ # Formtastic Location Selector
2
+
3
+ ## Installation
4
+
5
+ First, you'll need to install [Formtastic][1].
6
+
7
+ Next, install Maptastic as a plugin:
8
+
9
+ script/plugin install git@github.com:MattHall/maptastic.git
10
+
11
+ Or as a Gem:
12
+
13
+ gem install maptastic-form
14
+
15
+ ...and run the rake task to install the required js file into your javascripts directory. You will probably need to include this in your layouts, too.
16
+
17
+ rake maptastic_form:install
18
+
19
+ You'll need to add the [Google Maps **V3**][3] script include in your page, above your semantic_form:
20
+
21
+ <script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script>
22
+
23
+ Note that you no longer need an API key with the latest Google Maps release.
24
+
25
+ ## Usage
26
+
27
+ Maptastic adds a new #multi_input method as well as the map control:
28
+
29
+ <% semantic_form_for @venue do |f| %>
30
+ <%= f.multi_input :latitude, :longitude, :as => :map %>
31
+ <% end %>
32
+
33
+ Note that the map input expects two parameters - a latitude and longitude. The order is important.
34
+
35
+ ## Development
36
+
37
+ This plugin is under development. It's pretty simple, and patches are very welcome.
38
+
39
+ [The Repo is available on GitHub][5]
40
+
41
+ [Report bugs here][4]
42
+
43
+ A [testbed app is available][6] to check that the changes made actually work as expected.
44
+
45
+ ## Project Info
46
+
47
+ Copyright © 2010 [Matthew Hall][2], released under the MIT license.
48
+
49
+ [1]:http://github.com/justinfrench/formtastic
50
+ [2]:http://codebeef.com
51
+ [3]:http://code.google.com/apis/maps/documentation/javascript/
52
+ [4]:https://matt.purifyapp.com/projects/maptastic/issues
53
+ [5]:http://github.com/MattHall/maptastic
54
+ [6]:http://github.com/MattHall/maptastic-testbed
@@ -0,0 +1,48 @@
1
+ module MaptasticForm
2
+ class SemanticFormBuilder < Formtastic::SemanticFormBuilder
3
+
4
+ def multi_input(*args)
5
+ options = args.extract_options!
6
+
7
+ if (options[:as] == :map)
8
+ map_input(args, options)
9
+ else
10
+ args.inject('') {|html, arg| html << input(arg, options)}
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def map_div_id(methods)
17
+ generate_html_id(methods.map(&:to_s).join('_') << '_map')
18
+ end
19
+
20
+ def map_input_id(method)
21
+ generate_html_id("map_#{method}")
22
+ end
23
+
24
+ def map_js(methods)
25
+ @template.content_tag("script", :lang => "javascript") do
26
+ "
27
+ new MaptasticMap({
28
+ mapId: '#{map_div_id(methods)}',
29
+ latInput: '#{map_input_id(methods.first)}',
30
+ lngInput: '#{map_input_id(methods.last)}'
31
+ });
32
+ "
33
+ end
34
+ end
35
+
36
+ def map_input(methods, options = {})
37
+ options[:hint] ||= "Click to select a location, then drag the marker to position"
38
+ inputs_html = methods.inject('') {|html, method| html << input(method, :id => map_input_id(method), :as => :hidden)}
39
+ hint_html = inline_hints_for(methods.first, options)
40
+ map_container = @template.content_tag(:div, nil, :class => 'map', :id => map_div_id(methods))
41
+ map_html = @template.content_tag(:li, Formtastic::Util.html_safe("#{map_container} #{hint_html.to_s} #{options[:skip_js] == true ? '' : map_js(methods).to_s}"))
42
+
43
+ Formtastic::Util.html_safe(inputs_html + map_html)
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ module MaptasticForm
2
+ VERSION = '0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maptastic-form
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Matt Hall
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-03 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: formtastic
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Provides a map type to Formtastic, allowing you to easily add location selectors to your apps.
35
+ email:
36
+ - matt@codebeef.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/maptastic_form/semantic_form_builder.rb
45
+ - lib/maptastic_form/version.rb
46
+ - MIT-LICENSE
47
+ - README.markdown
48
+ has_rdoc: true
49
+ homepage: http://codebeef.com/projects/maptastic
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: The fastest way of adding maps to Formtastic forms
82
+ test_files: []
83
+