solidus_slider 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +26 -0
  6. data/LICENSE +26 -0
  7. data/README.md +61 -0
  8. data/README.textile +71 -0
  9. data/Rakefile +21 -0
  10. data/Versionfile +5 -0
  11. data/app/assets/javascripts/spree/backend/slide_location_picker.js +53 -0
  12. data/app/assets/javascripts/spree/backend/solidus_slider.js +1 -0
  13. data/app/controllers/spree/admin/slide_locations_controller.rb +19 -0
  14. data/app/controllers/spree/admin/slides_controller.rb +57 -0
  15. data/app/models/spree/product_decorator.rb +8 -0
  16. data/app/models/spree/slide.rb +49 -0
  17. data/app/models/spree/slide_location.rb +8 -0
  18. data/app/models/spree/slide_slide_location.rb +8 -0
  19. data/app/overrides/spree/admin/configurations/index/add_slides_to_admin_configurations_menu.html.erb.deface +11 -0
  20. data/app/overrides/spree/admin/shared/_configuration_menu/add_slide_locations_to_admin_configurations_sidebar_menu.html.erb.deface +3 -0
  21. data/app/overrides/spree/admin/shared/_configuration_menu/add_slides_to_admin_configurations_sidebar_menu.html.erb.deface +3 -0
  22. data/app/overrides/spree/home/index/add_slider.html.erb.deface +5 -0
  23. data/app/overrides/spree/shared/_header/add_slider.html.erb.deface +3 -0
  24. data/app/views/spree/admin/slide_locations/_form.html.erb +10 -0
  25. data/app/views/spree/admin/slide_locations/edit.html.erb +18 -0
  26. data/app/views/spree/admin/slide_locations/index.html.erb +40 -0
  27. data/app/views/spree/admin/slide_locations/new.html.erb +16 -0
  28. data/app/views/spree/admin/slide_locations/search.json.jbuilder +4 -0
  29. data/app/views/spree/admin/slides/_form.html.erb +70 -0
  30. data/app/views/spree/admin/slides/edit.html.erb +23 -0
  31. data/app/views/spree/admin/slides/index.html.erb +50 -0
  32. data/app/views/spree/admin/slides/new.html.erb +18 -0
  33. data/app/views/spree/admin/slides/show.html.erb +54 -0
  34. data/app/views/spree/shared/_slider.html.erb +19 -0
  35. data/bin/rails +7 -0
  36. data/config/locales/de.yml +27 -0
  37. data/config/locales/en.yml +28 -0
  38. data/config/locales/es-MX.yml +33 -0
  39. data/config/locales/es.yml +27 -0
  40. data/config/locales/nl-NL.yml +27 -0
  41. data/config/locales/nl.yml +27 -0
  42. data/config/locales/pl.yml +29 -0
  43. data/config/locales/pt-BR.yml +36 -0
  44. data/config/locales/ru.yml +27 -0
  45. data/config/routes.rb +15 -0
  46. data/db/migrate/20120222184238_create_slides.rb +16 -0
  47. data/db/migrate/20120816192758_add_position_to_slides.rb +5 -0
  48. data/db/migrate/20121219124126_add_product_id_to_slides.rb +5 -0
  49. data/db/migrate/20150611113500_create_slider_location.rb +8 -0
  50. data/db/migrate/20160214061128_add_show_caption_to_slides.rb +5 -0
  51. data/db/migrate/20180113010348_create_spree_slide_slide_locations_table.rb +10 -0
  52. data/lib/generators/solidus_slider/install/install_generator.rb +24 -0
  53. data/lib/generators/solidus_slider/install_anything_generator.rb +31 -0
  54. data/lib/generators/solidus_slider/install_nivo_generator.rb +34 -0
  55. data/lib/generators/solidus_slider/install_simple_carousel_generator.rb +30 -0
  56. data/lib/generators/solidus_slider/templates/anything_slider.html.erb +23 -0
  57. data/lib/generators/solidus_slider/templates/nivo_slider.html.erb +37 -0
  58. data/lib/generators/solidus_slider/templates/simple_carousel_slider.html.erb +15 -0
  59. data/lib/solidus_slider.rb +4 -0
  60. data/lib/solidus_slider/engine.rb +22 -0
  61. data/lib/solidus_slider/version.rb +3 -0
  62. data/solidus_slider.gemspec +55 -0
  63. data/spec/spec_helper.rb +21 -0
  64. metadata +550 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a29e78813609835968e64926fdd5b8b18ff1b9da3401164ee993099102b6b388
4
+ data.tar.gz: da93d1d4cd78f32fb289deb661f06c127b08ab50c04e7a6464be1d4681c68f4a
5
+ SHA512:
6
+ metadata.gz: 3b0495003b00da2b21981ac49f8494f4d8564645b2d4fe384325abf822b5d13119182781cf267e1e82192d94375f20de97adc1069cb0d93712f71903e2ca42d2
7
+ data.tar.gz: 88c3c7bbbb747cddaaad8529ae9ed4cf53681caa12fd7c2b60edfda8fe789872546ee4e4c31c2b01d3ebd41f4fde1b52009b7e280b9db5371b7bb0f724842474
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
10
+ spec/dummy
11
+ pkg/*
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ source 'https://rubygems.org'
2
+
3
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
5
+ gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: branch
6
+ gem 'globalize', github: 'globalize/globalize', branch: branch
7
+
8
+ if branch == 'master' || branch >= 'v2.3'
9
+ gem 'rails', '~> 5.1.0'
10
+ elsif branch >= 'v2.0'
11
+ gem 'rails', '~> 5.0.0'
12
+ gem 'rails-controller-testing', group: :test
13
+ else
14
+ gem 'rails', '~> 4.2.0'
15
+ gem 'rails_test_params_backport', group: :test
16
+ end
17
+
18
+ gem 'pg'
19
+ gem 'sqlite3'
20
+ gem 'mysql2'
21
+
22
+ group :development, :test do
23
+ gem 'i18n-tasks', '~> 0.9' if branch == 'master'
24
+ end
25
+
26
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2012 R.S.A.
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,61 @@
1
+ # SolidusSlider
2
+
3
+ Add a slider to the homepage of your Spree-Solidus site, and manage the slide show from within the Admin panel.
4
+
5
+ ## Installation
6
+
7
+ To install, add solidus_slider to your @Gemfile@ and run `bundle install`:
8
+
9
+ ```
10
+ gem 'solidus_slider', github: 'samanmohamadi/solidus_slider'
11
+ ```
12
+
13
+ Then install and run the migrations to add the tables:
14
+ ```
15
+ bundle exec rails g solidus_slider:install
16
+
17
+ ```
18
+
19
+ ### Using the slider
20
+
21
+ Spree 3 uses the bootstrap framework and a default slider template is available for bootstrap 3
22
+ `spree/shared/_slider.html.erb`.
23
+
24
+ Example usage:
25
+
26
+ ```erb
27
+ <%= render partial: 'spree/shared/slider', locals: { slider: Spree::Slide.published, cid: 'home' } %>
28
+ ```
29
+
30
+ If you desire to have a customized carousel template you can specify your own like so:
31
+
32
+ ```erb
33
+ <% if Spree::Slide.published.count > 0 %>
34
+ <section id="slideshow">
35
+ <ul class="slide">
36
+ <% Spree::Slide.published.order('position ASC').each do |s| %>
37
+ <li>
38
+ <h1><%= s.slide_caption %></h1>
39
+ <%= link_to image_tag(s.slide_image.url), url_for(s.link_url) %>
40
+ </li>
41
+ <% end %>
42
+ </ul>
43
+ <a title="<%= t(:previous) %>" class="slider-prev"><%= t(:previous)%></a>
44
+ <a title="<%= t(:next) %>" class="slider-next"><%= t(:next) %></a>
45
+ </section>
46
+ <% end %>
47
+ ```
48
+
49
+ ## Dynamic content management
50
+
51
+ To add dynamic content, go to the spree admin section, under 'Configuration'
52
+ and find the Solidus Slider & Solidus Slider Locations menu.
53
+
54
+ You can create new slides and new locations. Then to fetch & render the slider for a particular location you can do the following:
55
+
56
+ ```erb
57
+ <% slides = Spree::Slide.published.location("home") %>
58
+ <%= render partial: 'spree/shared/slider', locals: { slider: slides } %>
59
+ ```
60
+
61
+ Copyright (c) 2012 [R.S.A.](http://www.rsaweb.com) released under the New BSD License
data/README.textile ADDED
@@ -0,0 +1,71 @@
1
+ h1. SoldiusSlider
2
+
3
+ Add a slider to the homepage of your Spree site, and manage the slideshow from within the Admin panel.
4
+
5
+ h2. Installation
6
+
7
+ To install, add solidus_slider to your @Gemfile@ and run `bundle install`:
8
+
9
+ ```ruby
10
+ gem 'solidus_slider', github: 'jtapia/solidus_slider'
11
+ ```
12
+
13
+ Then install and run the migrations to add the tables:
14
+ ```ruby
15
+ bundle exec rake railties:install:migrations
16
+ bundle exec rake db:migrate
17
+ ```
18
+
19
+ This extension comes with three sliders plugins: Nivo, SimpleCarousel and Anything slider
20
+ Depending on which plugin you want to install, run the following command:
21
+
22
+ h3. Anything slider
23
+
24
+ ```ruby
25
+ rails generate solidus_slider:install_anything
26
+ ```
27
+
28
+ h3. SimpleCarousel slider
29
+
30
+ ```ruby
31
+ rails generate solidus_slider:install_simple_carousel
32
+ ```
33
+
34
+ h3. Nivo slider
35
+
36
+ ```ruby
37
+ rails generate solidus_slider:install_nivo
38
+ ```
39
+
40
+ The slider is almost unstyled. To customize you have to add your own css and
41
+ eventually modify the partial copied into your app folder:
42
+ app/views/spree/shared/_slider.html.erb
43
+
44
+ h3. Or Roll your own!
45
+
46
+ You may want to theme your site your own way. If you want to include your own library such Bootstrap or Foundation.
47
+ Just add your own to your asset pipeline, and update your theme templates with appropriate markup. Example:
48
+
49
+ ```ruby
50
+ <% if Spree::Slide.published.count > 0 %>
51
+ <section id="slideshow">
52
+ <ul class="slide">
53
+ <% Spree::Slide.published.order('position ASC').each do |s| %>
54
+ <li>
55
+ <h1><%= s.slide_name %></h1>
56
+ <%= link_to image_tag(s.slide_image.url), url_for(s.slide_link) %>
57
+ </li>
58
+ <% end %>
59
+ </ul>
60
+ <a title="<%= Spree.t(:previous) %>" class="slider-prev"><%= Spree.t(:previous)%></a>
61
+ <a title="<%= Spree.t(:next) %>" class="slider-next"><%= Spree.t(:next) %></a>
62
+ </section>
63
+ <% end %>
64
+ ```
65
+
66
+ h2. Dynamic content management
67
+
68
+ To add dynamic content, go to the spree admin section, under 'Configuration'
69
+ and find the Spree Slider menu.
70
+
71
+ Copyright (c) 2012 "R.S.A.":http://www.rsaweb.com 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'] = 'solidus_slider'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
data/Versionfile ADDED
@@ -0,0 +1,5 @@
1
+ "1.0.x" => { :ref => "2c31ead09bf6a62e7a0700a5d831c7933d63edd5" }
2
+ "1.1.x" => { :ref => "4f2c9e74e47e26b4f1fe67a59288d2cd45ccd13b" }
3
+ "1.2.x" => { :ref => "4f2c9e74e47e26b4f1fe67a59288d2cd45ccd13b" }
4
+ "2.0.x" => { :ref => "4d77dec367c1e8320fe0151aa0100814163c8217" }
5
+ "3.0.x" => { :branch => "master" }
@@ -0,0 +1,53 @@
1
+ Spree.routes.admin_slide_locations_search = Spree.pathFor('admin/slide_locations/search');
2
+
3
+ $.fn.slideLocationAutocomplete = function (options) {
4
+ 'use strict';
5
+
6
+ // Default options
7
+ options = options || {}
8
+ var multiple = typeof(options['multiple']) !== 'undefined' ? options['multiple'] : true
9
+
10
+ function formatSlideLocation(slide_location) {
11
+ return Select2.util.escapeMarkup(slide_location.name);
12
+ }
13
+
14
+ this.select2({
15
+ minimumInputLength: 3,
16
+ multiple: multiple,
17
+ initSelection: function (element, callback) {
18
+ $.get(Spree.routes.admin_slide_locations_search, {
19
+ ids: element.val().split(','),
20
+ token: Spree.api_key
21
+ }, function (data) {
22
+ callback(multiple ? data.slide_locations : data.slide_locations[0]);
23
+ });
24
+ },
25
+ ajax: {
26
+ url: Spree.routes.admin_slide_locations_search,
27
+ datatype: 'json',
28
+ params: { "headers": { "X-Spree-Token": Spree.api_key } },
29
+ data: function (term, page) {
30
+ return {
31
+ q: {
32
+ name_cont: term
33
+ },
34
+ token: Spree.api_key,
35
+ page: page
36
+ };
37
+ },
38
+ results: function (data, page) {
39
+ var slide_locations = data.slide_locations ? data.slide_locations : [];
40
+
41
+ return {
42
+ results: slide_locations
43
+ };
44
+ }
45
+ },
46
+ formatResult: formatSlideLocation,
47
+ formatSelection: formatSlideLocation
48
+ });
49
+ };
50
+
51
+ Spree.ready(function () {
52
+ $('.slide_location_picker').slideLocationAutocomplete();
53
+ });
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Admin
3
+ class SlideLocationsController < ResourceController
4
+ respond_to :html, :json, :js
5
+
6
+ def index
7
+ @slide_locations = Spree::SlideLocation.order(:name)
8
+ end
9
+
10
+ def search
11
+ if params[:ids]
12
+ @slide_locations = Spree::SlideLocation.where(id: params[:ids])
13
+ else
14
+ @slide_locations = Spree::SlideLocation.ransack(params[:q]).result
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ module Spree
2
+ module Admin
3
+ class SlidesController < ResourceController
4
+ respond_to :html
5
+
6
+ def index
7
+ @slides = Spree::Slide.order(:position).page(params[:page]).per(params[:per_page])
8
+ end
9
+
10
+ def update
11
+ invoke_callbacks(:update, :before)
12
+ if @object.update_attributes(permitted_resource_params)
13
+ invoke_callbacks(:update, :after)
14
+ handle_slide_locations(@object)
15
+ respond_with(@object) do |format|
16
+ format.html do
17
+ flash[:success] = flash_message_for(@object, :successfully_updated)
18
+ redirect_to location_after_save
19
+ end
20
+ format.js { render layout: false }
21
+ end
22
+ else
23
+ invoke_callbacks(:update, :fails)
24
+ respond_with(@object) do |format|
25
+ format.html do
26
+ flash.now[:error] = @object.errors.full_messages.join(", ")
27
+ render_after_update_error
28
+ end
29
+ format.js { render layout: false }
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def location_after_save
37
+ if @slide.created_at == @slide.updated_at
38
+ edit_admin_slide_url(@slide)
39
+ else
40
+ admin_slides_url
41
+ end
42
+ end
43
+
44
+ def permitted_resource_params
45
+ params.require(:slide).permit(:name, :body, :link_url, :published, :image, :position, :product_id, :slide_location_ids)
46
+ end
47
+
48
+ def handle_slide_locations(object)
49
+ slide_location_ids = permitted_resource_params[:slide_location_ids].split(',')
50
+
51
+ slide_location_ids.each do |slide_location_id|
52
+ object.slide_slide_locations.find_or_create_by(slide_id: object.id, slide_location_id: slide_location_id)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,8 @@
1
+ Spree::Product.class_eval do
2
+ has_one :slide, :dependent => :destroy
3
+ after_update :destroy_slide_if_deleted
4
+
5
+ def destroy_slide_if_deleted
6
+ slide.update_attributes(published: false) if slide && deleted_at
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+ module Spree
2
+ class Slide < ActiveRecord::Base
3
+ belongs_to :product, touch: true
4
+
5
+ self.table_name = 'spree_slides'
6
+
7
+ has_many :slide_slide_locations
8
+ has_many :slide_locations, through: :slide_slide_locations
9
+
10
+ has_attached_file :image,
11
+ url: '/spree/slides/:id/:style/:basename.:extension',
12
+ path: ':rails_root/public/spree/slides/:id/:style/:basename.:extension',
13
+ convert_options: { all: '-strip -auto-orient -colorspace sRGB' }
14
+
15
+ validates_attachment :image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
16
+
17
+ scope :published, -> { where(published: true).order('position ASC') }
18
+ scope :location, -> (location){ joins(:slide_locations).where('spree_slide_locations.name = ?', location) }
19
+
20
+ def initialize(attrs = nil)
21
+ attrs ||= { published: true }
22
+ super
23
+ end
24
+
25
+ def show_caption?
26
+ show_caption
27
+ end
28
+
29
+ def slide_caption
30
+ name.blank? && product.present? ? product.name : name
31
+ end
32
+
33
+ def slide_name
34
+ name.blank? && product.present? ? product.name : name
35
+ end
36
+
37
+ def slide_link
38
+ link_url.blank? && product.present? ? product : link_url
39
+ end
40
+
41
+ def slide_image
42
+ !image.file? && product.present? && product.images.any? ? product.images.first.attachment : image
43
+ end
44
+
45
+ def slide_location_ids
46
+ slide_locations.pluck(:id)
47
+ end
48
+ end
49
+ end