spree_banner 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,7 +9,7 @@ Basic Installation
9
9
 
10
10
  1. Add the following to your Gemfile
11
11
  <pre>
12
- gem 'spree_banner', :git => 'git://github.com/damianogiacomello/spree_banner'
12
+ gem 'spree_banner', '~> 1.0.3'
13
13
  </pre>
14
14
  2. Run `bundle install`
15
15
  3. To copy and apply migrations run:
@@ -41,6 +41,6 @@ set banner class (default banner)
41
41
  <pre>
42
42
  <%= insert_banner(:style => "your_container") %>
43
43
  </pre>
44
- set banner container (default list[ul/li])
44
+ set banner container (default list [possibile: div, p, ...])
45
45
 
46
46
  Copyright (c) 2012 [Damiano Giacomello], released under the New BSD License
@@ -3,10 +3,26 @@ module Spree
3
3
  class BannersController < ResourceController
4
4
  before_filter :load_data
5
5
 
6
+ def update_positions
7
+ params[:positions].each do |id, index|
8
+ Spree::Banner.update_all(['position=?', index], ['id=?', id])
9
+ end
10
+
11
+ respond_to do |format|
12
+ format.html { redirect_to admin_banners_url() }
13
+ format.js { render :text => 'Ok' }
14
+ end
15
+ end
6
16
 
7
17
  def load_data
8
18
  @banners = Spree::Banner.all
9
19
  end
20
+
21
+ private
22
+ def location_after_save
23
+ admin_banners_url(@banner)
24
+ end
25
+
10
26
  end
11
27
  end
12
28
  end
@@ -12,18 +12,49 @@ module Spree
12
12
  :convert_options => {
13
13
  :thumbnail => "-gravity center"
14
14
  }
15
+ after_post_process :find_dimensions
15
16
 
16
17
  validates_presence_of :category, :attachment_width, :attachment_height
17
18
  validates_attachment_presence :attachment
18
19
  validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'image/gif'], :message => "deve essere JPG, JPEG o PNG"
19
20
  #process_in_background :image UTILE MA OCCORRE ATTIVARE ANCHE LA GEMMA DELAYED-PAPERCLIP
20
21
  scope :enable, lambda { |category| {:conditions => {:enabled => true, :category => category}} }
21
-
22
+
23
+ # Load S3 settings
24
+ if (Rails.root.join('config', 's3.yml'))
25
+ S3_OPTIONS = {
26
+ :storage => 's3',
27
+ :s3_credentials => Rails.root.join('config', 's3.yml')
28
+ }
29
+ elsif (ENV['S3_KEY'] && ENV['S3_SECRET'] && ENV['S3_BUCKET'])
30
+ S3_OPTIONS = {
31
+ :storage => 's3',
32
+ :s3_credentials => {
33
+ :access_key_id => ENV['S3_KEY'],
34
+ :secret_access_key => ENV['S3_SECRET']
35
+ },
36
+ :bucket => ENV['S3_BUCKET']
37
+ }
38
+ else
39
+ S3_OPTIONS = { :storage => 'filesystem' }
40
+ end
41
+
42
+ attachment_definitions[:attachment] = (attachment_definitions[:attachment] || {}).merge(S3_OPTIONS)
43
+
22
44
  def initialize(*args)
23
45
  super(*args)
24
46
  last_banner = Banner.last
25
47
  self.position = last_banner ? last_banner.position + 1 : 0
26
48
  end
27
49
 
50
+ def find_dimensions
51
+ temporary = attachment.queued_for_write[:original]
52
+ filename = temporary.path unless temporary.nil?
53
+ filename = attachment.path if filename.blank?
54
+ geometry = Paperclip::Geometry.from_file(filename)
55
+ self.attachment_width = geometry.width
56
+ self.attachment_height = geometry.height
57
+ end
58
+
28
59
  end
29
60
  end
@@ -9,7 +9,7 @@
9
9
 
10
10
  <h1><%= t("banner.many") %></h1>
11
11
 
12
- <table class="index">
12
+ <table class="index sortable" data-hook data-sortable-link="<%= update_positions_admin_banners_url %>">
13
13
  <tr>
14
14
  <th><%= t("banner.category") %></th>
15
15
  <th><%= t("banner.position") %></th>
@@ -19,7 +19,10 @@
19
19
  <tbody>
20
20
  <% @banners.each do |banner| %>
21
21
  <tr class="<%= cycle('even', 'odd') %>" id="<%= dom_id banner %>">
22
- <td><%= banner.category %></td>
22
+ <td>
23
+ <span class="handle"></span>
24
+ <%= banner.category %>
25
+ </td>
23
26
  <td><%= banner.position %></td>
24
27
  <td><%= icon('tick') if banner.enabled %></td>
25
28
  <td>
data/config/routes.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  Spree::Core::Engine.routes.prepend do
2
2
  namespace :admin do
3
- resources :banners
3
+ resources :banners do
4
+ collection do
5
+ post :update_positions
6
+ end
7
+ end
4
8
  end
5
9
  end
@@ -1,6 +1,6 @@
1
1
  class CreateBanners < ActiveRecord::Migration
2
2
  def change
3
- create_table :spree_banners do |t|
3
+ create_table :banners do |t|
4
4
  t.string :title, :url
5
5
  t.string :category
6
6
  t.integer :position
@@ -0,0 +1,5 @@
1
+ class BannerNamespace < ActiveRecord::Migration
2
+ def change
3
+ rename_table :banners, :spree_banners
4
+ end
5
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_banner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Damiano Giacomello
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-22 00:00:00 Z
18
+ date: 2012-04-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spree_core
@@ -116,6 +116,7 @@ files:
116
116
  - app/views/spree/admin/banners/index.html.erb
117
117
  - app/views/spree/admin/banners/new.html.erb
118
118
  - db/migrate/20120116204313_create_banners.rb
119
+ - db/migrate/20120323174800_banner_namespace.rb
119
120
  - config/locales/en.yml
120
121
  - config/locales/it.yml
121
122
  - config/routes.rb
@@ -150,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  requirements:
151
152
  - none
152
153
  rubyforge_project:
153
- rubygems_version: 1.8.10
154
+ rubygems_version: 1.8.21
154
155
  signing_key:
155
156
  specification_version: 3
156
157
  summary: Extension to manage banner for you Spree Shop