Skip to content

Commit

Permalink
finished upgrade for spree 1.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
damdiginess committed Mar 14, 2012
1 parent 2419002 commit 411b075
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 35 deletions.
10 changes: 9 additions & 1 deletion README.md
@@ -1,4 +1,4 @@
SpreeMultiSlideshow
SpreeBanner
===================

Add banner for Spree Commerce Shop
Expand Down Expand Up @@ -34,5 +34,13 @@ displays banner for which the category column, dafault is ""
<%= insert_banner(:max => 10) %>
</pre>
limits the number of banner shown to 10 (default 1)
<pre>
<%= insert_banner(:class => "your_class") %>
</pre>
set banner class (default banner)
<pre>
<%= insert_banner(:style => "your_container") %>
</pre>
set banner container (default list[ul/li])

Copyright (c) 2012 [Damiano Giacomello], released under the New BSD License
9 changes: 7 additions & 2 deletions app/controllers/spree/admin/banners_controller.rb
@@ -1,7 +1,12 @@
module Spree
module Admin
class BannersController < BaseController

class BannersController < ResourceController
before_filter :load_data


def load_data
@banners = Spree::Banner.all
end
end
end
end
15 changes: 13 additions & 2 deletions app/helpers/spree/banners_helper.rb
Expand Up @@ -2,13 +2,24 @@ module Spree
module BannersHelper

def insert_banner(params={})
# max items show for list
max = params[:max] || 1
# category items show
category = params[:category] || ""
# class items show
cl = params[:class] || "banner"
# style items show
style = params[:style] || "list"
banner = Banner.enable(category).limit(max)
if !banner.blank?
banner = banner.sort_by { |ban| ban.position }

content_tag(:div, content_tag(:ul, raw(banner.map do |ban| content_tag(:li, link_to(image_tag(ban.attachment.url(:custom)), ban.url) ) end.join) ), :class => "banner")

if (style == "list")
content_tag(:ul, raw(banner.map do |ban| content_tag(:li, link_to(image_tag(ban.attachment.url(:custom)), ban.url), :class => cl) end.join) )
else
raw(banner.map do |ban| content_tag(style.to_sym, link_to(image_tag(ban.attachment.url(:custom)), ban.url), :class => cl) end.join)
end

end
end

Expand Down
3 changes: 1 addition & 2 deletions app/models/spree/banner.rb
Expand Up @@ -10,8 +10,7 @@ class Banner < ActiveRecord::Base
:custom => Proc.new { |instance| "#{instance.attachment_width}x#{instance.attachment_height}#" }
},
:convert_options => {
:thumbnail => "-gravity center",
:custom => "-gravity center"
:thumbnail => "-gravity center"
}

#process_in_background :image UTILE MA OCCORRE ATTIVARE ANCHE LA GEMMA DELAYED-PAPERCLIP
Expand Down
7 changes: 4 additions & 3 deletions app/overrides/banner_admin_tab.rb
@@ -1,4 +1,5 @@
Deface::Override.new(:virtual_path => "layouts/admin",
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "banner_admin_tab",
:insert_bottom => "[data-hook='admin_tabs']",
:text => "<%= tab(:banners) %>")
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:banners, :url => spree.admin_banners_path) %>",
:disabled => false)
9 changes: 3 additions & 6 deletions app/views/spree/admin/banners/edit.html.erb
@@ -1,10 +1,7 @@
<h1><%= t("banner.editing_page") %></h1>
<%= render "shared/error_messages", :target => @banner %>
<h1><%= t(:editing_banner) %></h1>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @banner } %>
<%= semantic_form_for([:admin, @banner]) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p class="form-buttons">
<%= button t("actions.create"), nil, 'submit' %>
<%= t("or") %> <%= link_to t("actions.cancel"), admin_banners_path %>
</p>
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>
22 changes: 12 additions & 10 deletions app/views/spree/admin/banners/index.html.erb
@@ -1,24 +1,26 @@
<div class='toolbar'>
<ul class='actions'>
<li id="new_product_link">
<%= button_link_to t("banner.new_page"), new_admin_banner_url, {:icon => 'add'} %>
</li>
</ul>
<br class='clear' />
<ul class='actions'>
<li>
<%= button_link_to t(:new_banner), spree.new_admin_banner_path, :icon => 'add' %>
</li>
</ul>
<br class="clear" />
</div>

<h1><%= t("banner.many") %></h1>
<h1><%= t(:banner) %></h1>

<table class="index">
<tr>
<th><%= t("banner.category") %></th>
<th><%= t("banner.enable") %></th>
<th><%= t("action") %></th>
<th><%= t(:category) %></th>
<th><%= t(:position) %></th>
<th><%= t(:enable) %></th>
<th><%= t(:action) %></th>
</tr>
<tbody>
<% @banners.each do |banner| %>
<tr class="<%= cycle('even', 'odd') %>" id="<%= dom_id banner %>">
<td><%= banner.category %></td>
<td><%= banner.position %></td>
<td><%= icon('tick') if banner.enabled %></td>
<td>
<%= link_to_edit banner %> &nbsp;
Expand Down
9 changes: 3 additions & 6 deletions app/views/spree/admin/banners/new.html.erb
@@ -1,10 +1,7 @@
<h1><%= t("banner.new_page") %></h1>
<%= render "shared/error_messages", :target => @banner %>
<h1><%= t(:new_banner) %></h1>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @banner } %>
<%= semantic_form_for([:admin, @banner], :html => { :enctype => "multipart/form-data" }) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p class="form-buttons">
<%= button t("actions.create"), nil, 'submit' %>
<%= t("or") %> <%= link_to t("actions.cancel"), admin_banners_path %>
</p>
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
<% end %>
4 changes: 1 addition & 3 deletions config/routes.rb
@@ -1,7 +1,5 @@
Rails.application.routes.draw do

Spree::Core::Engine.routes.prepend do
namespace :admin do
resources :banners
end

end

0 comments on commit 411b075

Please sign in to comment.