spree_zones_by_zip_code 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ SUMMARY
2
+ -------
3
+
4
+ This gem is an extension to spree and allows for zoning based on zip codes.
5
+
6
+
7
+ Installing the Gem
8
+ -------------
9
+
10
+ Start by adding the gem to your existing Rails 3.x application's Gemfile
11
+
12
+ gem 'spree_zones_by_zip_code', :git => 'git@github.com:desiringgod/spree-zones-by-zip-code.git'
13
+
14
+ Update your bundle
15
+
16
+ bundle install
17
+
18
+ Install all of the necessary migrations, assets, etc.
19
+
20
+ rake spree_zones_by_zip_code:install
21
+
22
+ Migrate
23
+
24
+ rake db:migrate
25
+
@@ -0,0 +1,30 @@
1
+ class Admin::ZipCodesController < Admin::BaseController
2
+ resource_controller
3
+ new_action.response do |wants|
4
+ wants.html {render :layout => !request.xhr?}
5
+ end
6
+ create.wants.html { redirect_to admin_zip_codes_url }
7
+ update.wants.html { redirect_to admin_zip_codes_url }
8
+ =begin
9
+ before_filter :load_data
10
+
11
+ index.response do |wants|
12
+ wants.html
13
+ wants.js do
14
+ render :partial => 'state_list.html.erb'
15
+ end
16
+ end
17
+
18
+
19
+
20
+ private
21
+
22
+ def collection
23
+ @collection ||= end_of_association_chain.order('name')
24
+ end
25
+
26
+ def load_data
27
+ @countries = Country.order('name')
28
+ end
29
+ =end
30
+ end
@@ -0,0 +1,10 @@
1
+ Admin::ZonesController.class_eval do
2
+ private
3
+ def load_data
4
+ @countries = Country.all.sort
5
+ @states = State.all.sort
6
+ @zip_codes = ZipCode.all
7
+ @zones = Zone.all.sort
8
+ end
9
+ end
10
+
@@ -0,0 +1,19 @@
1
+ class ZipCode < ActiveRecord::Base
2
+ has_many :zone_members, :as => :zoneable
3
+ has_many :zones, :through => :zone_members
4
+
5
+ validates :value, :presence => true
6
+
7
+ def <=>(other)
8
+ value <=> other.value
9
+ end
10
+
11
+ def to_s
12
+ value
13
+ end
14
+
15
+ def name
16
+ value
17
+ end
18
+ end
19
+
@@ -0,0 +1,13 @@
1
+ Zone.class_eval do
2
+ def kind
3
+ member = self.members.last
4
+ case member && member.zoneable_type
5
+ when "State" then "state"
6
+ when "Zone" then "zone"
7
+ when "Zip Code" then "zip code"
8
+ else
9
+ "country"
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,5 @@
1
+ <%= f.field_container :value do %>
2
+ <%= f.label :value, t("value") %><br />
3
+ <%=f.text_field :value %>
4
+ <% end %>
5
+
@@ -0,0 +1,11 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("editing_zip_code") %></h1>
4
+
5
+ <%= render 'shared/error_messages', :target => @zip_code %>
6
+
7
+ <%= form_for(:zip_code, :url => object_url, :html => { :method => :put }) do |f| %>
8
+ <%= render :partial => "form", :locals => { :f => f } %>
9
+ <%= render :partial => "admin/shared/edit_resource_links" %>
10
+ <% end %>
11
+
@@ -0,0 +1,36 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("zip_codes") %></h1>
4
+
5
+ <%= image_tag "spinner.gif", :plugin=>"spree", :style => "display:none", :id => 'busy_indicator' %>
6
+
7
+ <div id="zip-code-list">
8
+ <table class="index" id='listing_zip_codes'>
9
+ <thead>
10
+ <tr>
11
+ <th><%= t("value") %></th>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% @zip_codes.each do |zip_code| %>
17
+ <tr id="<%= dom_id zip_code %>">
18
+ <td><%=zip_code.value %></td>
19
+ <td class="actions">
20
+ <%=link_to_with_icon 'edit', t("edit"), edit_admin_zip_code_url(zip_code) %> &nbsp;
21
+ <%=link_to_delete zip_code%>
22
+ </td>
23
+ </tr>
24
+ <% end %>
25
+ <% if @zip_codes.empty? %>
26
+ <tr><td colspan="3"><%= t(:none) %></td></tr>
27
+ <% end %>
28
+ </tbody>
29
+ </table>
30
+ <div id="new_zip_code"></div>
31
+ <p>
32
+ <%= button_link_to t("new_zip_code"), new_admin_zip_code_url(@zip_code), {:remote => true, :icon => 'add'} %>
33
+ </p>
34
+
35
+ </div>
36
+
@@ -0,0 +1,10 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <%= render 'shared/error_messages', :target => @zip_code%>
4
+
5
+
6
+ <%= form_for(:zip_code, :url => collection_url) do |f| %>
7
+ <%= render :partial => "form", :locals => { :f => f } %>
8
+ <%= render :partial => "admin/shared/new_resource_links" %>
9
+ <% end %>
10
+
@@ -0,0 +1,35 @@
1
+ <%= zone_form.field_container :name do %>
2
+ <%= zone_form.label :name, t("name") %><br />
3
+ <%=zone_form.text_field :name %>
4
+ <% end %>
5
+
6
+ <%= zone_form.field_container :description do %>
7
+ <%= zone_form.label :description, t("description") %><br />
8
+ <%=zone_form.text_field :description %>
9
+ <% end %>
10
+
11
+ <p>
12
+ <label><%= t("type") %></label><br />
13
+ <label class="sub">
14
+ <%= zone_form.radio_button("kind", "country", {:id => "country_based"}) %>
15
+ <%= t("country_based") %>
16
+ </label> &nbsp;
17
+ <label class="sub">
18
+ <%= zone_form.radio_button("kind", "state", {:id => "state_based"}) %>
19
+ <%= t("state_based") %>
20
+ </label> &nbsp;
21
+ <label class="sub">
22
+ <%= zone_form.radio_button("kind", "zip code", {:id => "zip_code_based"}) %>
23
+ <%= t("zip_code_based") %>
24
+ </label> &nbsp;
25
+ <label class="sub">
26
+ <%= zone_form.radio_button("kind", "zone", {:id => "zone_based"}) %>
27
+ <%= t("zone_based") %>
28
+ </label>
29
+ </p>
30
+
31
+ <%= render "member_type", :type => "country", :zone_form => zone_form %>
32
+ <%= render "member_type", :type => "state", :zone_form => zone_form %>
33
+ <%= render "member_type", :type => "zip_code", :zone_form => zone_form %>
34
+ <%= render "member_type", :type => "zone", :zone_form => zone_form %>
35
+
@@ -0,0 +1,6 @@
1
+ <li>
2
+ <%= f.hidden_field :zoneable_type, :value => "Zip Code" %>
3
+ <%= f.collection_select(:zoneable_id, @zip_codes, :id, :value, :include_blank => true) %>
4
+ <%= remove_nested f %>
5
+ </li>
6
+
@@ -0,0 +1,17 @@
1
+ require 'spree_core'
2
+ require 'spree_zones_by_zip_code_hooks'
3
+
4
+ module SpreeZonesByZipCode
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
+ Rails.env.production? ? require(c) : load(c)
12
+ end
13
+ end
14
+
15
+ config.to_prepare &method(:activate).to_proc
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ class SpreeZonesByZipCodeHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ # TODO add a hook to zip codes in the configuration menu
4
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_zones_by_zip_code do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_zones_by_zip_code:install:migrations'].invoke
5
+ Rake::Task['spree_zones_by_zip_code:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_zones_by_zip_code
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Gagan Awhad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-17 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: spree_core
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.40.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description:
28
+ email: gagan.awhad@desiringgod.org
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - README.md
37
+ - LICENSE
38
+ - lib/spree_zones_by_zip_code.rb
39
+ - lib/spree_zones_by_zip_code_hooks.rb
40
+ - lib/tasks/install.rake
41
+ - lib/tasks/spree_zones_by_zip_code.rake
42
+ - app/controllers/admin/zip_codes_controller.rb
43
+ - app/controllers/admin/zones_controller_decorator.rb
44
+ - app/models/zip_code.rb
45
+ - app/models/zone_decorator.rb
46
+ - app/views/admin/zip_codes/_form.html.erb
47
+ - app/views/admin/zip_codes/edit.html.erb
48
+ - app/views/admin/zip_codes/index.html.erb
49
+ - app/views/admin/zip_codes/new.html.erb
50
+ - app/views/admin/zones/_form.html.erb
51
+ - app/views/admin/zones/_zip_code_member.html.erb
52
+ has_rdoc: false
53
+ homepage: http://www.desiringgod.org
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.8.7
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ requirements:
74
+ - none
75
+ rubyforge_project:
76
+ rubygems_version: 1.6.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Allows for zoning by zip codes
80
+ test_files: []
81
+