spree_retailers 0.40.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ Spree Retailers
2
+ ---------------
3
+
4
+ Spree Retailers is a simple Spree Extension.
5
+
6
+
7
+ Demo
8
+ ----
9
+
10
+ To create a spree retailers demo app, run the following:
11
+
12
+ rails new spree_retailers_example
13
+ cd spree_retailers_example
14
+ echo "gem 'spree', '0.40.2'" >> Gemfile
15
+ echo "gem 'spree_retailers', :git => 'git://github.com/citrus/spree_retailers.git'" >> Gemfile
16
+ rm public/index.html
17
+ bundle install
18
+ rake spree:install spree_retailers:install db:migrate db:seed db:admin:create
19
+
20
+
21
+ Or all at once:
22
+
23
+ rails new spree_retailers_example; cd spree_retailers_example; echo "gem 'spree', '0.40.2'" >> Gemfile; echo "gem 'spree_retailers', :git => 'git://github.com/citrus/spree_retailers.git'" >> Gemfile; rm public/index.html; bundle install; rake spree:install spree_retailers:install db:migrate db:seed db:admin:create
24
+
25
+ `rake db:sample` if you want to...
26
+
27
+ Then start the server with `rails s`
28
+
29
+
30
+
31
+ To Do
32
+ -----
33
+
34
+ * Write real tests
35
+
36
+ License
37
+ -------
38
+
39
+ Copyright (c) 2011 Spencer Steffen, released under the New BSD License All rights reserved.
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib"
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ desc "Default Task"
12
+ task :default => [ :test ]
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ # TODO: pull in the spree/core/Rakefile bits that set up for testing
22
+ desc "Regenerates a Rails 3 app for testing"
23
+ task :test_app do
24
+ # TODO - this path requires a certain directory structure -- need
25
+ # to think about how to refactor
26
+
27
+
28
+ files = `gem contents spree`.split("\n").select{|file| file.match("test_app_generator")}
29
+ if files.length == 1
30
+ require files.first
31
+ class SpreeRetailersTestAppGenerator < Spree::Generators::TestAppGenerator
32
+ def tweak_gemfile
33
+ append_file "Gemfile" ,
34
+ <<-gems
35
+ gem 'activemerchant'
36
+ gem 'spree_core', '>=0.40.2'
37
+ gem 'spree_auth', '>=0.40.2'
38
+ gem 'spree_retailers', :path => "#{File.dirname(__FILE__)}"
39
+ gems
40
+ end
41
+
42
+ def install_spree_gems
43
+
44
+ puts "-----------------------------------------"
45
+ puts "Installing gems..."
46
+ `bundle install --gemfile=spec/test_app/Gemfile`
47
+ puts "-----------------------------------------"
48
+
49
+ inside "test_app" do
50
+ run 'rake spree_core:install'
51
+ run 'rake spree_auth:install'
52
+ run 'rake spree_retailers:install'
53
+ end
54
+ end
55
+
56
+ def migrate_db
57
+ run_migrations
58
+ end
59
+ end
60
+
61
+ SpreeRetailersTestAppGenerator.start
62
+
63
+ puts "spec/test_app created. "
64
+
65
+ else
66
+ puts "Failed: Could not find lib/generators/spree/test_app_generator.rb"
67
+ end
68
+ end
69
+
70
+ namespace :test_app do
71
+ desc 'Rebuild test database'
72
+ task :rebuild_db do
73
+ system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test")
74
+ end
75
+ end
@@ -0,0 +1,52 @@
1
+ class Admin::RetailersController < Admin::BaseController
2
+
3
+ resource_controller
4
+
5
+ actions :all
6
+
7
+ create.response do |wants|
8
+ wants.html {redirect_to admin_retailers_path}
9
+ end
10
+
11
+ update.response do |wants|
12
+ wants.html {redirect_to admin_retailers_path}
13
+ end
14
+
15
+ index.response do |wants|
16
+ wants.html { render :action => :index }
17
+ wants.json { render :json => @collection.to_json() }
18
+ end
19
+
20
+ destroy.success.wants.js { render_js_for_destroy }
21
+
22
+ private
23
+
24
+ def object
25
+ get_states
26
+ super
27
+ end
28
+
29
+ def collection
30
+ return @collection if @collection.present?
31
+ unless request.xhr?
32
+ params[:search] ||= {}
33
+ params[:search][:order] ||= "ascend_by_name"
34
+
35
+ @search = Retailer.searchlogic(params[:search])
36
+
37
+ #set order by to default or form result
38
+ @search.order ||= "ascend_by_name"
39
+
40
+ @collection = @search.do_search.paginate(:per_page => Spree::Config[:admin_products_per_page], :page => params[:page])
41
+ else
42
+ @collection = Retailer.find(:all,
43
+ :conditions => params[:q] ? ["Retailer.name like :search OR Retailer.email like :search OR Retailer.phone like :search", {:search => "#{params[:q].strip}%"}] : nil,
44
+ :limit => (params[:limit] || 100))
45
+ end
46
+ end
47
+
48
+ def get_states
49
+ @states = State.where(:country_id => 214).collect{|state| state.name }.sort
50
+ end
51
+
52
+ end
@@ -0,0 +1,10 @@
1
+ class RetailersController < Spree::BaseController
2
+
3
+ def index
4
+ @retailers = Retailer.order(:name)
5
+ #if request.xhr?
6
+ # render :partial => 'list', :layout => false, :locals => { :retailers => @retailers }
7
+ #end
8
+ end
9
+
10
+ end
@@ -0,0 +1,25 @@
1
+ class Retailer < ActiveRecord::Base
2
+
3
+ validates_presence_of :name, :address, :city, :state, :zipcode
4
+
5
+ [:address2, :phone, :email].each do |property|
6
+ define_method "has_#{property.to_s}?" do
7
+ val = self.send property
8
+ !(val.nil? || val.empty?)
9
+ end
10
+ end
11
+
12
+ def has_url?
13
+ (self.url.nil? || self.url.empty?) && self.url != "http://"
14
+ end
15
+
16
+
17
+ def url=(value)
18
+ val = value.strip.downcase
19
+ if val.match(/^http(s)?:\/\//) == nil
20
+ val = "http://" + val
21
+ end
22
+ write_attribute :url, val
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ <%= tab :retailers %>
@@ -0,0 +1,57 @@
1
+ <%= f.field_container :name do %>
2
+ <%= f.label :name, "Name" %><br />
3
+ <%= f.text_field :name %>
4
+ <%= error_message_on :retailer, :name %>
5
+ <% end %>
6
+
7
+ <%= f.field_container :address do %>
8
+ <%= f.label :address, "Address" %><br />
9
+ <%= f.text_field :address %>
10
+ <%= error_message_on :retailer, :address %>
11
+ <% end %>
12
+
13
+ <%= f.field_container :address2 do %>
14
+ <%= f.label :address2, "Address (cont)" %><br />
15
+ <%= f.text_field :address2 %>
16
+ <%= error_message_on :retailer, :address2 %>
17
+ <% end %>
18
+
19
+
20
+ <%= f.field_container :city do %>
21
+ <%= f.label :city, "City" %><br />
22
+ <%= f.text_field :city %>
23
+ <%= error_message_on :retailer, :city %>
24
+ <% end %>
25
+
26
+ <%= f.field_container :state do %>
27
+ <%= f.label :state, "State" %><br />
28
+ <%= f.select :state, @states %>
29
+ <%= error_message_on :retailer, :state %>
30
+ <% end %>
31
+
32
+
33
+ <%= f.field_container :zipcode do %>
34
+ <%= f.label :zipcode, "Zip" %><br />
35
+ <%= f.text_field :zipcode %>
36
+ <%= error_message_on :retailer, :zipcode %>
37
+ <% end %>
38
+
39
+
40
+
41
+ <%= f.field_container :phone do %>
42
+ <%= f.label :phone, "Phone" %><br />
43
+ <%= f.text_field :phone %>
44
+ <%= error_message_on :retailer, :phone %>
45
+ <% end %>
46
+
47
+ <%= f.field_container :email do %>
48
+ <%= f.label :email, "Email" %><br />
49
+ <%= f.text_field :email %>
50
+ <%= error_message_on :retailer, :email %>
51
+ <% end %>
52
+
53
+ <%= f.field_container :url do %>
54
+ <%= f.label :url, "Website URL" %><br />
55
+ <%= f.text_field :url %>
56
+ <%= error_message_on :retailer, :url %>
57
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <h1>Edit Retailer</h1>
2
+
3
+ <% form_for(@retailer, :url => object_url, :html => { :multipart => true, :method => :put }) do |f| %>
4
+ <%= render :partial => "form", :locals => { :f => f } %>
5
+ <p class="form-buttons">
6
+ <%= button t("update") %> <%= link_to t('cancel'), collection_url %>
7
+ </p>
8
+ <% end %>
@@ -0,0 +1,55 @@
1
+ <div class='toolbar'>
2
+ <ul class='actions'>
3
+ <li>
4
+ <p><%= button_link_to "New Retailer", new_object_url, :icon => 'add' %></p>
5
+ </li>
6
+ </ul>
7
+ <br class='clear' />
8
+ </div>
9
+
10
+
11
+ <h1>Listing Retailers</h1>
12
+
13
+ <table class="index">
14
+ <thead>
15
+ <tr>
16
+ <th><%= order @search, :by => :name %></th>
17
+ <th><%= order @search, :by => :address %></th>
18
+ <th><%= order @search, :by => :email %></th>
19
+ <th><%= order @search, :by => :phone %></th>
20
+ <th><%= t("action") %></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <%- @collection.each do |retailer|%>
25
+ <tr id="<%= dom_id retailer %>">
26
+ <td width="200px"><%= link_to retailer.name, object_url(retailer) %></td>
27
+ <td><%= retailer.address %></td>
28
+ <td><%= retailer.email %></td>
29
+ <td><%= retailer.phone %></td>
30
+ <td>
31
+ <%= link_to_edit retailer %> &nbsp;
32
+ <%= link_to_delete retailer %> &nbsp;
33
+ </td>
34
+ </tr>
35
+ <% end %>
36
+ </tbody>
37
+ </table>
38
+
39
+ <%= will_paginate(:prev => "&#171; #{t('previous')}", :next => "#{t('next')} &#187;") %>
40
+
41
+
42
+ <% content_for :sidebar do %>
43
+
44
+ <%= form_for @search do |f| %>
45
+ <div class="box">
46
+ <h3><%= t(:search) %></h3>
47
+ <p>
48
+ <%= t("title") %><br />
49
+ <%= f.text_field :name_contains, :size=> 18 %>
50
+ </p>
51
+ <p><%= button t("search") %></p>
52
+ </div>
53
+ <% end %>
54
+
55
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <h1>New Retailer</h1>
2
+
3
+ <%= form_for(@retailer, :url => collection_url, :html => { :multipart => true }) do |f| %>
4
+ <%= render :partial => "form", :locals => { :f => f } %>
5
+
6
+ <p class="form-buttons">
7
+ <%= button t("create") %> <%= link_to t('cancel'), collection_url %>
8
+ </p>
9
+ <% end %>
10
+
@@ -0,0 +1,36 @@
1
+ <h1><%= @retailer.name %></h1>
2
+ <p>
3
+ <%= @retailer.address %>
4
+
5
+ <% if @retailer.has_address2? %>
6
+ <br/>
7
+ <%= @retailer.address2 %>
8
+ <% end %>
9
+
10
+ <br/>
11
+
12
+ <%= @retailer.city %>,
13
+ <%= @retailer.state %>
14
+ <%= @retailer.zipcode %>
15
+
16
+ <% if @retailer.has_phone? %>
17
+ <br/>
18
+ <%= @retailer.phone %>
19
+ <% end %>
20
+
21
+ <% if @retailer.has_email? %>
22
+ <br/>
23
+ <%= mail_to @retailer.email %>
24
+ <% end %>
25
+
26
+ <% if @retailer.has_url? %>
27
+ <br/>
28
+ <%= link_to @retailer.url, @retailer.url, :class => 'popup' %>
29
+ <% end %>
30
+ </p>
31
+
32
+
33
+ <p>
34
+ <%= link_to_edit @user %> &nbsp;
35
+ <%= link_to t('back'), collection_url %>
36
+ </p>
@@ -0,0 +1,6 @@
1
+ <% if defined? retailers %>
2
+ <div class="retailers">
3
+ <h3>Find <%= Spree::Config[:site_name] %> at the following retail locations:</h3>
4
+ <%= render :partial => 'retailer', :collection => retailers %>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,34 @@
1
+ <% if defined? retailer %>
2
+ <div class="retailer">
3
+ <p>
4
+ <b><%= retailer.has_url? ? link_to(retailer.name, retailer.url, :class => 'popup') : retailer.name %></b><br/>
5
+ <%= retailer.address %>
6
+
7
+ <% if retailer.has_address2? %>
8
+ <br/>
9
+ <%= retailer.address2 %>
10
+ <% end %>
11
+
12
+ <br/>
13
+
14
+ <%= retailer.city %>,
15
+ <%= retailer.state %>
16
+ <%= retailer.zipcode %>
17
+
18
+ <% if retailer.has_phone? %>
19
+ <br/>
20
+ <%= retailer.phone %>
21
+ <% end %>
22
+
23
+ <% if retailer.has_email? %>
24
+ <br/>
25
+ <%= mail_to retailer.email %>
26
+ <% end %>
27
+
28
+ <% if retailer.has_url? %>
29
+ <br/>
30
+ <%= link_to retailer.url, retailer.url, :class => 'popup' %>
31
+ <% end %>
32
+ </p>
33
+ </div>
34
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <div class="left">
2
+ <%= hook :retailers_static_content do %>
3
+ <h1><%= t('retailers') %></h1>
4
+ <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis. In condimentum facilisis porta. Sed nec diam eu diam mattis viverra. Nulla fringilla, orci ac euismod semper, magna diam porttitor mauris, quis sollicitudin sapien justo in libero. Vestibulum mollis mauris enim. Morbi euismod magna ac lorem rutrum elementum. Donec viverra auctor lobortis. Pellentesque eu est.</p>
5
+ <% end %>
6
+ </div>
7
+
8
+ <div class="right">
9
+
10
+ <%= hook :retailers_list do %>
11
+ <% unless !@retailers || @retailers.empty? %>
12
+ <%= render 'list', :retailers => @retailers %>
13
+ <% end %>
14
+ <% end %>
15
+
16
+ </div>
17
+
18
+ <div class="clear">&nbsp;</div>
@@ -0,0 +1,2 @@
1
+ en:
2
+ retailers: Retailers
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :retailers
4
+
5
+ namespace :admin do
6
+ resources :retailers
7
+ end
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ class InstallSpreeRetailers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :retailers do |t|
4
+ t.string :name, :required => true
5
+ t.string :address, :required => true
6
+ t.string :address2
7
+ t.string :city
8
+ t.string :state
9
+ t.string :zipcode
10
+ t.string :country
11
+ t.string :phone
12
+ t.string :email
13
+ t.string :url
14
+ t.timestamps
15
+ end
16
+ end
17
+ def self.down
18
+ drop_table :retailers
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module SpreeRetailers
2
+ class CustomHooks < Spree::ThemeSupport::HookListener
3
+
4
+ insert_after :admin_tabs, 'admin/hooks/retailers_tab'
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SpreeRetailers
2
+ VERSION = "0.40.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spree_retailers/version'
2
+ require 'spree_retailers/custom_hooks'
3
+
4
+ module SpreeRetailers
5
+
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ #initializer "static assets" do |app|
11
+ # app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{config.root}/public"
12
+ #end
13
+
14
+ #def self.activate
15
+ # #Dir["../app/**/*.rb"].each do |c|
16
+ # # puts c
17
+ # # #Rails.env.production? ? require(c) : load(c)
18
+ # #end
19
+ #end
20
+
21
+ #config.to_prepare &method(:activate).to_proc
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ namespace :spree_retailers do
2
+
3
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
4
+ task :install do
5
+ Rake::Task['spree_retailers:install:migrations'].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
+
12
+ source = File.expand_path('../../../db/migrate', __FILE__)
13
+ destination = File.join(Rails.root, 'db', 'migrate')
14
+
15
+ FileUtils.mkdir_p(destination)
16
+
17
+ migrations = Dir.entries(destination).select{|file| file.match('.rb') }
18
+
19
+ files = Dir.entries(source).select{|file| file.match('.rb') }
20
+ files.each_with_index do |file,index|
21
+ time = Time.now + (index * 7)
22
+ number = [time.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % index].max
23
+ new_file = [number,file].join('_')
24
+ src = File.join(source, file)
25
+ dst = File.join(destination, new_file)
26
+ if 0 < migrations.select{|migration| migration.match(file) != nil }.length
27
+ puts "#{file} exists!"
28
+ else
29
+ FileUtils.cp(src, dst)
30
+ puts "#{new_file} copied!"
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_retailers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 40
8
+ - 0
9
+ - 1
10
+ version: 0.40.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Spencer Steffen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-27 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ - 40
32
+ - 2
33
+ version: 0.40.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: spree_auth
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ - 40
47
+ - 2
48
+ version: 0.40.2
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: ""
52
+ email:
53
+ - spencer@citrusme.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - README.md
62
+ - config/locales/en.yml
63
+ - config/routes.rb
64
+ - lib/spree_retailers/custom_hooks.rb
65
+ - lib/spree_retailers/version.rb
66
+ - lib/spree_retailers.rb
67
+ - lib/tasks/install.rake
68
+ - app/controllers/admin/retailers_controller.rb
69
+ - app/controllers/retailers_controller.rb
70
+ - app/models/retailer.rb
71
+ - app/views/admin/hooks/_retailers_tab.html.erb
72
+ - app/views/admin/retailers/_form.html.erb
73
+ - app/views/admin/retailers/edit.html.erb
74
+ - app/views/admin/retailers/index.html.erb
75
+ - app/views/admin/retailers/new.html.erb
76
+ - app/views/admin/retailers/show.html.erb
77
+ - app/views/retailers/_list.html.erb
78
+ - app/views/retailers/_retailer.html.erb
79
+ - app/views/retailers/index.html.erb
80
+ - db/migrate/install_spree_retailers.rb
81
+ - Rakefile
82
+ has_rdoc: false
83
+ homepage: http://github.com/citrus/spree_retailers
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Spree Retailers adds a retailer admin to Spree.
114
+ test_files: []
115
+