spree_counties 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +2 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +43 -0
  8. data/Rakefile +21 -0
  9. data/app/assets/javascripts/spree/backend/spree_counties.js +30 -0
  10. data/app/assets/javascripts/spree/frontend/spree_counties.js.coffee +58 -0
  11. data/app/assets/stylesheets/spree/backend/spree_counties.css +4 -0
  12. data/app/assets/stylesheets/spree/frontend/spree_counties.css +4 -0
  13. data/app/controllers/spree/api/counties_controller.rb +38 -0
  14. data/app/models/county_ability.rb +10 -0
  15. data/app/models/spree/address_decorator.rb +7 -0
  16. data/app/models/spree/county.rb +13 -0
  17. data/app/models/spree/state_decorator.rb +3 -0
  18. data/app/views/spree/address/_form.html.erb +86 -0
  19. data/app/views/spree/admin/shared/_address_form.html.erb +81 -0
  20. data/app/views/spree/api/counties/index.v1.rabl +11 -0
  21. data/app/views/spree/api/counties/show.v1.rabl +2 -0
  22. data/bin/rails +7 -0
  23. data/config/locales/en.yml +5 -0
  24. data/config/routes.rb +6 -0
  25. data/db/migrate/20140729200830_create_spree_counties.rb +10 -0
  26. data/db/migrate/20140729203900_add_spree_county_reference_to_spree_address.rb +5 -0
  27. data/db/migrate/20141119225426_add_county_name_to_spree_address.rb +5 -0
  28. data/lib/generators/spree_counties/install/install_generator.rb +41 -0
  29. data/lib/generators/spree_counties/install/templates/1.png +0 -0
  30. data/lib/generators/spree_counties/install/templates/2.png +0 -0
  31. data/lib/generators/spree_counties/install/templates/seeds/counties.rb +367 -0
  32. data/lib/spree_counties/engine.rb +20 -0
  33. data/lib/spree_counties/factories.rb +6 -0
  34. data/lib/spree_counties/version.rb +3 -0
  35. data/lib/spree_counties.rb +2 -0
  36. data/spec/spec_helper.rb +87 -0
  37. data/spree_counties.gemspec +32 -0
  38. metadata +235 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e93c413637e88d68cee31578248d340bb10ced70
4
+ data.tar.gz: b6f8a04f81f2afe561add3d03e051fe24b4bdc09
5
+ SHA512:
6
+ metadata.gz: 035a10e4a361f0f965bc5ced571d3eff1f02cb67b0cc769109a83d09244a3e95234792980b864c955bd44cfa845b17dd2cede9ca08b05a89d9370c699c7a15af
7
+ data.tar.gz: ff6effea687e7e2bd76ddf6683e85539c4e095957b54fefc6147695dc4ca4cf512faf9a0424c50d6365d53dfa41eef166aff1130199dd810792527dc9d537b4c
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_JOBS: 8
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', github: 'spree/spree', branch: '2-3-stable'
4
+ # Provides basic authentication functionality for testing parts of your engine
5
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-3-stable'
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Gonzalo Moreno
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ Spree Counties
2
+ =============
3
+
4
+ Lets your users pick counties from states list in address's step
5
+
6
+ ![alt tag](https://raw.githubusercontent.com/ronzalo/spree_counties/master/lib/generators/spree_counties/install/templates/1.png)
7
+
8
+ ![alt tag](https://raw.githubusercontent.com/ronzalo/spree_counties/master/lib/generators/spree_counties/install/templates/2.png)
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Add spree_counties to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'spree_counties'
17
+ ```
18
+
19
+ Bundle your dependencies and run the installation generator:
20
+
21
+ ```shell
22
+ bundle
23
+ bundle exec rails g spree_counties:install
24
+ ```
25
+
26
+ Testing
27
+ -------
28
+
29
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
30
+
31
+ ```shell
32
+ bundle
33
+ bundle exec rake
34
+ ```
35
+
36
+ When testing your applications integration with this extension you may use it's factories.
37
+ Simply add this require statement to your spec_helper:
38
+
39
+ ```ruby
40
+ require 'spree_counties/factories'
41
+ ```
42
+
43
+ Copyright (c) 2014 Gonzalo Moreno C, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_counties'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,30 @@
1
+ var update_county = function (region, done) {
2
+ 'use strict';
3
+
4
+ var state = $('span#' + region + 'state .select2').select2('val');
5
+ var county_select = $('span#' + region + 'county select.select2');
6
+
7
+ $.get('/api/counties?state_id=' + state, function (data) {
8
+ var counties = data.counties;
9
+ if (counties.length > 0) {
10
+ county_select.html('');
11
+ var counties_with_blank = [{
12
+ name: '',
13
+ id: ''
14
+ }].concat(counties);
15
+ $.each(counties_with_blank, function (pos, county) {
16
+ var opt = $(document.createElement('option'))
17
+ .prop('value', state.id)
18
+ .html(county.name);
19
+ county_select.append(opt);
20
+ });
21
+ county_select.prop('disabled', false).show();
22
+ county_select.select2();
23
+
24
+ } else {
25
+ county_select.select2('destroy').hide();
26
+ }
27
+
28
+ if(done) done();
29
+ });
30
+ };
@@ -0,0 +1,58 @@
1
+ Spree.ready ($) ->
2
+ ($ '#bstate select').change ->
3
+ updateCounty 'b'
4
+
5
+ ($ '#sstate select').change ->
6
+ updateCounty 's'
7
+
8
+ updateCounty = (region) ->
9
+ stateId = getStateId(region)
10
+ if stateId?
11
+ $.get '/api/counties', {state_id: stateId}, (data) ->
12
+ Spree.Checkout[stateId] =
13
+ counties: data.counties
14
+ fillCounties(Spree.Checkout[stateId], region)
15
+
16
+ getStateId = (region) ->
17
+ $('#' + region + 'state select').val()
18
+
19
+ fillCounties = (data, region) ->
20
+ countiesRequired = true
21
+ counties = data.counties
22
+
23
+ countyPara = ($ '#' + region + 'county')
24
+ countySelect = countyPara.find('select')
25
+ countyInput = countyPara.find('input')
26
+ countySpanRequired = countyPara.find('county-required')
27
+ if counties.length > 0
28
+ selected = parseInt countySelect.val()
29
+ countySelect.html ''
30
+ countyWithBlank = [{ name: '', id: ''}].concat(counties)
31
+ $.each countyWithBlank, (idx, county) ->
32
+ opt = ($ document.createElement('option')).attr('value', county.id).html(county.name)
33
+ opt.prop 'selected', true if selected is county.id
34
+ countySelect.append opt
35
+
36
+ countySelect.prop('disabled', false).show()
37
+ countyInput.hide().prop 'disabled', true
38
+ countyPara.show()
39
+ countySpanRequired.show()
40
+ countySelect.addClass('required') if countiesRequired
41
+ countySelect.removeClass('hidden')
42
+ countyInput.removeClass('required')
43
+ else
44
+ countySelect.hide().prop 'disabled', true
45
+ countyInput.show()
46
+ if countiesRequired
47
+ countySpanRequired.show()
48
+ countyInput.addClass('required')
49
+ else
50
+ countyInput.val ''
51
+ countySpanRequired.hide()
52
+ countyInput.removeClass('required')
53
+ countyPara.toggle(!!countiesRequired)
54
+ countyInput.prop('disabled', !countiesRequired)
55
+ countyInput.removeClass('hidden')
56
+ countySelect.removeClass('required')
57
+
58
+ updateCounty 'b'
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,38 @@
1
+ module Spree
2
+ module Api
3
+ class CountiesController < Spree::Api::BaseController
4
+ skip_before_filter :set_expiry
5
+ skip_before_filter :check_for_user_or_api_key
6
+ skip_before_filter :authenticate_user
7
+
8
+ def index
9
+ @counties = scope.ransack(params[:q]).result.
10
+ includes(:state).order('name ASC')
11
+
12
+ if params[:page] || params[:per_page]
13
+ @counties = @counties.page(params[:page]).per(params[:per_page])
14
+ end
15
+
16
+ county = @counties.last
17
+ if stale?(county)
18
+ respond_with(@counties)
19
+ end
20
+ end
21
+
22
+ def show
23
+ @county = scope.find(params[:id])
24
+ respond_with(@county)
25
+ end
26
+
27
+ private
28
+ def scope
29
+ if params[:state_id]
30
+ @state = Spree::State.accessible_by(current_ability, :read).find(params[:state_id])
31
+ return @state.counties.accessible_by(current_ability, :read)
32
+ else
33
+ return Spree::County.accessible_by(current_ability, :read)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ class CountyAbility
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ user ||= Spree::User.new
6
+ unless user.has_spree_role? 'admin'
7
+ can [:index, :read], Spree::County
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ Address.class_eval do
3
+ belongs_to :county, class_name: "Spree::County"
4
+ Spree::PermittedAttributes.address_attributes << :county_id
5
+ Spree::PermittedAttributes.address_attributes << :county_name
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class Spree::County < ActiveRecord::Base
2
+ belongs_to :state
3
+ has_many :addresses, dependent: :nullify
4
+ Spree::Ability.register_ability(CountyAbility)
5
+
6
+ def <=>(other)
7
+ name <=> other.name
8
+ end
9
+
10
+ def to_s
11
+ name
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Spree::State.class_eval do
2
+ has_many :counties, -> { order('name ASC') }, dependent: :destroy
3
+ end
@@ -0,0 +1,86 @@
1
+ <% address_id = address_type.chars.first %>
2
+ <div class="inner" data-hook=<%="#{address_type}_inner" %>>
3
+ <p class="field" id=<%="#{address_id}firstname" %>>
4
+ <%= form.label :firstname, Spree.t(:first_name) %><span class="required">*</span><br />
5
+ <%= form.text_field :firstname, :class => 'required' %>
6
+ </p>
7
+ <p class="field" id=<%="#{address_id}lastname" %>>
8
+ <%= form.label :lastname, Spree.t(:last_name) %><span class="required">*</span><br />
9
+ <%= form.text_field :lastname, :class => 'required' %>
10
+ </p>
11
+ <% if Spree::Config[:company] %>
12
+ <p class="field" id=<%="#{address_id}company" %>>
13
+ <%= form.label :company, Spree.t(:company) %><br />
14
+ <%= form.text_field :company %>
15
+ </p>
16
+ <% end %>
17
+ <p class="field" id=<%="#{address_id}address1" %>>
18
+ <%= form.label :address1, Spree.t(:street_address) %><span class="required">*</span><br />
19
+ <%= form.text_field :address1, :class => 'required' %>
20
+ </p>
21
+ <p class="field" id=<%="#{address_id}address2" %>>
22
+ <%= form.label :address2, Spree.t(:street_address_2) %><br />
23
+ <%= form.text_field :address2 %>
24
+ </p>
25
+ <p class="field" id=<%="#{address_id}city" %>>
26
+ <%= form.label :city, Spree.t(:city) %><span class="required">*</span><br />
27
+ <%= form.text_field :city, :class => 'required' %>
28
+ </p>
29
+ <p class="field" id=<%="#{address_id}country" %>>
30
+ <%= form.label :country_id, Spree.t(:country) %><span class="required">*</span><br />
31
+ <span id=<%="#{address_id}country-selection" %>>
32
+ <%= form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %>
33
+ </span>
34
+ </p>
35
+
36
+ <% if Spree::Config[:address_requires_state] %>
37
+ <p class="field" id=<%="#{address_id}state" %>>
38
+ <% have_states = !address.country.states.empty? %>
39
+ <%= form.label :state, Spree.t(:state) %><span class='required' id=<%="#{address_id}state-required"%>>*</span><br/>
40
+
41
+ <% state_elements = [
42
+ form.collection_select(:state_id, address.country.states,
43
+ :id, :name,
44
+ {:include_blank => true},
45
+ {:class => have_states ? 'required' : 'hidden',
46
+ :disabled => !have_states}) +
47
+ form.text_field(:state_name,
48
+ :class => !have_states ? 'required' : 'hidden',
49
+ :disabled => have_states)
50
+ ].join.gsub('"', "'").gsub("\n", "")
51
+ %>
52
+ <%= javascript_tag do -%>
53
+ $('#<%="#{address_id}state" %>').append("<%== state_elements %>");
54
+ <% end %>
55
+ </p>
56
+ <noscript>
57
+ <%= form.text_field :state_name, :class => 'required' %>
58
+ </noscript>
59
+
60
+ <p class="field" id=<%="#{address_id}county" %>>
61
+ <%= form.label :county do %>
62
+ <%= Spree.t(:county) %>
63
+ <span class="required" id=<%="#{address_id}county-required"%>>*</span>
64
+ <% end %>
65
+ <%= form.collection_select(:county_id, [],
66
+ :id, :name,
67
+ {:include_blank => true},
68
+ {:class => "form-control required",}) %>
69
+ </p>
70
+ <% end %>
71
+
72
+ <p class="field" id=<%="#{address_id}zipcode" %>>
73
+ <%= form.label :zipcode, Spree.t(:zip) %><% if address.require_zipcode? %><span class="required">*</span><br /><% end %>
74
+ <%= form.text_field :zipcode, :class => "#{'required' if address.require_zipcode?}" %>
75
+ </p>
76
+ <p class="field" id=<%="#{address_id}phone" %>>
77
+ <%= form.label :phone, Spree.t(:phone) %><% if address.require_phone? %><span class="required">*</span><br /><% end %>
78
+ <%= form.phone_field :phone, :class => "#{'required' if address.require_phone?}" %>
79
+ </p>
80
+ <% if Spree::Config[:alternative_shipping_phone] %>
81
+ <p class="field" id=<%="#{address_id}altphone" %>>
82
+ <%= form.label :alternative_phone, Spree.t(:alternative_phone) %><br />
83
+ <%= form.phone_field :alternative_phone %>
84
+ </p>
85
+ <% end %>
86
+ </div>
@@ -0,0 +1,81 @@
1
+ <% s_or_b = type.chars.first %>
2
+
3
+ <div id="<%= type %>" data-hook="address_fields">
4
+ <div class="field <%= "#{type}-row" %>">
5
+ <%= f.label :firstname, Spree.t(:first_name) %>
6
+ <%= f.text_field :firstname, :class => 'fullwidth' %>
7
+ </div>
8
+
9
+ <div class="field <%= "#{type}-row" %>">
10
+ <%= f.label :lastname, Spree.t(:last_name) %>
11
+ <%= f.text_field :lastname, :class => 'fullwidth' %>
12
+ </div>
13
+
14
+ <% if Spree::Config[:company] %>
15
+ <div class="field <%= "#{type}-row" %>">
16
+ <%= f.label :company, Spree.t(:company) %>
17
+ <%= f.text_field :company, :class => 'fullwidth' %>
18
+ </div>
19
+ <% end %>
20
+
21
+ <div class="field <%= "#{type}-row" %>">
22
+ <%= f.label :address1, Spree.t(:street_address) %>
23
+ <%= f.text_field :address1, :class => 'fullwidth' %>
24
+ </div>
25
+
26
+ <div class="field <%= "#{type}-row" %>">
27
+ <%= f.label :address2, Spree.t(:street_address_2) %>
28
+ <%= f.text_field :address2, :class => 'fullwidth' %>
29
+ </div>
30
+
31
+ <div class="field <%= "#{type}-row" %>">
32
+ <%= f.label :city, Spree.t(:city) %>
33
+ <%= f.text_field :city, :class => 'fullwidth' %>
34
+ </div>
35
+
36
+ <div class="field <%= "#{type}-row" %>">
37
+ <%= f.label :zipcode, Spree.t(:zip) %>
38
+ <%= f.text_field :zipcode, :class => 'fullwidth' %>
39
+ </div>
40
+
41
+ <div class="field <%= "#{type}-row" %>">
42
+ <%= f.label :country_id, Spree.t(:country) %>
43
+ <span id="<%= s_or_b %>country">
44
+ <%= f.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'select2 fullwidth'} %>
45
+ </span>
46
+ </div>
47
+
48
+ <div class="field <%= "#{type}-row" %>">
49
+ <%= f.label :state_id, Spree.t(:state) %>
50
+ <span id="<%= s_or_b %>state">
51
+ <%= f.text_field :state_name,
52
+ :style => "display: #{f.object.country.states.empty? ? 'block' : 'none' };",
53
+ :disabled => !f.object.country.states.empty?, :class => 'fullwidth state_name' %>
54
+ <%= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth', :style => "display: #{f.object.country.states.empty? ? 'none' : 'block' };", :disabled => f.object.country.states.empty?} %>
55
+ </span>
56
+ </div>
57
+
58
+ <div class="field <%= "#{type}-row" %>">
59
+ <%= f.label :county_id, Spree.t(:county) %>
60
+ <span id="<%= s_or_b %>county">
61
+ <%= f.text_field :county_name,
62
+ :style => "display: #{f.object.state.counties.empty? ? 'block' : 'none' };",
63
+ :disabled => !f.object.state.counties.empty?, :class => 'fullwidth county_name' %>
64
+ <%= f.collection_select :county_id, f.object.state.counties.sort, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth', :style => "display: #{f.object.state.counties.empty? ? 'none' : 'block' };", :disabled => f.object.state.counties.empty?} %>
65
+ </span>
66
+ </div>
67
+
68
+ <div class="field <%= "#{type}-row" %>">
69
+ <%= f.label :phone, Spree.t(:phone) %>
70
+ <%= f.phone_field :phone, :class => 'fullwidth' %>
71
+ </div>
72
+ </div>
73
+
74
+ <% content_for :head do %>
75
+ <%= javascript_tag do -%>
76
+ $(document).ready(function(){
77
+ $('span#<%= s_or_b %>country .select2').on('change', function() { update_state('<%= s_or_b %>'); });
78
+ $('span#<%= s_or_b %>state .select2').on('change', function() { update_county('<%= s_or_b %>'); });
79
+ });
80
+ <% end -%>
81
+ <% end %>
@@ -0,0 +1,11 @@
1
+ object false
2
+
3
+ child(@counties => :counties) do
4
+ attributes :id, :name
5
+ end
6
+
7
+ if @counties.respond_to?(:num_pages)
8
+ node(:count) { @counties.count }
9
+ node(:current_page) { params[:page] || 1 }
10
+ node(:pages) { @counties.num_pages }
11
+ end
@@ -0,0 +1,2 @@
1
+ object @county
2
+ attributes :id, :name
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_counties/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ namespace :api, :defaults => { :format => 'json' } do
4
+ resources :counties, :only => [:index, :show]
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSpreeCounties < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_counties do |t|
4
+ t.string :name
5
+ t.references :state, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddSpreeCountyReferenceToSpreeAddress < ActiveRecord::Migration
2
+ def change
3
+ add_reference :spree_addresses, :county, index: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddCountyNameToSpreeAddress < ActiveRecord::Migration
2
+ def change
3
+ add_column :spree_addresses, :county_name, :string
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ module SpreeCounties
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ class_option :auto_run_migrations, :type => :boolean, :default => false
6
+
7
+ def add_javascripts
8
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_counties\n"
9
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_counties\n"
10
+ end
11
+
12
+ def add_stylesheets
13
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_counties\n", :before => /\*\//, :verbose => true
14
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_counties\n", :before => /\*\//, :verbose => true
15
+ end
16
+
17
+ def add_migrations
18
+ run 'bundle exec rake railties:install:migrations FROM=spree_counties'
19
+ end
20
+
21
+ def run_seeds
22
+ run_seeds = options[:auto_run_seeds] || ['', 'y', 'Y'].include?(ask 'Would you like to load chilean example seeds now? [Y/n]')
23
+ if run_seeds
24
+ copy_file "seeds/counties.rb", "db/seeds/counties.rb"
25
+ run 'bundle exec rails runner db/seeds/counties.rb'
26
+ else
27
+ puts 'Skipping bundle exec rails runner, don\'t forget to run it!'
28
+ end
29
+ end
30
+
31
+ def run_migrations
32
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
33
+ if run_migrations
34
+ run 'bundle exec rake db:migrate'
35
+ else
36
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end