spree_downloads 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +10 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +209 -0
  6. data/LICENSE +26 -0
  7. data/README.md +21 -0
  8. data/Rakefile +29 -0
  9. data/Versionfile +2 -0
  10. data/app/assets/javascripts/admin/spree_downloads.js +1 -0
  11. data/app/assets/javascripts/store/spree_downloads.js +1 -0
  12. data/app/assets/stylesheets/admin/spree_downloads.css +3 -0
  13. data/app/assets/stylesheets/store/spree_downloads.css +3 -0
  14. data/app/controllers/spree/admin/download_categories_controller.rb +51 -0
  15. data/app/controllers/spree/admin/downloads_controller.rb +55 -0
  16. data/app/controllers/spree/downloads_controller.rb +7 -0
  17. data/app/models/spree/download.rb +14 -0
  18. data/app/models/spree/download_category.rb +9 -0
  19. data/app/models/spree/download_product.rb +6 -0
  20. data/app/models/spree/product_decorator.rb +4 -0
  21. data/app/overrides/spree_downloads.rb +5 -0
  22. data/app/views/spree/admin/download_categories/_download_categories.html.erb +15 -0
  23. data/app/views/spree/admin/download_categories/_form.html.erb +20 -0
  24. data/app/views/spree/admin/download_categories/destroy.js.erb +8 -0
  25. data/app/views/spree/admin/download_categories/edit.html.erb +5 -0
  26. data/app/views/spree/admin/download_categories/edit.js.erb +4 -0
  27. data/app/views/spree/admin/download_categories/index.html.erb +16 -0
  28. data/app/views/spree/admin/download_categories/new.html.erb +3 -0
  29. data/app/views/spree/admin/download_categories/new.js.erb +2 -0
  30. data/app/views/spree/admin/download_categories/show.html.erb +10 -0
  31. data/app/views/spree/admin/downloads/_downloads.html.erb +36 -0
  32. data/app/views/spree/admin/downloads/_form.html.erb +41 -0
  33. data/app/views/spree/admin/downloads/edit.html.erb +6 -0
  34. data/app/views/spree/admin/downloads/index.html.erb +4 -0
  35. data/app/views/spree/admin/downloads/new.html.erb +3 -0
  36. data/app/views/spree/admin/downloads/new.js.erb +2 -0
  37. data/app/views/spree/admin/downloads/show.html.erb +15 -0
  38. data/app/views/spree/admin/shared/_download_sub_menu.html.erb +6 -0
  39. data/app/views/spree/downloads/index.html.erb +39 -0
  40. data/config/locales/en.yml +5 -0
  41. data/config/routes.rb +8 -0
  42. data/db/migrate/20120308131418_create_spree_downloads.rb +12 -0
  43. data/db/migrate/20120308131708_create_spree_download_products.rb +10 -0
  44. data/db/migrate/20120308132352_create_spree_download_categories.rb +18 -0
  45. data/lib/generators/spree_downloads/install/install_generator.rb +29 -0
  46. data/lib/spree_downloads/engine.rb +25 -0
  47. data/lib/spree_downloads.rb +2 -0
  48. data/script/rails +5 -0
  49. data/spec/spec_helper.rb +32 -0
  50. data/spree_downloads.gemspec +26 -0
  51. metadata +162 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
10
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby_string="ruby-1.9.2"
4
+ gemset_name="rebo"
5
+
6
+ if rvm list strings | grep -q "${ruby_string}" ; then
7
+ rvm use "${ruby_string}@${gemset_name}" --create
8
+ else
9
+ echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."
10
+ fi
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'ffaker'
5
+ end
6
+
7
+ if RUBY_VERSION < "1.9"
8
+ gem "ruby-debug"
9
+ else
10
+ gem "ruby-debug19"
11
+ end
12
+
13
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,209 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ spree_downloads (1.0.0)
5
+ spree_core (~> 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.1.4)
11
+ actionpack (= 3.1.4)
12
+ mail (~> 2.3.0)
13
+ actionpack (3.1.4)
14
+ activemodel (= 3.1.4)
15
+ activesupport (= 3.1.4)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.6)
20
+ rack-cache (~> 1.1)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.3)
24
+ active_utils (1.0.3)
25
+ activesupport (>= 2.3.11)
26
+ i18n
27
+ activemerchant (1.20.1)
28
+ active_utils (>= 1.0.1)
29
+ activesupport (>= 2.3.11)
30
+ braintree (>= 2.0.0)
31
+ builder (>= 2.0.0)
32
+ i18n
33
+ json (>= 1.5.1)
34
+ money (<= 3.7.1)
35
+ activemodel (3.1.4)
36
+ activesupport (= 3.1.4)
37
+ builder (~> 3.0.0)
38
+ i18n (~> 0.6)
39
+ activerecord (3.1.4)
40
+ activemodel (= 3.1.4)
41
+ activesupport (= 3.1.4)
42
+ arel (~> 2.2.3)
43
+ tzinfo (~> 0.3.29)
44
+ activeresource (3.1.4)
45
+ activemodel (= 3.1.4)
46
+ activesupport (= 3.1.4)
47
+ activesupport (3.1.4)
48
+ multi_json (~> 1.0)
49
+ acts_as_list (0.1.4)
50
+ archive-tar-minitar (0.5.2)
51
+ arel (2.2.3)
52
+ braintree (2.14.0)
53
+ builder (>= 2.0.0)
54
+ builder (3.0.0)
55
+ capybara (1.0.1)
56
+ mime-types (>= 1.16)
57
+ nokogiri (>= 1.3.3)
58
+ rack (>= 1.0.0)
59
+ rack-test (>= 0.5.4)
60
+ selenium-webdriver (~> 2.0)
61
+ xpath (~> 0.1.4)
62
+ childprocess (0.3.1)
63
+ ffi (~> 1.0.6)
64
+ cocaine (0.2.1)
65
+ columnize (0.3.6)
66
+ deface (0.7.2)
67
+ nokogiri (~> 1.5.0)
68
+ rails (>= 3.0.9)
69
+ diff-lcs (1.1.3)
70
+ erubis (2.7.0)
71
+ factory_girl (2.6.1)
72
+ activesupport (>= 2.3.9)
73
+ ffaker (1.12.1)
74
+ ffi (1.0.11)
75
+ highline (1.6.8)
76
+ hike (1.2.1)
77
+ i18n (0.6.0)
78
+ jquery-rails (1.0.19)
79
+ railties (~> 3.0)
80
+ thor (~> 0.14)
81
+ json (1.6.5)
82
+ kaminari (0.13.0)
83
+ actionpack (>= 3.0.0)
84
+ activesupport (>= 3.0.0)
85
+ railties (>= 3.0.0)
86
+ linecache19 (0.5.12)
87
+ ruby_core_source (>= 0.1.4)
88
+ mail (2.3.2)
89
+ i18n (>= 0.4.0)
90
+ mime-types (~> 1.16)
91
+ treetop (~> 1.4.8)
92
+ meta_search (1.1.1)
93
+ actionpack (~> 3.1.0)
94
+ activerecord (~> 3.1.0)
95
+ activesupport (~> 3.1.0)
96
+ polyamorous (~> 0.5.0)
97
+ mime-types (1.17.2)
98
+ money (3.7.1)
99
+ i18n (~> 0.4)
100
+ multi_json (1.1.0)
101
+ nested_set (1.6.8)
102
+ activerecord (>= 3.0.0)
103
+ railties (>= 3.0.0)
104
+ nokogiri (1.5.0)
105
+ paperclip (2.5.0)
106
+ activerecord (>= 2.3.0)
107
+ activesupport (>= 2.3.2)
108
+ cocaine (>= 0.0.2)
109
+ mime-types
110
+ polyamorous (0.5.0)
111
+ activerecord (~> 3.0)
112
+ polyglot (0.3.3)
113
+ rack (1.3.6)
114
+ rack-cache (1.2)
115
+ rack (>= 0.4)
116
+ rack-mount (0.8.3)
117
+ rack (>= 1.0.0)
118
+ rack-ssl (1.3.2)
119
+ rack
120
+ rack-test (0.6.1)
121
+ rack (>= 1.0)
122
+ rails (3.1.4)
123
+ actionmailer (= 3.1.4)
124
+ actionpack (= 3.1.4)
125
+ activerecord (= 3.1.4)
126
+ activeresource (= 3.1.4)
127
+ activesupport (= 3.1.4)
128
+ bundler (~> 1.0)
129
+ railties (= 3.1.4)
130
+ railties (3.1.4)
131
+ actionpack (= 3.1.4)
132
+ activesupport (= 3.1.4)
133
+ rack-ssl (~> 1.3.2)
134
+ rake (>= 0.8.7)
135
+ rdoc (~> 3.4)
136
+ thor (~> 0.14.6)
137
+ rake (0.9.2.2)
138
+ rdoc (3.12)
139
+ json (~> 1.4)
140
+ rspec (2.8.0)
141
+ rspec-core (~> 2.8.0)
142
+ rspec-expectations (~> 2.8.0)
143
+ rspec-mocks (~> 2.8.0)
144
+ rspec-core (2.8.0)
145
+ rspec-expectations (2.8.0)
146
+ diff-lcs (~> 1.1.2)
147
+ rspec-mocks (2.8.0)
148
+ rspec-rails (2.8.1)
149
+ actionpack (>= 3.0)
150
+ activesupport (>= 3.0)
151
+ railties (>= 3.0)
152
+ rspec (~> 2.8.0)
153
+ ruby-debug-base19 (0.11.25)
154
+ columnize (>= 0.3.1)
155
+ linecache19 (>= 0.5.11)
156
+ ruby_core_source (>= 0.1.4)
157
+ ruby-debug19 (0.11.6)
158
+ columnize (>= 0.3.1)
159
+ linecache19 (>= 0.5.11)
160
+ ruby-debug-base19 (>= 0.11.19)
161
+ ruby_core_source (0.1.5)
162
+ archive-tar-minitar (>= 0.5.2)
163
+ rubyzip (0.9.6.1)
164
+ selenium-webdriver (2.20.0)
165
+ childprocess (>= 0.2.5)
166
+ ffi (~> 1.0)
167
+ multi_json (~> 1.0)
168
+ rubyzip
169
+ spree_core (1.0.1)
170
+ activemerchant (= 1.20.1)
171
+ acts_as_list (= 0.1.4)
172
+ deface (>= 0.7.2)
173
+ ffaker (~> 1.12.0)
174
+ highline (= 1.6.8)
175
+ jquery-rails (>= 1.0.18, <= 1.0.19)
176
+ kaminari (>= 0.13.0)
177
+ meta_search (= 1.1.1)
178
+ nested_set (= 1.6.8)
179
+ paperclip (= 2.5.0)
180
+ rails (>= 3.1.1, <= 3.1.4)
181
+ state_machine (= 1.1.1)
182
+ stringex (~> 1.3.0)
183
+ sprockets (2.0.3)
184
+ hike (~> 1.2)
185
+ rack (~> 1.0)
186
+ tilt (~> 1.1, != 1.3.0)
187
+ sqlite3 (1.3.5)
188
+ state_machine (1.1.1)
189
+ stringex (1.3.2)
190
+ thor (0.14.6)
191
+ tilt (1.3.3)
192
+ treetop (1.4.10)
193
+ polyglot
194
+ polyglot (>= 0.3.1)
195
+ tzinfo (0.3.32)
196
+ xpath (0.1.4)
197
+ nokogiri (~> 1.3)
198
+
199
+ PLATFORMS
200
+ ruby
201
+
202
+ DEPENDENCIES
203
+ capybara (= 1.0.1)
204
+ factory_girl
205
+ ffaker
206
+ rspec-rails (~> 2.7)
207
+ ruby-debug19
208
+ spree_downloads!
209
+ sqlite3
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ SpreeDownloads
2
+ ==============
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+ Testing
13
+ -------
14
+
15
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
16
+
17
+ $ bundle
18
+ $ bundle exec rake test app
19
+ $ bundle exec rspec spec
20
+
21
+ Copyright (c) 2012 [name of extension creator], released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/package_task'
5
+ require 'rspec/core/rake_task'
6
+ require 'spree/core/testing_support/common_rake'
7
+
8
+ RSpec::Core::RakeTask.new
9
+
10
+ task :default => [:spec]
11
+
12
+ spec = eval(File.read('spree_downloads.gemspec'))
13
+
14
+ Gem::PackageTask.new(spec) do |p|
15
+ p.gem_spec = spec
16
+ end
17
+
18
+ desc "Release to gemcutter"
19
+ task :release => :package do
20
+ require 'rake/gemcutter'
21
+ Rake::Gemcutter::Tasks.new(spec).define
22
+ Rake::Task['gem:push'].invoke
23
+ end
24
+
25
+ desc "Generates a dummy app for testing"
26
+ task :test_app do
27
+ ENV['LIB_NAME'] = 'spree_downloads'
28
+ Rake::Task['common:test_app'].invoke
29
+ end
data/Versionfile ADDED
@@ -0,0 +1,2 @@
1
+ "1.0.x" => { :branch => "master", :version => "1.0.1" }
2
+
@@ -0,0 +1 @@
1
+ //= require admin/spree_core
@@ -0,0 +1 @@
1
+ //= require store/spree_core
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_core
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require store/spree_core
3
+ */
@@ -0,0 +1,51 @@
1
+ # Controller voor het toevoegen van downloadcategorieen. Deze controller maakt geen gebruik van Ajax functionaliteiten,
2
+ # omdat Javascript geen toegang heeft tot lokale bestanden en het daarom onmogelijk is om via een remote form bestanden
3
+ # te uploaden.
4
+ class Spree::Admin::DownloadCategoriesController < Spree::Admin::ResourceController
5
+
6
+ def index
7
+ @download_categories = Spree::DownloadCategory.all
8
+ end
9
+
10
+ def new
11
+ @download_category = Spree::DownloadCategory.new
12
+ end
13
+
14
+ def edit
15
+ @download_category = Spree::DownloadCategory.find(params[:id])
16
+ end
17
+
18
+ def create
19
+ @download_category = Spree::DownloadCategory.new(params[:download_category])
20
+
21
+ if @download_category.save
22
+ flash.now[:notice] = t('admin.download_categories.form.created')
23
+ redirect_to :action => :index
24
+ else
25
+ respond_with @download_category
26
+ end
27
+ end
28
+
29
+ def update
30
+ @download_category = Spree::DownloadCategory.find(params[:id])
31
+
32
+ if @download_category.update_attributes(params[:download_category])
33
+ flash.now[:notice] = t('admin.download_categories.form.updated')
34
+ redirect_to :action => :index
35
+ else
36
+ # Toon het formulier.
37
+ @render_form = true
38
+ @download_categories = Spree::DownloadCategory.all
39
+
40
+ render :action => :index
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ @download_category = Spree::DownloadCategory.find(params[:id])
46
+ @download_category.destroy
47
+ @download_categories = Spree::DownloadCategory.all
48
+
49
+ flash.now[:notice] = t('admin.download_categories.form.deleted')
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ class Spree::Admin::DownloadsController < Spree::Admin::ResourceController
2
+
3
+ def index
4
+ @downloads = Spree::Download.all
5
+ end
6
+
7
+ def new
8
+ @download = Spree::Download.new
9
+ initialize_lists
10
+ end
11
+
12
+ def edit
13
+ @download = Spree::Download.find(params[:id])
14
+ initialize_lists
15
+ end
16
+
17
+ def create
18
+ @download = Spree::Download.new(params[:download])
19
+
20
+ if @download.save
21
+ redirect_to(admin_downloads_url)
22
+ else
23
+ initialize_lists
24
+ render :action => "new"
25
+ end
26
+ end
27
+
28
+ def update
29
+ @download = Spree::Download.find(params[:id])
30
+
31
+ if @download.update_attributes(params[:download])
32
+ redirect_to(admin_downloads_url)
33
+ else
34
+ initialize_lists
35
+ render :action => "new"
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @download = Spree::Download.find(params[:id])
41
+ @download.destroy
42
+
43
+ redirect_to(admin_downloads_url)
44
+ end
45
+
46
+
47
+ private
48
+
49
+ def initialize_lists
50
+ @downloads = Spree::Download.all
51
+ @download_categories = Spree::DownloadCategory.all
52
+ @languages = Language::ALL_LANGUAGES
53
+ @products = Spree::Product.where(:is_printer => true)
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ class Spree::DownloadsController < Spree::BaseController
2
+
3
+ def index
4
+ @download_categories = Spree::DownloadCategory.all
5
+ @printers = Spree::Product.where(:is_printer => true)
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ class Spree::Download < ActiveRecord::Base
2
+ belongs_to :download_category
3
+ has_one :language
4
+ has_many :download_products
5
+ has_many :products, :through => :download_products
6
+
7
+ validates_presence_of :name, :url, :download_category_id
8
+ validates_numericality_of :download_category_id
9
+
10
+ # Bepaalt of deze download relevant is voor het meegegeven product.
11
+ def is_relevant_for_product?(product)
12
+ self.products.include?(product)
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class Spree::DownloadCategory < ActiveRecord::Base
2
+ has_attached_file :icon, :styles => { :mini => ["48x48#", :png] }
3
+ has_many :downloads
4
+
5
+ validates_presence_of :name
6
+ validates_attachment_presence :icon, :on => :create
7
+ validates_length_of :name, :maximum => 100
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+ class Spree::DownloadProduct < ActiveRecord::Base
2
+ validates_presence_of :product_id, :download_id
3
+ belongs_to :product
4
+ belongs_to :download
5
+ end
6
+
@@ -0,0 +1,4 @@
1
+ Spree::Product.class_eval do
2
+ has_many :download_products
3
+ has_many :downloads, :through => :download_products
4
+ end
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => "spree/layouts/admin",
2
+ :name => "downloads_admin_tabs",
3
+ :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
4
+ :text => "<%= tab(:downloads, :url => admin_downloads_path) %>",
5
+ :disabled => false)
@@ -0,0 +1,15 @@
1
+ <table class="index">
2
+ <tr>
3
+ <th><%= t('activerecord.attributes.download_category.name') %></th>
4
+ <th class="tc"><%= t('scaffold.actions') %></th>
5
+ </tr>
6
+ <% @download_categories.each do |download_category| %>
7
+ <tr>
8
+ <td><%= download_category.name %></td>
9
+ <td class="actions">
10
+ <%= link_to_edit download_category, :class => "edit" %>
11
+ <%= link_to_delete download_category %>
12
+ </td>
13
+ </tr>
14
+ <% end %>
15
+ </table>
@@ -0,0 +1,20 @@
1
+ <%= form_for([:admin, @download_category], :html => {:id => "download_category_form", :multipart => true}) do |f| %>
2
+ <fieldset>
3
+ <%= f.label :name %><span class="required">*</span><br />
4
+ <%= f.text_field :name, :class => "fullwidth title" %>
5
+ <%= f.error_message_on :name %>
6
+
7
+ <div class="clearfix" data-hook="new_product_attrs">
8
+ <div class="left">
9
+
10
+ <%= f.label :icon %><span class="required">*</span>
11
+ <%= f.file_field :icon %>
12
+ <%= f.error_message_on :icon %>
13
+
14
+ </div>
15
+ </div>
16
+
17
+ <%= render :partial => 'spree/admin/shared/new_resource_links' %>
18
+
19
+ </fieldset>
20
+ <% end %>
@@ -0,0 +1,8 @@
1
+ $("#download_categories").html("<%= escape_javascript(render("download_categories"))%>");
2
+ $("#flash_notice").html("<%= flash[:notice] %>")
3
+ $("#flash_notice_column").show('blind', {}, 300);
4
+
5
+ /* Hide the form. */
6
+ $("#form-column").hide('blind', {}, 300);
7
+ $("#download_category-form").html("");
8
+
@@ -0,0 +1,5 @@
1
+ <div class="clear"></div>
2
+
3
+ <%= render :partial => "form" %>
4
+
5
+ <div class="clear"></div>
@@ -0,0 +1,4 @@
1
+ $("#form").html("<%= escape_javascript(render("form"))%>");
2
+ $("#form-column").show(300);
3
+ $("#form_title").html("<%= t('admin.download_categories.index.edit') %>");
4
+
@@ -0,0 +1,16 @@
1
+ <%= render :partial => 'spree/admin/shared/download_sub_menu' %>
2
+
3
+ <div class="toolbar">
4
+ <ul class="actions">
5
+ <li id="new_download_category_link">
6
+ <%= button_link_to 'New download category', new_admin_download_category_path, {:remote => true, :icon => 'add', :id => 'admin_new_download_category'} %>
7
+ </li>
8
+ </ul>
9
+ <br class="clear" />
10
+ </div>
11
+
12
+ <h1><%= t('.listing') %></h1>
13
+
14
+ <div id="new_download_category"></div>
15
+
16
+ <%= render "download_categories" %>
@@ -0,0 +1,3 @@
1
+ <%= render :partial => 'spree/admin/shared/download_sub_menu' %>
2
+
3
+ <%= render :partial => 'form' %>
@@ -0,0 +1,2 @@
1
+ $("#new_download_category").html('<%= escape_javascript(render :partial => "form") %>');
2
+ // $("#admin_new_download_category").parent().hide();
@@ -0,0 +1,10 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @download_category.name %>
6
+ </p>
7
+
8
+
9
+ <%= link_to 'Edit', edit_download_category_path(@download_category) %> |
10
+ <%= link_to 'Back', download_categories_path %>
@@ -0,0 +1,36 @@
1
+ <div data-hook="toolbar" class="toolbar">
2
+ <ul class="actions">
3
+ <li id="new_product_link">
4
+ <%= button_link_to "New download", new_admin_download_path, {:remote => true, :icon => 'add', :id => 'admin_new_download'} %>
5
+ </li>
6
+ </ul>
7
+ <br class="clear">
8
+ </div>
9
+
10
+ <h1>Listing downloads</h1>
11
+
12
+ <div id="new_download"></div>
13
+
14
+ <table class="index">
15
+ <tr>
16
+ <th><%= t('activerecord.attributes.download.name') %></th>
17
+ <th><%= t('activerecord.attributes.download_category.name') %></th>
18
+ <th><%= t('activerecord.attributes.download.products') %></th>
19
+ <th class="tc"><%= t('scaffold.actions') %></th>
20
+ </tr>
21
+ <% @downloads.each do |download| %>
22
+ <tr>
23
+ <td><%= download.name %></td>
24
+ <td><%= download.download_category.name %></td>
25
+ <td>
26
+ <% download.products.each do |product| %>
27
+ <span><%= product.name %>, </span>
28
+ <% end %>
29
+ </td>
30
+ <td class="actions">
31
+ <%= link_to_edit download, :class => "edit" %>
32
+ <%= link_to_delete download %>
33
+ </td>
34
+ </tr>
35
+ <% end %>
36
+ </table>
@@ -0,0 +1,41 @@
1
+ <%= form_for([:admin, @download], :html => {:id => "download_form"}) do |f| %>
2
+ <fieldset>
3
+ <%= f.label :name %><span class="required">*</span><br />
4
+ <%= f.text_field :name, :class => "title" %>
5
+ <%= f.error_message_on :name %>
6
+
7
+ <br />
8
+
9
+ <%= f.label :url %><span class="required">*</span><br />
10
+ <%= f.text_field :url, :class => 'fullwidth' %>
11
+ <%= f.error_message_on :url %>
12
+
13
+
14
+ <div class="clearfix" data-hook="new_product_attrs">
15
+ <div class="left">
16
+
17
+ <%= f.label :download_category_id %><span class="required">*</span><br />
18
+ <%= f.select :download_category_id, @download_categories.collect {|category| [category.name, category.id]} %>
19
+ <%= f.error_message_on :download_category_id %>
20
+
21
+ <br/>
22
+
23
+ <%= f.label :language_id %><span class="required">*</span><br />
24
+ <%= f.select :language_id, @languages.collect {|language| [language[:name], language[:id]]} %>
25
+ <%= f.error_message_on :language_id %>
26
+
27
+ </div>
28
+ <div class="right">
29
+
30
+ <%= f.label :products %><span class="required">*</span><br />
31
+ <% @products.each do |product| -%>
32
+ <%= check_box_tag "download[product_ids][]", product.id, @download.is_relevant_for_product?(product), :id => "download_product_id_#{product.id}" -%> <%= f.label "product_id_#{product.id}", product.name -%><br />
33
+ <% end -%>
34
+ <%= f.error_message_on :products %>
35
+
36
+ </div>
37
+ </div>
38
+
39
+ <%= render :partial => 'spree/admin/shared/new_resource_links' %>
40
+ </fieldset>
41
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div class="clear"></div>
2
+
3
+ <%= render :partial => "form" %>
4
+
5
+ <div class="clear"></div>
6
+
@@ -0,0 +1,4 @@
1
+ <%= render :partial => 'spree/admin/shared/download_sub_menu' %>
2
+
3
+ <%= render :partial => "downloads" %>
4
+
@@ -0,0 +1,3 @@
1
+ <%= render :partial => 'spree/admin/shared/download_sub_menu' %>
2
+
3
+ <%= render :partial => 'form' %>
@@ -0,0 +1,2 @@
1
+ $("#new_download").html('<%= escape_javascript(render :partial => "form") %>');
2
+ $("#admin_new_download").parent().hide();
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @admin_download.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Language:</b>
10
+ <%= @admin_download.language_id %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_admin_download_path(@admin_download) %> |
15
+ <%= link_to 'Back', admin_downloads_path %>
@@ -0,0 +1,6 @@
1
+ <% content_for :sub_menu do %>
2
+ <ul id="sub_nav">
3
+ <%= tab :downloads, :url => admin_downloads_path %>
4
+ <%= tab :download_categories, :url => admin_download_categories_path %>
5
+ </ul>
6
+ <% end %>
@@ -0,0 +1,39 @@
1
+ <div id="downloads">
2
+ <div id="select-downloads" class="left">
3
+ <%- @printers.each do |printer| %>
4
+ <%= link_to printer.name, "#", :class => "printer-#{printer.id}", :style => ("background-image:url('#{printer.images.first.attachment.url(:mini)}')" if printer.images.any?) %><br />
5
+ <%- end %>
6
+ </div>
7
+
8
+ <div class="right" id="show-downloads">
9
+ <%- @download_categories.each do |category| %>
10
+ <div class="show-category-<%= category.id %>" style="display:none;">
11
+ <h2><%= category.name %></h2>
12
+ <br />
13
+ <%- category.downloads.each do |download| %>
14
+ <%= link_to download.name, download.url %><br />
15
+ <%- end %>
16
+ </div>
17
+ <%- end %>
18
+
19
+ <%- @printers.each do |printer| %>
20
+ <div class="show-printer-<%= printer.id %>" style="display:none;">
21
+ <h2><%= printer.name %></h2>
22
+ <br />
23
+ <%- @download_categories.each do |category| %>
24
+ <h3 style="background-image:url('<%= category.icon.url(:mini) %>')"><%= category.name %></h3>
25
+ <% category.downloads.each do |download| %>
26
+ <%= link_to download.name, download.url if printer.downloads.map(&:id).include? download.id %><br />
27
+ <% end %>
28
+ <% end %>
29
+ </div>
30
+ <%- end %>
31
+ </div>
32
+ </div>
33
+
34
+ <script type="text/javascript">
35
+ $('#select-downloads a').click(function() {
36
+ $('#show-downloads').children().hide();
37
+ $('.show-' + $(this).attr('class')).show();
38
+ });
39
+ </script>
@@ -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,8 @@
1
+ Spree::Core::Engine.routes.prepend do
2
+ namespace :admin do
3
+ resources :download_categories
4
+ resources :downloads
5
+ end
6
+
7
+ resources :downloads
8
+ end
@@ -0,0 +1,12 @@
1
+ class CreateSpreeDownloads < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_downloads do |t|
4
+ t.string :name, :null => false
5
+ t.integer :download_category_id, :null => false
6
+ t.integer :language_id
7
+ t.string :url
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class SpreeDownloadProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_download_products do |t|
4
+ t.integer :download_id
5
+ t.integer :product_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class CreateSpreeDownloadCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :spree_download_categories do |t|
4
+ t.string :name, :null => false
5
+
6
+ t.string :icon_file_name, :null => false
7
+ t.string :icon_content_type, :null => false
8
+ t.integer :icon_file_size, :null => false
9
+ t.datetime :icon_updated_at, :null => false
10
+
11
+ t.boolean :contains_applications, :null => :false, :default => false
12
+ t.boolean :contains_movies, :null => :false, :default => false
13
+ t.boolean :contains_brochures, :null => :false, :default => false
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module SpreeDownloads
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ def add_javascripts
6
+ append_file "app/assets/javascripts/store/all.js", "//= require store/spree_downloads\n"
7
+ append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_downloads\n"
8
+ end
9
+
10
+ def add_stylesheets
11
+ inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_downloads\n", :before => /\*\//, :verbose => true
12
+ inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_downloads\n", :before => /\*\//, :verbose => true
13
+ end
14
+
15
+ def add_migrations
16
+ run 'bundle exec rake railties:install:migrations FROM=spree_downloads'
17
+ end
18
+
19
+ def run_migrations
20
+ res = ask "Would you like to run the migrations now? [Y/n]"
21
+ if res == "" || res.downcase == "y"
22
+ run 'bundle exec rake db:migrate'
23
+ else
24
+ puts "Skiping rake db:migrate, don't forget to run it!"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module SpreeDownloads
2
+ class Engine < Rails::Engine
3
+ engine_name 'spree_downloads'
4
+
5
+ config.autoload_paths += %W(#{config.root}/lib)
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+
17
+ #loads application's deface view overrides
18
+ Dir.glob File.expand_path("../../app/overrides/*.rb", __FILE__) do |c|
19
+ Rails.application.config.cache_classes ? require(c) : load(c)
20
+ end
21
+ end
22
+
23
+ config.to_prepare &method(:activate).to_proc
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_downloads/engine'
data/script/rails ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_PATH = File.expand_path('../..', __FILE__)
5
+ load File.expand_path('../../spec/dummy/script/rails', __FILE__)
@@ -0,0 +1,32 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+
6
+ require 'rspec/rails'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
11
+
12
+ # Requires factories defined in spree_core
13
+ require 'spree/core/testing_support/factories'
14
+
15
+ RSpec.configure do |config|
16
+ # == Mock Framework
17
+ #
18
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
19
+ #
20
+ # config.mock_with :mocha
21
+ # config.mock_with :flexmock
22
+ # config.mock_with :rr
23
+ config.mock_with :rspec
24
+
25
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
26
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
27
+
28
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
29
+ # examples within a transaction, remove the following line or assign false
30
+ # instead of true.
31
+ config.use_transactional_fixtures = true
32
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_downloads'
5
+ s.version = '1.0.1'
6
+ s.summary = 'Adds a downloads (via urls) page for products'
7
+ s.description = 'Manage downloads and download categories in the admin'
8
+ s.required_ruby_version = '>= 1.8.7'
9
+
10
+ s.author = 'Martijn Lafeber'
11
+ s.email = 'martijn@coupling.nl'
12
+ s.homepage = 'http://www.coupling.nl'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency 'spree_core', '~> 1.0.0'
20
+
21
+ s.add_development_dependency 'capybara', '1.0.1'
22
+ s.add_development_dependency 'factory_girl'
23
+ s.add_development_dependency 'ffaker'
24
+ s.add_development_dependency 'rspec-rails', '~> 2.7'
25
+ s.add_development_dependency 'sqlite3'
26
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_downloads
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martijn Lafeber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: &70185889364860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70185889364860
25
+ - !ruby/object:Gem::Dependency
26
+ name: capybara
27
+ requirement: &70185889364220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.1
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70185889364220
36
+ - !ruby/object:Gem::Dependency
37
+ name: factory_girl
38
+ requirement: &70185889363640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70185889363640
47
+ - !ruby/object:Gem::Dependency
48
+ name: ffaker
49
+ requirement: &70185889362940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70185889362940
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec-rails
60
+ requirement: &70185889362160 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '2.7'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70185889362160
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: &70185889361300 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70185889361300
80
+ description: Manage downloads and download categories in the admin
81
+ email: martijn@coupling.nl
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - .rvmrc
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - Versionfile
95
+ - app/assets/javascripts/admin/spree_downloads.js
96
+ - app/assets/javascripts/store/spree_downloads.js
97
+ - app/assets/stylesheets/admin/spree_downloads.css
98
+ - app/assets/stylesheets/store/spree_downloads.css
99
+ - app/controllers/spree/admin/download_categories_controller.rb
100
+ - app/controllers/spree/admin/downloads_controller.rb
101
+ - app/controllers/spree/downloads_controller.rb
102
+ - app/models/spree/download.rb
103
+ - app/models/spree/download_category.rb
104
+ - app/models/spree/download_product.rb
105
+ - app/models/spree/product_decorator.rb
106
+ - app/overrides/spree_downloads.rb
107
+ - app/views/spree/admin/download_categories/_download_categories.html.erb
108
+ - app/views/spree/admin/download_categories/_form.html.erb
109
+ - app/views/spree/admin/download_categories/destroy.js.erb
110
+ - app/views/spree/admin/download_categories/edit.html.erb
111
+ - app/views/spree/admin/download_categories/edit.js.erb
112
+ - app/views/spree/admin/download_categories/index.html.erb
113
+ - app/views/spree/admin/download_categories/new.html.erb
114
+ - app/views/spree/admin/download_categories/new.js.erb
115
+ - app/views/spree/admin/download_categories/show.html.erb
116
+ - app/views/spree/admin/downloads/_downloads.html.erb
117
+ - app/views/spree/admin/downloads/_form.html.erb
118
+ - app/views/spree/admin/downloads/edit.html.erb
119
+ - app/views/spree/admin/downloads/index.html.erb
120
+ - app/views/spree/admin/downloads/new.html.erb
121
+ - app/views/spree/admin/downloads/new.js.erb
122
+ - app/views/spree/admin/downloads/show.html.erb
123
+ - app/views/spree/admin/shared/_download_sub_menu.html.erb
124
+ - app/views/spree/downloads/index.html.erb
125
+ - config/locales/en.yml
126
+ - config/routes.rb
127
+ - db/migrate/20120308131418_create_spree_downloads.rb
128
+ - db/migrate/20120308131708_create_spree_download_products.rb
129
+ - db/migrate/20120308132352_create_spree_download_categories.rb
130
+ - lib/generators/spree_downloads/install/install_generator.rb
131
+ - lib/spree_downloads.rb
132
+ - lib/spree_downloads/engine.rb
133
+ - script/rails
134
+ - spec/spec_helper.rb
135
+ - spree_downloads.gemspec
136
+ homepage: http://www.coupling.nl
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: 1.8.7
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements:
155
+ - none
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.10
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Adds a downloads (via urls) page for products
161
+ test_files:
162
+ - spec/spec_helper.rb