spree_zaez_banner 3.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 +15 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Guardfile +90 -0
- data/LICENSE +26 -0
- data/README.md +66 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/app/banner_box_settings/banner_box_setting.js.coffee +65 -0
- data/app/assets/javascripts/spree/backend/app/banner_box_settings/banner_box_style.js.coffee +23 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_banner.js +1 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_banner.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_banner.css +6 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_banner.css +4 -0
- data/app/controllers/spree/admin/banner_box_settings_controller.rb +52 -0
- data/app/controllers/spree/admin/banner_boxes_controller.rb +54 -0
- data/app/helpers/spree/banner_boxes_helper.rb +39 -0
- data/app/models/spree/banner_box.rb +68 -0
- data/app/models/spree/banner_configuration.rb +10 -0
- data/app/overrides/spree/admin/shared/_main_menu/add_banner_tab_to_main_menu.html.erb.deface +6 -0
- data/app/views/spree/admin/banner_box_settings/edit.html.erb +104 -0
- data/app/views/spree/admin/banner_boxes/_form.html.erb +63 -0
- data/app/views/spree/admin/banner_boxes/edit.html.erb +10 -0
- data/app/views/spree/admin/banner_boxes/index.html.erb +80 -0
- data/app/views/spree/admin/banner_boxes/new.html.erb +17 -0
- data/app/views/spree/admin/shared/sub_menu/_banner.html.erb +4 -0
- data/app/views/spree/shared/_banner_box.html.erb +31 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +48 -0
- data/config/locales/pt-br.yml +48 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20120116204313_create_banners.rb +17 -0
- data/db/migrate/20120323174800_banner_namespace.rb +5 -0
- data/db/migrate/20131001104524_rename_presentation_to_alt_text.rb +5 -0
- data/db/migrate/20150721160059_add_display_period_to_spree_banner_boxes.rb +6 -0
- data/lib/generators/spree_zaez_banner/install/install_generator.rb +31 -0
- data/lib/spree_zaez_banner/engine.rb +24 -0
- data/lib/spree_zaez_banner/factories.rb +8 -0
- data/lib/spree_zaez_banner.rb +2 -0
- data/spec/features/admin/banner_box_settings_spec.rb +47 -0
- data/spec/features/admin/banner_boxes_spec.rb +126 -0
- data/spec/fixtures/spree.jpg +0 -0
- data/spec/models/spree/banner_box_spec.rb +58 -0
- data/spec/models/spree/banner_configuration_spec.rb +12 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/support/capybara_login.rb +13 -0
- data/spree_zaez_banner.gemspec +38 -0
- data/test +0 -0
- metadata +350 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a9ecc30e4202c324f68912db8a8fc865f32f8a5
|
4
|
+
data.tar.gz: e739f41db8115943dd850f91e5ccd702260d4f85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d857826b56d4e67146e826a60c809fe30487fa84f137b828720423eb7e52349287a0c553d6e31199c30d6173eadbf8c1daf96424747cc3a8f273aa450c0eef35
|
7
|
+
data.tar.gz: c15ad8f15882c652f58493de206eb1b60ea548a07e99b39ce35f230f3db98976cb8e359c3e6e7871b9adff92668863fe7a993158b5730178140a3c409fd783c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format documentation --color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), the you will want to move the Guardfile
|
18
|
+
## to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :shell do
|
36
|
+
watch(/^db\/migrate\/.*\.rb/) do |m|
|
37
|
+
puts "#{m[0]} Changed"
|
38
|
+
`bundle exec rake test_app`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
guard :bundler do
|
43
|
+
watch('Gemfile')
|
44
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
45
|
+
watch(/^.+\.gemspec/)
|
46
|
+
end
|
47
|
+
|
48
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
49
|
+
require "guard/rspec/dsl"
|
50
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
51
|
+
|
52
|
+
# Feel free to open issues for suggestions and improvements
|
53
|
+
|
54
|
+
# RSpec files
|
55
|
+
rspec = dsl.rspec
|
56
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
57
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
58
|
+
watch(rspec.spec_files)
|
59
|
+
|
60
|
+
# Ruby files
|
61
|
+
ruby = dsl.ruby
|
62
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
63
|
+
|
64
|
+
# Rails files
|
65
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
66
|
+
dsl.watch_spec_files_for(rails.app_files)
|
67
|
+
dsl.watch_spec_files_for(rails.views)
|
68
|
+
|
69
|
+
watch(rails.controllers) do |m|
|
70
|
+
[
|
71
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
72
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
73
|
+
rspec.spec.("acceptance/#{m[1]}")
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Rails config changes
|
78
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
79
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
80
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
81
|
+
|
82
|
+
# Capybara features specs
|
83
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
84
|
+
|
85
|
+
# Turnip features and steps
|
86
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
87
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
88
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
89
|
+
end
|
90
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2015 [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,66 @@
|
|
1
|
+
Spree Banner [![Build Status](https://travis-ci.org/zaeznet/spree_zaez_banner.svg?branch=master)](https://travis-ci.org/zaeznet/spree_zaez_banner)
|
2
|
+
============
|
3
|
+
|
4
|
+
Adds a way to manage banners to Spree Commerce.
|
5
|
+
|
6
|
+
|
7
|
+
Old versions of Spree
|
8
|
+
------------
|
9
|
+
|
10
|
+
For old version of Spree (before 3-0-stable), go to [old extension](https://github.com/zaeznet/spree_banner) (fork of [Damiano Giacomello](https://github.com/damianogiacomello/spree_banner)).
|
11
|
+
|
12
|
+
|
13
|
+
Installation
|
14
|
+
------------
|
15
|
+
|
16
|
+
1. Add the following to your Gemfile
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'spree_zaez_banner'
|
20
|
+
```
|
21
|
+
|
22
|
+
2. Run `bundle install`
|
23
|
+
|
24
|
+
3. To copy and apply migrations run:
|
25
|
+
|
26
|
+
```
|
27
|
+
rails g spree_banner:install
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
Configuration
|
32
|
+
-------------
|
33
|
+
|
34
|
+
Preferences can be updated within the admin panel "Banner box settings".
|
35
|
+
Or you may set them with an initializer within your application:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
SpreeBanner::Config.tap do |config|
|
39
|
+
config.banner_styles = {mini: "48x48>", small: "100x100>", large: "800x200#"}
|
40
|
+
config.banner_default_style = 'small'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
Banner use example
|
46
|
+
------------------
|
47
|
+
|
48
|
+
1. Add banner helper method in your view:
|
49
|
+
|
50
|
+
```erb
|
51
|
+
<%= insert_banner_box(category: "my_category") %>
|
52
|
+
```
|
53
|
+
|
54
|
+
2. Additional options:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
class: 'my_class'
|
58
|
+
style: 'my_style'
|
59
|
+
carousel_id: 'carousel'
|
60
|
+
buttons_carousel: true|false
|
61
|
+
buttons_class: 'my_buttons_class'
|
62
|
+
indicators_carousel: true|false
|
63
|
+
image_class: 'my_image_class'
|
64
|
+
```
|
65
|
+
|
66
|
+
Copyright (c) 2015 Zaez Inovação Digital, 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_zaez_banner'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
data/app/assets/javascripts/spree/backend/app/banner_box_settings/banner_box_setting.js.coffee
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#= require_self
|
2
|
+
#= require ./banner_box_style
|
3
|
+
|
4
|
+
class window.BannerBoxSetting
|
5
|
+
|
6
|
+
# Callback disparado após a execução
|
7
|
+
# do constructor de uma classe
|
8
|
+
afterConstructor: ->
|
9
|
+
|
10
|
+
# Callback disparado antes da execução
|
11
|
+
# do constructor de uma classe
|
12
|
+
beforeConstructor: ->
|
13
|
+
|
14
|
+
# Constructor da classe
|
15
|
+
constructor: (defaultExecution = true) ->
|
16
|
+
do @beforeConstructor
|
17
|
+
do @defaultExecution if defaultExecution
|
18
|
+
do @afterConstructor
|
19
|
+
|
20
|
+
# Execucao padrao da classe
|
21
|
+
defaultExecution: ->
|
22
|
+
do @setVariables
|
23
|
+
do @setEvents
|
24
|
+
|
25
|
+
# Exibe o formulario para insercao de um novo estilo
|
26
|
+
addNewStyle: (e) ->
|
27
|
+
e.preventDefault()
|
28
|
+
@add_new_style_button.attr('disabled', true)
|
29
|
+
object = {translations: {text: 'Text', value: 'Value'}}
|
30
|
+
rendered = @add_new_style_template {new_style: object}
|
31
|
+
@banner_styles_container.append(rendered)
|
32
|
+
$('.new_banner_style_form').click (e) => @addNewStyleToList(e)
|
33
|
+
|
34
|
+
# Adiciona um novo estilo de banner a lista de estilos
|
35
|
+
addNewStyleToList: (e) ->
|
36
|
+
e.preventDefault()
|
37
|
+
# validar
|
38
|
+
params =
|
39
|
+
text: $('#new_banner_styles_name').val()
|
40
|
+
value: $('#new_banner_styles_value').val()
|
41
|
+
banner_style = new BannerBoxStyle($.extend({}, params))
|
42
|
+
rendered = @banner_style_template {new_style: banner_style}
|
43
|
+
$('#banner_style_form').remove()
|
44
|
+
@banner_styles_container.append(rendered)
|
45
|
+
$("#preferences_banner_default_style").append("<option value='#{params.text}'>#{params.text}</option>")
|
46
|
+
@add_new_style_button.attr('disabled', false)
|
47
|
+
|
48
|
+
destroyStyle: (e) ->
|
49
|
+
e.preventDefault()
|
50
|
+
style = e.target.parentElement.dataset['value']
|
51
|
+
$("#banner_style_#{style}").remove()
|
52
|
+
$("#preferences_banner_default_style option[value='#{style}']").remove()
|
53
|
+
|
54
|
+
# Seta os eventos do formulario
|
55
|
+
setEvents: ->
|
56
|
+
@destroy_button.click (e) => @destroyStyle(e)
|
57
|
+
@add_new_style_button.on 'click', $.proxy(@addNewStyle, @)
|
58
|
+
|
59
|
+
# Seta as variaveis utilizadas
|
60
|
+
setVariables: ->
|
61
|
+
@destroy_button = $ '.destroy_banner_style'
|
62
|
+
@add_new_style_button = $ '.add_new_banner_style'
|
63
|
+
@banner_styles_container = $ '#banner_styles'
|
64
|
+
@add_new_style_template = Handlebars.compile $('#new_banner_style_template').html()
|
65
|
+
@banner_style_template = Handlebars.compile $('#banner_style_template').html()
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Modelo base para os estilos de banners
|
2
|
+
class window.BannerBoxStyle
|
3
|
+
|
4
|
+
# Callback disparado após a execução
|
5
|
+
# do constructor de uma classe
|
6
|
+
afterConstructor: (style) ->
|
7
|
+
|
8
|
+
# Callback disparado antes da execução
|
9
|
+
# do constructor de uma classe
|
10
|
+
beforeConstructor: (style) ->
|
11
|
+
|
12
|
+
# Constructor da classe
|
13
|
+
constructor: (@style) ->
|
14
|
+
@beforeConstructor @style
|
15
|
+
@setAttributes @style
|
16
|
+
@afterConstructor @style
|
17
|
+
|
18
|
+
# Seta os attributos do estilo passado
|
19
|
+
# no construtor
|
20
|
+
# @param style Object
|
21
|
+
setAttributes: (@style) ->
|
22
|
+
@text = @style.text
|
23
|
+
@value = @style.value
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./app/banner_box_settings/banner_box_setting
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class BannerBoxSettingsController < Spree::Admin::BaseController
|
4
|
+
|
5
|
+
def show
|
6
|
+
redirect_to( :action => :edit )
|
7
|
+
end
|
8
|
+
|
9
|
+
# def create
|
10
|
+
# update_paperclip_settings
|
11
|
+
# # @styles = Spree::BannerConfig[:banner_styles]
|
12
|
+
# @config = Spree::BannerConfig.new
|
13
|
+
# super
|
14
|
+
# end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@config = Spree::BannerConfiguration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
Spree::BannerConfig.set(params[:preferences])
|
22
|
+
|
23
|
+
update_banner_style
|
24
|
+
update_paperclip_settings
|
25
|
+
|
26
|
+
respond_to do |format|
|
27
|
+
format.html {
|
28
|
+
flash[:notice] = Spree.t(:banner_settings_updated)
|
29
|
+
redirect_to edit_admin_banner_box_settings_path
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def update_banner_style
|
37
|
+
collection = {}
|
38
|
+
params[:banner_styles].each do |key, value|
|
39
|
+
collection[key.to_sym] = value
|
40
|
+
end
|
41
|
+
Spree::BannerConfig.banner_styles = collection
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_paperclip_settings
|
45
|
+
Spree::BannerBox.attachment_definitions[:attachment][:styles] = Spree::BannerConfig[:banner_styles].symbolize_keys!
|
46
|
+
Spree::BannerBox.attachment_definitions[:attachment][:path] = Spree::BannerConfig[:banner_path]
|
47
|
+
Spree::BannerBox.attachment_definitions[:attachment][:default_url] = Spree::BannerConfig[:banner_default_url]
|
48
|
+
Spree::BannerBox.attachment_definitions[:attachment][:default_style] = Spree::BannerConfig[:banner_default_style].to_sym
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class BannerBoxesController < ResourceController
|
4
|
+
|
5
|
+
def index
|
6
|
+
respond_with(@collection)
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
redirect_to( :action => :edit )
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
@banner_box.enhance_settings
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def clone
|
19
|
+
@new = @banner_box.duplicate
|
20
|
+
|
21
|
+
if @new.save
|
22
|
+
flash.notice = I18n.t('notice_messages.banner_box_cloned')
|
23
|
+
else
|
24
|
+
flash.notice = I18n.t('notice_messages.banner_box_not_cloned')
|
25
|
+
end
|
26
|
+
|
27
|
+
respond_with(@new) { |format| format.html { redirect_to edit_admin_banner_box_url(@new) } }
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def find_resource
|
32
|
+
Spree::BannerBox.find(params[:id])
|
33
|
+
end
|
34
|
+
|
35
|
+
def location_after_save
|
36
|
+
admin_banner_boxes_url
|
37
|
+
end
|
38
|
+
|
39
|
+
def collection
|
40
|
+
return @collection if @collection.present?
|
41
|
+
params[:q] ||= {}
|
42
|
+
|
43
|
+
params[:q][:s] ||= 'category, position asc'
|
44
|
+
@collection = super
|
45
|
+
|
46
|
+
@q = @collection.ransack(params[:q])
|
47
|
+
@collection = @q.result.
|
48
|
+
page(params[:page]).
|
49
|
+
per(params[:per_page] || Spree::Config[:admin_products_per_page])
|
50
|
+
@collection
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|