spree_banner 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/app/assets/javascripts/admin/banner_settings.js +31 -0
- data/app/assets/javascripts/admin/spree_banner.js +1 -1
- data/app/assets/stylesheets/store/spree_banner.css +0 -4
- data/app/controllers/spree/admin/banner_settings_controller.rb +49 -0
- data/app/controllers/spree/admin/banners_controller.rb +5 -7
- data/app/models/spree/app_configuration_decorator.rb +8 -0
- data/app/models/spree/banner.rb +20 -14
- data/app/overrides/banner_admin_tab.rb +6 -1
- data/app/views/spree/admin/banner_settings/edit.html.erb +48 -0
- data/app/views/spree/admin/banner_settings/show.html.erb +10 -0
- data/app/views/spree/admin/banners/_form.html.erb +3 -3
- data/app/views/spree/admin/banners/new.html.erb +2 -10
- data/app/views/spree/admin/shared/_banner_setting_configurations_menu.html.erb +4 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20120116204313_create_banners.rb +1 -1
- data/lib/generators/spree_banner/install/install_generator.rb +4 -1
- metadata +10 -20
data/README.md
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
$('.destroy_banner_style').on("click", function() {
|
4
|
+
$(this).parent().remove();
|
5
|
+
});
|
6
|
+
|
7
|
+
// Handle adding new styles
|
8
|
+
var styles_hash_index = 1;
|
9
|
+
$('.add_banner_style').click(function() {
|
10
|
+
$('#styles_list').append(generate_html_for_hash("new_banner_styles", styles_hash_index));
|
11
|
+
});
|
12
|
+
|
13
|
+
// Generates html for new paperclip styles form fields
|
14
|
+
generate_html_for_hash = function(hash_name, index) {
|
15
|
+
var html = '<li>';
|
16
|
+
html += '<label for="' + hash_name + '_' + index + '_name">';
|
17
|
+
html += 'Name</label>';
|
18
|
+
html += '<input id="' + hash_name + '_' + index + '_name" name="' + hash_name + '[' + index + '][name]" type="text">';
|
19
|
+
html += '<label for="' + hash_name + '_' + index + '_value">';
|
20
|
+
html += 'Value</label>';
|
21
|
+
html += '<input id="' + hash_name + '_' + index + '_value" name="' + hash_name + '[' + index + '][value]" type="text">';
|
22
|
+
html += '<a href="#" alt="Destroy" class="destroy_banner_style"> x</a>';
|
23
|
+
html += '</li>';
|
24
|
+
|
25
|
+
index += 1;
|
26
|
+
return html;
|
27
|
+
};
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
});
|
@@ -1 +1 @@
|
|
1
|
-
//= require admin/
|
1
|
+
//= require admin/banner_settings
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class BannerSettingsController < Spree::Admin::BaseController
|
4
|
+
def show
|
5
|
+
styles = ActiveSupport::JSON.decode(Spree::Config[:banner_styles])
|
6
|
+
@styles_list = styles.collect { |k, v| k }.join(", ")
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
@styles = ActiveSupport::JSON.decode(Spree::Config[:banner_styles])
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
update_styles(params)
|
15
|
+
|
16
|
+
Spree::Config.set(params[:preferences])
|
17
|
+
update_paperclip_settings
|
18
|
+
|
19
|
+
respond_to do |format|
|
20
|
+
format.html {
|
21
|
+
flash[:notice] = t(:banner_settings_updated)
|
22
|
+
redirect_to admin_banner_settings_path
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def update_styles(params)
|
31
|
+
params[:new_banner_styles].each do |index, style|
|
32
|
+
params[:banner_styles][style[:name]] = style[:value] unless style[:value].empty?
|
33
|
+
end if params[:new_banner_styles].present?
|
34
|
+
|
35
|
+
styles = params[:banner_styles]
|
36
|
+
|
37
|
+
Spree::Config[:banner_styles] = ActiveSupport::JSON.encode(styles) unless styles.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_paperclip_settings
|
41
|
+
Spree::Banner.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:banner_styles])
|
42
|
+
Spree::Banner.attachment_definitions[:attachment][:path] = Spree::Config[:banner_path]
|
43
|
+
Spree::Banner.attachment_definitions[:attachment][:default_url] = Spree::Config[:banner_default_url]
|
44
|
+
Spree::Banner.attachment_definitions[:attachment][:default_style] = Spree::Config[:banner_default_style]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -1,23 +1,21 @@
|
|
1
1
|
module Spree
|
2
2
|
module Admin
|
3
3
|
class BannersController < ResourceController
|
4
|
-
|
4
|
+
|
5
|
+
def show
|
6
|
+
redirect_to(:action => :edit)
|
7
|
+
end
|
5
8
|
|
6
9
|
def update_positions
|
7
10
|
params[:positions].each do |id, index|
|
8
|
-
Spree::Banner.update_all(
|
11
|
+
Spree::Banner.where(:id => id).update_all(:position => index)
|
9
12
|
end
|
10
13
|
|
11
14
|
respond_to do |format|
|
12
|
-
format.html { redirect_to admin_banners_url() }
|
13
15
|
format.js { render :text => 'Ok' }
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
def load_data
|
18
|
-
@banners = Spree::Banner.all
|
19
|
-
end
|
20
|
-
|
21
19
|
private
|
22
20
|
def location_after_save
|
23
21
|
edit_admin_banner_url(@banner)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Spree::AppConfiguration.class_eval do
|
2
|
+
# Preferences related to banner settings
|
3
|
+
preference :banner_default_url, :string, :default => '/spree/banners/:id/:style/:basename.:extension'
|
4
|
+
preference :banner_path, :string, :default => ':rails_root/public/spree/banners/:id/:style/:basename.:extension'
|
5
|
+
preference :banner_url, :string, :default => '/spree/banners/:id/:style/:basename.:extension'
|
6
|
+
preference :banner_styles, :string, :default => "{\"mini\":\"80x80#\",\"small\":\"120x120#\"}"
|
7
|
+
preference :banner_default_style, :string, :default => 'small'
|
8
|
+
end
|
data/app/models/spree/banner.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
module Spree
|
2
2
|
class Banner < ActiveRecord::Base
|
3
|
-
attr_accessible :title, :url, :category, :position, :enabled, :attachment
|
3
|
+
attr_accessible :title, :url, :category, :position, :enabled, :attachment
|
4
4
|
|
5
5
|
has_attached_file :attachment,
|
6
|
-
:url => "/spree/
|
7
|
-
:path => ":rails_root/public/spree/
|
6
|
+
:url => "/spree/banners/:id/:style_:basename.:extension",
|
7
|
+
:path => ":rails_root/public/spree/banners/:id/:style_:basename.:extension",
|
8
8
|
:styles => lambda {|a| {
|
9
|
-
:
|
9
|
+
:mini => "80x80#",
|
10
|
+
:small => "120x120#",
|
10
11
|
:custom => "#{a.instance.attachment_width}x#{a.instance.attachment_height}#"
|
11
12
|
}},
|
12
13
|
:convert_options => {
|
13
|
-
:
|
14
|
+
:mini => "-gravity center",
|
15
|
+
:small => "-gravity center",
|
14
16
|
:custom => "-gravity center"
|
15
17
|
}
|
16
18
|
|
17
19
|
after_post_process :find_dimensions
|
18
20
|
|
19
|
-
validates_presence_of :category
|
21
|
+
validates_presence_of :category
|
20
22
|
validates_attachment_presence :attachment
|
21
23
|
validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/x-png', 'image/pjpeg'], :message => "deve essere JPG, JPEG, PNG o GIF"
|
22
24
|
|
@@ -31,6 +33,12 @@ module Spree
|
|
31
33
|
Spree::Banner.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket]
|
32
34
|
Spree::Banner.attachment_definitions[:attachment][:s3_protocol] = Spree::Config[:s3_protocol] unless Spree::Config[:s3_protocol].blank?
|
33
35
|
end
|
36
|
+
|
37
|
+
Spree::Banner.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:banner_styles])
|
38
|
+
Spree::Banner.attachment_definitions[:attachment][:path] = Spree::Config[:banner_path]
|
39
|
+
Spree::Banner.attachment_definitions[:attachment][:url] = Spree::Config[:banner_url]
|
40
|
+
Spree::Banner.attachment_definitions[:attachment][:default_url] = Spree::Config[:banner_default_url]
|
41
|
+
Spree::Banner.attachment_definitions[:attachment][:default_style] = Spree::Config[:banner_default_style]
|
34
42
|
|
35
43
|
def initialize(*args)
|
36
44
|
super(*args)
|
@@ -39,14 +47,12 @@ module Spree
|
|
39
47
|
end
|
40
48
|
|
41
49
|
def find_dimensions
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
self.attachment_height = geometry.height
|
49
|
-
end
|
50
|
+
temporary = attachment.queued_for_write[:original]
|
51
|
+
filename = temporary.path unless temporary.nil?
|
52
|
+
filename = attachment.path if filename.blank?
|
53
|
+
geometry = Paperclip::Geometry.from_file(filename)
|
54
|
+
self.attachment_width = geometry.width
|
55
|
+
self.attachment_height = geometry.height
|
50
56
|
end
|
51
57
|
|
52
58
|
end
|
@@ -2,4 +2,9 @@ Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
|
2
2
|
:name => "banner_admin_tab",
|
3
3
|
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
4
4
|
:text => "<%= tab(:banners, :url => spree.admin_banners_path) %>",
|
5
|
-
:disabled => false)
|
5
|
+
:disabled => false)
|
6
|
+
|
7
|
+
Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
|
8
|
+
:name => "add_banner_setting_to_configuration_menu",
|
9
|
+
:insert_bottom => "[data-hook='admin_configurations_menu']",
|
10
|
+
:partial => "spree/admin/shared/banner_setting_configurations_menu")
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t(:banner_settings) %></h1>
|
4
|
+
|
5
|
+
<p><span class="warning"><%= t(:banner_settings_warning) %></span></p>
|
6
|
+
|
7
|
+
<%= form_tag admin_banner_settings_path, :method => :put do %>
|
8
|
+
|
9
|
+
<p data-hook="banner_path">
|
10
|
+
<label>
|
11
|
+
<%= label_tag 'preferences[banner_path]', t(:banner_path) %>
|
12
|
+
<%= preference_field_tag 'preferences[banner_path]', Spree::Config[:banner_path], :type => :string %>
|
13
|
+
</label>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p data-hook="banner_default_url">
|
17
|
+
<label>
|
18
|
+
<%= label_tag 'preferences[banner_default_url]', t(:banner_default_url) %>
|
19
|
+
<%= preference_field_tag 'preferences[banner_default_url]', Spree::Config[:banner_default_url], :type => :string %>
|
20
|
+
</label>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p data-hook="banner_default_style">
|
24
|
+
<label>
|
25
|
+
<%= label_tag 'preferences[banner_default_style]', t(:banner_default_style) %>
|
26
|
+
<%= collection_select 'preferences', 'banner_default_style', @styles, :first, :first, {:selected => Spree::Config[:banner_default_style] } %>
|
27
|
+
</label>
|
28
|
+
</p>
|
29
|
+
|
30
|
+
<div id="banner_styles" data-hook="banner_styles">
|
31
|
+
<h2><%= t(:banner_styles) %></h2>
|
32
|
+
<ul id="styles_list">
|
33
|
+
<% @styles.each do |style_name, style_value| %>
|
34
|
+
<li>
|
35
|
+
<%= label_tag "banner_styles[#{style_name}]", style_name %>
|
36
|
+
<%= text_field_tag "banner_styles[#{style_name}]", style_value %>
|
37
|
+
<a href="#" alt="Destroy" class="destroy_banner_style">x</a>
|
38
|
+
</li>
|
39
|
+
<% end %>
|
40
|
+
</ul>
|
41
|
+
<p><a href="#" alt="Add Style" class="add_banner_style"><%= t(:add_new_style) %></a></p>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<p class="form-buttons" data-hook="buttons">
|
45
|
+
<%= button t(:update) %>
|
46
|
+
</p>
|
47
|
+
|
48
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t(:banner_settings) %></h1>
|
4
|
+
|
5
|
+
<h4><%= t(:banner_path) %>: <%= Spree::Config[:banner_path] %></h4>
|
6
|
+
<h4><%= t(:banner_default_url) %>: <%= Spree::Config[:banner_default_url] %></h4>
|
7
|
+
<h4><%= t(:banner_default_style) %>: <%= Spree::Config[:banner_default_style] %></h4>
|
8
|
+
<h4><%= t(:defined_paperclip_styles) %>: <%= @styles_list %></h4>
|
9
|
+
|
10
|
+
<%= link_to_with_icon 'edit', t(:edit), edit_admin_banner_settings_path, :id => 'admin_banner_settings_link' %>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<div data-hook="
|
1
|
+
<div data-hook="admin_banner_form_fields">
|
2
2
|
<div class="clearfix">
|
3
|
-
<div class="left" data-hook="
|
3
|
+
<div class="left" data-hook="admin_banner_form_left">
|
4
4
|
<%= f.field_container :category do %>
|
5
5
|
<%= f.label :category, t(:category) %> <span class="required">*</span><br />
|
6
6
|
<%= f.text_field :category, :class => 'fullwidth title' %>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<%= f.error_message_on :attachment %>
|
20
20
|
<% end %>
|
21
21
|
</div>
|
22
|
-
<div class="right" data-hook="
|
22
|
+
<div class="right" data-hook="admin_banner_form_right">
|
23
23
|
<%= f.field_container :attachment_width do %>
|
24
24
|
<%= f.label :attachment_width, t(:attachment_width) %> <span class="required">*</span><br />
|
25
25
|
<%= f.text_field :attachment_width, :class => 'fullwidth title' %>
|
@@ -1,16 +1,8 @@
|
|
1
|
-
<h1><%= t("banner.new_banner") %></h1>
|
2
|
-
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @banner } %>
|
3
|
-
|
4
|
-
<%= semantic_form_for([:admin, @banner], :html => { :enctype => "multipart/form-data" }) do |f| %>
|
5
|
-
<%= render :partial => "form", :locals => { :f => f } %>
|
6
|
-
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
|
7
|
-
<% end %>
|
8
|
-
|
9
1
|
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @banner } %>
|
10
2
|
|
11
3
|
<%= form_for [:admin, @banner], :html => { :multipart => true } do |f| %>
|
12
|
-
<fieldset data-hook="
|
13
|
-
<div class="clearfix" data-hook="
|
4
|
+
<fieldset data-hook="new_banner">
|
5
|
+
<div class="clearfix" data-hook="new_banner_attrs">
|
14
6
|
<div class="left">
|
15
7
|
<%= f.field_container :category do %>
|
16
8
|
<%= f.label :category, t(:category) %> <span class="required">*</span><br />
|
data/config/routes.rb
CHANGED
@@ -8,7 +8,7 @@ class CreateBanners < ActiveRecord::Migration
|
|
8
8
|
|
9
9
|
t.string :attachment_content_type, :attachment_file_name
|
10
10
|
t.datetime :attachment_updated_at
|
11
|
-
t.integer :attachment_width, :attachment_height
|
11
|
+
t.integer :attachment_width, :attachment_height
|
12
12
|
t.integer :attachment_size
|
13
13
|
|
14
14
|
t.timestamps
|
@@ -2,8 +2,11 @@ module SpreeBanner
|
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
|
5
|
+
def add_javascripts
|
6
|
+
append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_banner\n"
|
7
|
+
end
|
8
|
+
|
5
9
|
def add_stylesheets
|
6
|
-
inject_into_file "app/assets/stylesheets/admin/all.css", " *= require admin/spree_banner\n", :before => /\*\//, :verbose => true
|
7
10
|
inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/spree_banner\n", :before => /\*\//, :verbose => true
|
8
11
|
end
|
9
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_banner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.1.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.1.3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: paperclip
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rspec-rails
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
62
|
description:
|
79
63
|
email: damiano.giacomello@diginess.it
|
80
64
|
executables: []
|
@@ -86,19 +70,25 @@ files:
|
|
86
70
|
- lib/generators/spree_banner/install/install_generator.rb
|
87
71
|
- lib/spree_banner/engine.rb
|
88
72
|
- lib/spree_banner.rb
|
73
|
+
- app/assets/javascripts/admin/banner_settings.js
|
89
74
|
- app/assets/javascripts/admin/spree_banner.js
|
90
75
|
- app/assets/javascripts/store/spree_banner.js
|
91
76
|
- app/assets/stylesheets/admin/spree_banner.css
|
92
77
|
- app/assets/stylesheets/store/spree_banner.css
|
78
|
+
- app/controllers/spree/admin/banner_settings_controller.rb
|
93
79
|
- app/controllers/spree/admin/banners_controller.rb
|
94
80
|
- app/helpers/spree/banners_helper.rb
|
81
|
+
- app/models/spree/app_configuration_decorator.rb
|
95
82
|
- app/models/spree/banner.rb
|
96
83
|
- app/overrides/banner_admin_tab.rb
|
84
|
+
- app/views/spree/admin/banner_settings/edit.html.erb
|
85
|
+
- app/views/spree/admin/banner_settings/show.html.erb
|
97
86
|
- app/views/spree/admin/banners/_form.html.erb
|
98
87
|
- app/views/spree/admin/banners/edit.html.erb
|
99
88
|
- app/views/spree/admin/banners/index.html.erb
|
100
89
|
- app/views/spree/admin/banners/new.html.erb
|
101
90
|
- app/views/spree/admin/banners/new.js.erb
|
91
|
+
- app/views/spree/admin/shared/_banner_setting_configurations_menu.html.erb
|
102
92
|
- db/migrate/20120116204313_create_banners.rb
|
103
93
|
- db/migrate/20120323174800_banner_namespace.rb
|
104
94
|
- config/locales/en.yml
|