spree_easy_homepage 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/.travis.yml +51 -0
- data/Appraisals +28 -0
- data/Gemfile +18 -0
- data/LICENSE +26 -0
- data/README.md +124 -0
- data/Rakefile +22 -0
- data/app/assets/javascripts/spree/backend/product_autosearch.js +33 -0
- data/app/assets/javascripts/spree/backend/spree_easy_homepage.js +42 -0
- data/app/assets/javascripts/spree/frontend/spree_easy_homepage.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_easy_homepage.scss +12 -0
- data/app/concerns/spree/product_ids_processable.rb +19 -0
- data/app/controllers/spree/admin/base_controller_decorator.rb +13 -0
- data/app/controllers/spree/admin/home_sections_controller.rb +6 -0
- data/app/helpers/spree/admin/home_section_helper.rb +28 -0
- data/app/helpers/spree/easy_homepage_helper.rb +29 -0
- data/app/models/spree/home_section.rb +44 -0
- data/app/models/spree/home_section_product.rb +8 -0
- data/app/models/spree/product_decorator.rb +29 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration.rb +8 -0
- data/app/presenter/spree/easy_homepage/product_presenter.rb +40 -0
- data/app/views/spree/admin/home_section_products/_line_item.js.erb +27 -0
- data/app/views/spree/admin/home_sections/_form.html.erb +48 -0
- data/app/views/spree/admin/home_sections/edit.html.erb +11 -0
- data/app/views/spree/admin/home_sections/index.html.erb +52 -0
- data/app/views/spree/admin/home_sections/new.html.erb +11 -0
- data/app/views/spree/admin/products/_autosearch.js.erb +16 -0
- data/app/views/spree/shared/_home_sections.html.erb +16 -0
- data/bin/rails +8 -0
- data/config/locales/en.yml +16 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20191228110047_create_spree_home_section.rb +10 -0
- data/db/migrate/20191228112655_create_spree_home_section_product.rb +11 -0
- data/gemfiles/spree_3_5.gemfile +10 -0
- data/gemfiles/spree_3_7.gemfile +11 -0
- data/gemfiles/spree_4_0.gemfile +10 -0
- data/gemfiles/spree_master.gemfile +10 -0
- data/lib/generators/spree_easy_homepage/install/install_generator.rb +29 -0
- data/lib/spree_easy_homepage.rb +4 -0
- data/lib/spree_easy_homepage/engine.rb +20 -0
- data/lib/spree_easy_homepage/version.rb +17 -0
- data/spree_easy_homepage.gemspec +47 -0
- metadata +408 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 07a6b8470e8fe93f97aee4eef3e1a20b8a70a1b4e5959a6f46419009e5c1dc83
|
4
|
+
data.tar.gz: 011fb3662bd6335ed7886e47f10fa826e8a12011edbaa7268b937ee1314236cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9555510dfd993241ae76c4fe2ba017bf71bf0ab8d10ba80f574365fca1e5e1cc081ce83272dab49dae9902d33134d986a3d8c24fc7823d0f6485f051d951472
|
7
|
+
data.tar.gz: 1c4890144873221edad49e955619d8a46c6840b5bc65fa1d5434fa2f979a1df3464ffedf3af1e5b269381a02d6e8b1d72af8290ad042613fb963625fd9a5c19f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
\#*
|
2
|
+
*~
|
3
|
+
.#*
|
4
|
+
.DS_Store
|
5
|
+
.idea
|
6
|
+
.localeapp/locales
|
7
|
+
.project
|
8
|
+
.vscode
|
9
|
+
coverage
|
10
|
+
default
|
11
|
+
Gemfile.lock
|
12
|
+
tmp
|
13
|
+
nbproject
|
14
|
+
pkg
|
15
|
+
*.sw?
|
16
|
+
spec/dummy
|
17
|
+
.rvmrc
|
18
|
+
.sass-cache
|
19
|
+
public/spree
|
20
|
+
.ruby-version
|
21
|
+
.ruby-gemset
|
22
|
+
gemfiles/*.gemfile.lock
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require: rubocop-rails
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
TargetRubyVersion: 2.6.4
|
6
|
+
Exclude:
|
7
|
+
- 'spec/**/*'
|
8
|
+
- 'lib/generators/**/*'
|
9
|
+
- 'bin/rails'
|
10
|
+
- 'lib/spree_easy_homepage/engine.rb'
|
11
|
+
|
12
|
+
Rails:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Gemspec/RequiredRubyVersion:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Rails/BelongsTo:
|
25
|
+
Exclude:
|
26
|
+
- 'app/models/spree/home_section_product.rb'
|
27
|
+
|
28
|
+
Layout/LineLength:
|
29
|
+
Exclude:
|
30
|
+
- 'app/overrides/spree/admin/shared/sub_menu/_configuration.rb'
|
31
|
+
- 'spree_easy_homepage.gemspec'
|
32
|
+
|
33
|
+
Rails/RakeEnvironment:
|
34
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
sudo: required
|
2
|
+
dist: trusty
|
3
|
+
|
4
|
+
language: ruby
|
5
|
+
|
6
|
+
env:
|
7
|
+
- DB=postgres
|
8
|
+
- DB=mysql
|
9
|
+
|
10
|
+
addons:
|
11
|
+
chrome: stable
|
12
|
+
postgresql: 9.4
|
13
|
+
|
14
|
+
gemfile:
|
15
|
+
- gemfiles/spree_3_5.gemfile
|
16
|
+
- gemfiles/spree_3_7.gemfile
|
17
|
+
- gemfiles/spree_4_0.gemfile
|
18
|
+
- gemfiles/spree_master.gemfile
|
19
|
+
|
20
|
+
script:
|
21
|
+
- bundle exec rake test_app
|
22
|
+
- bundle exec rake spec
|
23
|
+
|
24
|
+
rvm:
|
25
|
+
- 2.5.1
|
26
|
+
- 2.4.4
|
27
|
+
- 2.3.8
|
28
|
+
|
29
|
+
matrix:
|
30
|
+
allow_failures:
|
31
|
+
- gemfile: gemfiles/spree_master.gemfile
|
32
|
+
exclude:
|
33
|
+
- rvm: 2.3.8
|
34
|
+
gemfile: gemfiles/spree_4_0.gemfile
|
35
|
+
- rvm: 2.4.4
|
36
|
+
gemfile: gemfiles/spree_4_0.gemfile
|
37
|
+
- rvm: 2.3.8
|
38
|
+
gemfile: gemfiles/spree_master.gemfile
|
39
|
+
- rvm: 2.4.4
|
40
|
+
gemfile: gemfiles/spree_master.gemfile
|
41
|
+
- rvm: 2.5.1
|
42
|
+
gemfile: gemfiles/spree_3_5.gemfile
|
43
|
+
|
44
|
+
before_install:
|
45
|
+
- mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
|
46
|
+
- wget -N https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip -P ~/
|
47
|
+
- unzip ~/chromedriver_linux64.zip -d ~/
|
48
|
+
- rm ~/chromedriver_linux64.zip
|
49
|
+
- sudo mv -f ~/chromedriver /usr/local/share/
|
50
|
+
- sudo chmod +x /usr/local/share/chromedriver
|
51
|
+
- sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
|
data/Appraisals
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
appraise 'spree-3-5' do
|
2
|
+
gem 'spree_core', '~> 3.5.0'
|
3
|
+
gem 'spree_backend', '~> 3.5.0'
|
4
|
+
gem 'spree_auth_devise', '~> 3.4.0'
|
5
|
+
gem 'rails-controller-testing'
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise 'spree-3-7' do
|
9
|
+
gem 'spree_core', '~> 3.7.0'
|
10
|
+
gem 'spree_backend', '~> 3.7.0'
|
11
|
+
gem 'spree_auth_devise', '~> 3.5.0'
|
12
|
+
gem 'rails-controller-testing'
|
13
|
+
gem 'sass-rails'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'spree-4-0' do
|
17
|
+
gem 'spree_core', '~> 4.0.0.rc2'
|
18
|
+
gem 'spree_backend', '~> 4.0.0.rc2'
|
19
|
+
gem 'spree_auth_devise', '~> 4.0'
|
20
|
+
gem 'rails-controller-testing'
|
21
|
+
end
|
22
|
+
|
23
|
+
appraise 'spree-master' do
|
24
|
+
gem 'spree_core', github: 'spree/spree', branch: 'master'
|
25
|
+
gem 'spree_backend', github: 'spree/spree', branch: 'master'
|
26
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
|
27
|
+
gem 'rails-controller-testing'
|
28
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) do |repo_name|
|
4
|
+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
|
5
|
+
"https://github.com/#{repo_name}.git"
|
6
|
+
end
|
7
|
+
|
8
|
+
gem 'spree_backend', github: 'spree/spree', branch: 'master'
|
9
|
+
gem 'spree_core', github: 'spree/spree', branch: 'master'
|
10
|
+
# Provides basic authentication functionality for testing parts of your engine
|
11
|
+
gem 'rails-controller-testing'
|
12
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
|
13
|
+
|
14
|
+
gem 'rubocop', require: false
|
15
|
+
gem 'rubocop-rails', require: false
|
16
|
+
gem 'rubocop-rspec', require: false
|
17
|
+
|
18
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2019 [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,124 @@
|
|
1
|
+
# SpreeEasyHomepage
|
2
|
+
|
3
|
+
This is a complete open source [Spree](https://github.com/spree/spree) extension for easily managing your website's homepage products. Particularly useful for programmers who have clients or users with limited technological literacy. The current default operation for managing your homepage is cumbersome and time consuming for what is suppose to be a simple operation. Spree also does not include related frontend helpers which would require effort from the programmer to create and maintain.
|
4
|
+
|
5
|
+
![SpreeEasyHomepage Demonstration](https://media.giphy.com/media/ekedAYQFgW0iIW1hCg/giphy.gif)
|
6
|
+
|
7
|
+
**SpreeEasyHomepage** provides a beautiful and intuitive interface for populating and categorizing products without compromising ease of use. Developers would be delighted to know that setup is as simple as calling a single method from the view.
|
8
|
+
|
9
|
+
|
10
|
+
Getting Started
|
11
|
+
----------------------
|
12
|
+
|
13
|
+
##### Add this extension to your Gemfile with this line:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'spree_easy_homepage'
|
17
|
+
```
|
18
|
+
|
19
|
+
##### Install the gem
|
20
|
+
|
21
|
+
```shell
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
##### Run the install generators from your console
|
26
|
+
|
27
|
+
```shell
|
28
|
+
rails g spree_easy_homepage:install
|
29
|
+
```
|
30
|
+
|
31
|
+
Admins can manage their Homepage by navigating to the configurations tab from the sidebar.
|
32
|
+
|
33
|
+
Frontend Setup
|
34
|
+
----------------------
|
35
|
+
|
36
|
+
#### To populate your homepage with products
|
37
|
+
|
38
|
+
Expose this gem's frontend helper in your controller, eg:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class ApplicationController < ActionController::Base
|
42
|
+
helper Spree::EasyHomepageHelper
|
43
|
+
end
|
44
|
+
```
|
45
|
+
Then from your view, add the helper method `fill_with_sections` eg:
|
46
|
+
|
47
|
+
```
|
48
|
+
<div class="row">
|
49
|
+
<%= fill_with_sections %>
|
50
|
+
</div>
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Thats it!
|
54
|
+
|
55
|
+
`fill_with_sections` defaults to use the product "tile" partial in `app/views/spree/products/_product.html.erb`. If none are found in your project folder, the call is delegated to the official "tile" partial used by Spree.
|
56
|
+
|
57
|
+
The default product "tile" partial can be optionally overridden by passing `locals: {product_partial: '/path/to/tile_partial'}` in `fill_with_sections` arguments. EG:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
fill_with_sections(locals: {product_partial: 'spree/shared/product_tile'})
|
61
|
+
```
|
62
|
+
|
63
|
+
If you want to pass variables to the product "tile" partial, you can use `product_locals: {}`, similar to the procedure above. EG:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
fill_with_sections(locals: {product_locals: {taxon: @taxon, product_tile_size: :small}})
|
67
|
+
```
|
68
|
+
|
69
|
+
deep inside the helper, between the products loop, the locals passed from the above code is passed to the product "tile" partial:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
render partial: 'spree/products/product', locals: {product: product, taxon: @taxon, product_tile_size: :small}
|
73
|
+
```
|
74
|
+
|
75
|
+
Information
|
76
|
+
----------------------
|
77
|
+
|
78
|
+
#### Editing the view generated by `fill_with_sections`
|
79
|
+
|
80
|
+
By default, `fill_with_sections` renders the `_home_sections.html.erb` partial located in `app/views/spree/shared/`. To change the default path.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
fill_with_sections(partial: 'spree/shared/custom_home_sections')
|
84
|
+
```
|
85
|
+
|
86
|
+
or simply create a `_home_sections.html.erb` partial file in your `spree/shared` folder.
|
87
|
+
|
88
|
+
If you want to edit the HTML elements outputted by `fill_with_sections`. Investigate the `shared/_home_sections.html.erb` partial from the gem then override with your edited version in your main project as instructed above.
|
89
|
+
|
90
|
+
Testing via Rspec
|
91
|
+
----------------------
|
92
|
+
|
93
|
+
From the gem's root folder
|
94
|
+
|
95
|
+
```shell
|
96
|
+
bundle install
|
97
|
+
```
|
98
|
+
|
99
|
+
Generate a dummy app via Rspec
|
100
|
+
|
101
|
+
```shell
|
102
|
+
bundle exec rake generate_dummy_app
|
103
|
+
```
|
104
|
+
|
105
|
+
Then call Rspec
|
106
|
+
|
107
|
+
```shell
|
108
|
+
rspec
|
109
|
+
```
|
110
|
+
|
111
|
+
Note: for feature tests, chrome (headless) is selected by default.
|
112
|
+
|
113
|
+
|
114
|
+
##### Run the install generators from your console
|
115
|
+
|
116
|
+
```shell
|
117
|
+
rails g spree_easy_homepage:install
|
118
|
+
```
|
119
|
+
|
120
|
+
Contributing
|
121
|
+
----------------------
|
122
|
+
This gem has only been released recently. Feedback is appreciated. I have no guidelines for pull-requests other than the basic description and reproduction steps (for bugs). Proper OOP must be followed for feature submissions.
|
123
|
+
|
124
|
+
Copyright (c) 2020 [Jibril Tapiador](https://www.jibril.ch/), released under the New BSD License.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
|
19
|
+
task :generate_dummy_app do
|
20
|
+
ENV['LIB_NAME'] = 'spree_easy_homepage'
|
21
|
+
Rake::Task['extension:test_app'].invoke
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
(function ($) {
|
2
|
+
$.fn.productAutoSearch = function(formatResult) {
|
3
|
+
return this.select2({
|
4
|
+
placeholder: Spree.translations.product_placeholder,
|
5
|
+
minimumInputLength: 3,
|
6
|
+
ajax: {
|
7
|
+
url: Spree.routes.products_api,
|
8
|
+
quietMillis: 200,
|
9
|
+
datatype: 'json',
|
10
|
+
cache: true,
|
11
|
+
data: function(term) {
|
12
|
+
return {
|
13
|
+
q: {
|
14
|
+
name_or_master_sku_cont: term
|
15
|
+
},
|
16
|
+
token: Spree.api_key,
|
17
|
+
per_page: 5
|
18
|
+
};
|
19
|
+
},
|
20
|
+
results: function(data) {
|
21
|
+
var products = data.products ? data.products : [];
|
22
|
+
return {
|
23
|
+
results: data.products
|
24
|
+
};
|
25
|
+
}
|
26
|
+
},
|
27
|
+
formatResult: formatResult,
|
28
|
+
formatSelection: function(product) {
|
29
|
+
return Select2.util.escapeMarkup(product.name);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
};
|
33
|
+
})(jQuery);
|
@@ -0,0 +1,42 @@
|
|
1
|
+
(function ($) {
|
2
|
+
const addProductSection = function(product, lineItemTemplate) {
|
3
|
+
$("#section-product-list").append(lineItemTemplate({product: product}));
|
4
|
+
};
|
5
|
+
|
6
|
+
const fillSectionsList = function(lineItemTemplate) {
|
7
|
+
const products = $("#section-product-list").data("home-sections");
|
8
|
+
$.each(products, function() {
|
9
|
+
addProductSection(this, lineItemTemplate);
|
10
|
+
});
|
11
|
+
};
|
12
|
+
|
13
|
+
const ready = function() {
|
14
|
+
const productSearchResult = $("#product-search-result");
|
15
|
+
if (productSearchResult.length === 0) return;
|
16
|
+
|
17
|
+
const productResultTemplate = Handlebars.compile(productSearchResult.text());
|
18
|
+
const lineItemTemplate = Handlebars.compile($("#product-search-lineitem").text());
|
19
|
+
|
20
|
+
fillSectionsList(lineItemTemplate);
|
21
|
+
|
22
|
+
$(".product-autosearch").productAutoSearch(function(product) {
|
23
|
+
const masterImage = product.master.images[0];
|
24
|
+
if (masterImage !== undefined && masterImage.mini_url !== undefined) {
|
25
|
+
product.image = masterImage.mini_url;
|
26
|
+
}
|
27
|
+
return productResultTemplate({
|
28
|
+
product: product
|
29
|
+
});
|
30
|
+
}).on("change", function(e) {
|
31
|
+
addProductSection(e.added, lineItemTemplate);
|
32
|
+
});
|
33
|
+
|
34
|
+
$('#section-product-list').on("click", ".delete-resource", function(e) {
|
35
|
+
$(this).closest("tr").remove();
|
36
|
+
});
|
37
|
+
|
38
|
+
$('#section-product-list').sortable({handle: '.handle'});
|
39
|
+
};
|
40
|
+
|
41
|
+
$(document).ready(ready);
|
42
|
+
})(jQuery);
|