banner_module 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,23 @@
1
+ CHANGELOG
2
+ MIT-LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ app/controllers/banners_controller.rb
7
+ app/helpers/banners_helper.rb
8
+ app/models/banner.rb
9
+ app/views/banners/_banner.erb
10
+ app/views/banners/crop.html.erb
11
+ app/views/banners/edit.html.erb
12
+ app/views/banners/index.html.erb
13
+ app/views/banners/new.html.erb
14
+ app/views/banners/show.html.erb
15
+ app/views/banners/showp.pdf.prawn
16
+ banner_module.gemspec
17
+ config/routes.rb
18
+ generators/banner_module/banner_module_generator.rb
19
+ generators/banner_module/templates/create_banner_module.rb
20
+ init.rb
21
+ install.rb
22
+ lib/banner_module.rb
23
+ uninstall.rb
data/README ADDED
@@ -0,0 +1,45 @@
1
+ Background
2
+ ==========
3
+
4
+ Create a helpers/controller/views to control e show ramdom banners.
5
+
6
+ Dependencies:
7
+ =============
8
+ paperclip
9
+ acl9
10
+
11
+
12
+ Install
13
+ =======
14
+ Run:
15
+
16
+ gem sources -a http://gemcutter.org
17
+ gem install banner_module
18
+
19
+ put in your environment.rb :
20
+ config.gem "banner_module"
21
+ config.reload_plugins = true
22
+
23
+
24
+ Run:
25
+ //create the migration of background tables
26
+ script/generate banner_module migration
27
+ rake db:migrate
28
+
29
+
30
+ Use the gem
31
+ ===========
32
+
33
+
34
+ IMPORTANT
35
+ =========
36
+ This gem is to be use with acl9
37
+ The menu is able just for user with :moderator role
38
+
39
+ The menu will use the layout "adm" and "adm-clean"
40
+
41
+
42
+ =========
43
+
44
+
45
+ Copyright (c) 2010 Eduardo Cauli, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('banner_module', '0.1.0') do |p|
6
+ p.description = "Ramdom banners"
7
+ p.url = "http://github.com/ecauli/banner_module"
8
+ p.author = "Eduardo Cauli"
9
+ p.email = "ecauli@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,101 @@
1
+ class BannersController < ApplicationController
2
+ # GET /banners
3
+ # GET /banners.xml
4
+
5
+ layout :select_layout
6
+
7
+ access_control do
8
+ allow :moderator, :to => [:index, :show,:create, :new, :destroy, :update, :edit, :crop]
9
+ end
10
+ def index
11
+ @banners = Banner.paginate :page => params[:page], :per_page=>20
12
+
13
+ respond_to do |format|
14
+ format.html # index.html.erb
15
+ format.xml { render :xml => @banners }
16
+ end
17
+ end
18
+
19
+ # GET /banners/1
20
+ # GET /banners/1.xml
21
+ def show
22
+ @banner = Banner.find(params[:id])
23
+
24
+ respond_to do |format|
25
+ format.html # show.html.erb
26
+ format.xml { render :xml => @banner }
27
+ end
28
+ end
29
+
30
+ # GET /banners/new
31
+ # GET /banners/new.xml
32
+ def new
33
+ @banner = Banner.new
34
+
35
+ respond_to do |format|
36
+ format.html # new.html.erb
37
+ format.xml { render :xml => @banner }
38
+ end
39
+ end
40
+
41
+ # GET /banners/1/edit
42
+ def edit
43
+ @banner = Banner.find(params[:id])
44
+ end
45
+
46
+ # POST /banners
47
+ # POST /banners.xml
48
+ def create
49
+ @banner = Banner.new(params[:banner])
50
+
51
+ respond_to do |format|
52
+ if @banner.save
53
+ flash[:notice] = 'Banner adicionado com sucesso.'
54
+ format.html { redirect_to(banners_url)}
55
+ format.xml { render :xml => @banner, :status => :created, :location => @banner }
56
+ else
57
+ format.html { render :action => "new" }
58
+ format.xml { render :xml => @banner.errors, :status => :unprocessable_entity }
59
+ end
60
+ end
61
+ end
62
+
63
+ # PUT /banners/1
64
+ # PUT /banners/1.xml
65
+ def update
66
+ @banner = Banner.find(params[:id])
67
+
68
+ respond_to do |format|
69
+ if @banner.update_attributes(params[:banner])
70
+ flash[:notice] = 'Banner adicionado com sucesso.'
71
+ format.html { redirect_to(banners_url)}
72
+ format.xml { head :ok }
73
+ else
74
+ format.html { render :action => "edit" }
75
+ format.xml { render :xml => @banner.errors, :status => :unprocessable_entity }
76
+ end
77
+ end
78
+ end
79
+
80
+ # DELETE /banners/1
81
+ # DELETE /banners/1.xml
82
+ def destroy
83
+ @banner = Banner.find(params[:id])
84
+ @banner.destroy
85
+
86
+ respond_to do |format|
87
+ format.html { redirect_to(banners_url) }
88
+ format.xml { head :ok }
89
+ end
90
+ end
91
+
92
+ def crop
93
+ @banner = Banner.find(params[:id])
94
+ end
95
+
96
+ private
97
+
98
+ def select_layout
99
+ [ 'crop' ].include?(action_name) ? "adm-clean" : "adm"
100
+ end
101
+ end
@@ -0,0 +1,2 @@
1
+ module BannersHelper
2
+ end
@@ -0,0 +1,37 @@
1
+ class Banner < ActiveRecord::Base
2
+ has_attached_file :arquivo,
3
+ :styles => {
4
+ :show=> "200x200>",
5
+ :thumb=> "100x100#",
6
+ :leaderboard => "728x90#",
7
+ :fullbanner => "468x60#",
8
+ :halfbanner => "234x60#",
9
+ :rectangle => "180x150#",
10
+ :squarebutton => "125x125#",
11
+ :skyscraper => "120x600#",
12
+ :wideskyscraper => "160x600#",
13
+ :largerectangle => "120x600#",
14
+ :mediumrectangle => "160x600#",
15
+ :big => "725x220#",
16
+ :normal => "580x176#",
17
+ :large => "700x700>"
18
+ }, :processors => [:cropper]
19
+ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
20
+ validates_attachment_presence :arquivo
21
+ validates_attachment_size :arquivo, :less_than => 5.megabytes
22
+ validates_attachment_content_type :arquivo, :content_type =>['image/jpeg', 'image/png','image/pjpeg', 'image/x-png']
23
+ after_update :reprocess_arquivo, :if => :cropping?
24
+ def cropping?
25
+ !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
26
+ end
27
+
28
+ def arquivo_geometry(style = :original)
29
+ @geometry ||= {}
30
+ @geometry[style] ||= Paperclip::Geometry.from_file(arquivo.path(style))
31
+ end
32
+
33
+ private
34
+ def reprocess_arquivo
35
+ arquivo.reprocess!
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ <% form_for banner, :html => { :multipart => true } do |f| %>
2
+ <%= f.error_messages %>
3
+
4
+ <p>
5
+ <%= f.label :titulo %><br />
6
+ <%= f.text_field :titulo %>
7
+ </p>
8
+ <p>
9
+ <%= f.label :link %><br />
10
+ <%= f.text_field :link %>
11
+ </p>
12
+ <p>
13
+ <%= f.label :click %><br />
14
+ <%= f.text_field :click %>
15
+ </p>
16
+ <p>
17
+ <%= f.label :arquivo, "Arquivo" %>
18
+ <%= f.file_field :arquivo %>
19
+ </p>
20
+ <p>
21
+ <%= f.label "Banner 1" %><br />
22
+ <%= f.check_box :topo %>
23
+ </p>
24
+ <p>
25
+ <%= f.label "Banner 2" %><br />
26
+ <%= f.check_box :conteudo %>
27
+ </p>
28
+ <p>
29
+ <%= f.submit 'Enviar' %>
30
+ </p>
31
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <% title "Edição de Banner" %>
2
+ <% content_for (:head) do %>
3
+ <%= javascript_include_tag 'jquery' %>
4
+ <%= stylesheet_link_tag "jquery.Jcrop" %>
5
+ <%= javascript_include_tag "jquery.Jcrop.min" %>
6
+ <script type="text/javascript">
7
+ jQuery.noConflict();
8
+ jQuery(document).ready(function() {
9
+ jQuery('#cropbox').Jcrop({
10
+ onChange: update_crop,
11
+ onSelect: update_crop,
12
+ aspectRatio: 3.3
13
+ });
14
+ });
15
+ function update_crop(coords) {
16
+ var ratio = <%= @banner.arquivo_geometry(:original).width %> / <%= @banner.arquivo_geometry(:large).width %>;
17
+ jQuery('#crop_x').val(Math.floor(coords.x * ratio));
18
+ jQuery('#crop_y').val(Math.floor(coords.y * ratio));
19
+ jQuery('#crop_w').val(Math.floor(coords.w * ratio));
20
+ jQuery('#crop_h').val(Math.floor(coords.h * ratio));
21
+ }
22
+ </script>
23
+ <% end %>
24
+ <div style="margin:0 auto"><%= image_tag @banner.arquivo.url(:large), :id => "cropbox" %> </div>
25
+
26
+
27
+ <% form_for @banner do |form| %>
28
+ <% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
29
+ <%= form.hidden_field attribute, :id => attribute %>
30
+ <% end %>
31
+ <p><%= form.submit "Ajustar" %></p>
32
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h1>Editar Banner</h1>
2
+
3
+ <%= render :partial => @banner %>
4
+
5
+ <%= link_to 'Voltar', banners_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Lista de banners</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Titulo</th>
6
+ <th>Topo</th>
7
+ <th>Conteudo</th>
8
+ <th>Click</th>
9
+ </tr>
10
+
11
+ <% @banners.each do |banner| %>
12
+ <tr>
13
+ <td><%=h banner.titulo %></td>
14
+ <td><%=h simnao(banner.topo) %></td>
15
+ <td><%=h simnao(banner.conteudo) %></td>
16
+ <td><%=h banner.click %></td>
17
+ <td><%= link_to 'Detalhes', banner %></td>
18
+ <td><%= link_to 'Editar', edit_banner_path(banner) %></td>
19
+ <td><%= link_to 'Deletar', banner, :confirm => 'tem certeza?', :method => :delete %></td>
20
+ <td><%= link_to 'Recortar', "/banners/crop/" + banner.id.to_s %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+ <%= will_paginate @banners %>
25
+ <br />
26
+
27
+ <%= link_to 'Novo Banner', new_banner_path %>
@@ -0,0 +1,5 @@
1
+ <h1>Novo Banner</h1>
2
+
3
+ <%= render :partial => @banner %>
4
+
5
+ <%= link_to 'Voltar', banners_path %>
@@ -0,0 +1,21 @@
1
+ <p>
2
+ <b>Titulo:</b>
3
+ <%=h @banner.titulo %>
4
+ </p>
5
+ <p>
6
+ <b>Link:</b>
7
+ <%=h @banner.link %>
8
+ </p>
9
+ <p>
10
+ <b>Click:</b>
11
+ <%=h @banner.click %>
12
+ </p>
13
+ </p>
14
+ <p>
15
+ <b>Figura:</b>
16
+ <%= image_tag @banner.arquivo.url(:show) %>
17
+ </p>
18
+
19
+
20
+ <%= link_to 'Editar', edit_banner_path(@banner) %> |
21
+ <%= link_to 'Voltar', banners_path %>
@@ -0,0 +1 @@
1
+ pdf.text "teste"
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{banner_module}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Eduardo Cauli"]
9
+ s.date = %q{2010-04-27}
10
+ s.description = %q{Ramdom banners}
11
+ s.email = %q{ecauli@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README", "lib/banner_module.rb"]
13
+ s.files = ["CHANGELOG", "MIT-LICENSE", "Manifest", "README", "Rakefile", "app/controllers/banners_controller.rb", "app/helpers/banners_helper.rb", "app/models/banner.rb", "app/views/banners/_banner.erb", "app/views/banners/crop.html.erb", "app/views/banners/edit.html.erb", "app/views/banners/index.html.erb", "app/views/banners/new.html.erb", "app/views/banners/show.html.erb", "app/views/banners/showp.pdf.prawn", "banner_module.gemspec", "config/routes.rb", "generators/banner_module/banner_module_generator.rb", "generators/banner_module/templates/create_banner_module.rb", "init.rb", "install.rb", "lib/banner_module.rb", "uninstall.rb"]
14
+ s.homepage = %q{http://github.com/ecauli/banner_module}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Banner_module", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{banner_module}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Ramdom banners}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.resources :banners
3
+ end
@@ -0,0 +1,19 @@
1
+ class BackgroundGenerator < Rails::Generator::NamedBase
2
+ def migration
3
+ record do |m|
4
+ unless options[:skip_migration]
5
+ m.migration_template('create_banner_module.rb', 'db/migrate', :migration_file_name => 'create_banner_module')
6
+ end
7
+ end
8
+ end
9
+
10
+ protected
11
+
12
+ def add_options!(opt)
13
+ opt.separator ''
14
+ opt.separator 'Options:'
15
+ opt.on("--skip-migration", "Don't generate a migration for the banner table") do |value|
16
+ options[:skip_migration] = value
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ class CreateBanners < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :banners do |t|
4
+ t.string :titulo
5
+ t.integer :click, :default => 0
6
+ t.string :arquivo_file_name
7
+ t.string :arquivo_content_type
8
+ t.integer :arquivo_file_size
9
+ t.datetime :arquivo_updated_at
10
+ t.string :link
11
+ t.boolean :topo, :default=> false
12
+ t.boolean :conteudo, :default=> false
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+
18
+ def self.down
19
+ drop_table :banners
20
+ end
21
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "banner_module")
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,10 @@
1
+ # Background
2
+ module BannerModule
3
+
4
+
5
+ end
6
+
7
+
8
+ #require File.join(File.dirname(__FILE__), "lib", "background")
9
+
10
+ #ActionView::Base.send :include, FundoHelper
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banner_module
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Eduardo Cauli
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-27 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ramdom banners
22
+ email: ecauli@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG
29
+ - README
30
+ - lib/banner_module.rb
31
+ files:
32
+ - CHANGELOG
33
+ - MIT-LICENSE
34
+ - Manifest
35
+ - README
36
+ - Rakefile
37
+ - app/controllers/banners_controller.rb
38
+ - app/helpers/banners_helper.rb
39
+ - app/models/banner.rb
40
+ - app/views/banners/_banner.erb
41
+ - app/views/banners/crop.html.erb
42
+ - app/views/banners/edit.html.erb
43
+ - app/views/banners/index.html.erb
44
+ - app/views/banners/new.html.erb
45
+ - app/views/banners/show.html.erb
46
+ - app/views/banners/showp.pdf.prawn
47
+ - banner_module.gemspec
48
+ - config/routes.rb
49
+ - generators/banner_module/banner_module_generator.rb
50
+ - generators/banner_module/templates/create_banner_module.rb
51
+ - init.rb
52
+ - install.rb
53
+ - lib/banner_module.rb
54
+ - uninstall.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/ecauli/banner_module
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --title
64
+ - Banner_module
65
+ - --main
66
+ - README
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 1
82
+ - 2
83
+ version: "1.2"
84
+ requirements: []
85
+
86
+ rubyforge_project: banner_module
87
+ rubygems_version: 1.3.6
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Ramdom banners
91
+ test_files: []
92
+