papermill 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/app/controllers/papermill_controller.rb +22 -17
- data/app/views/papermill/_form.html.erb +11 -14
- data/config/locales/papermill.yml +2 -0
- data/generators/papermill_table/templates/migrate/papermill_migration.rb.erb +9 -6
- data/lib/papermill.rb +1 -1
- data/lib/papermill/papermill_asset.rb +19 -5
- data/lib/papermill/papermill_options.rb +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Asset management made easy. Now in pre-1.0.0 release!
|
4
4
|
|
5
|
+
== IE6 Problems
|
6
|
+
|
7
|
+
I can't make it work with IE6, there seems to be a jQuery problem. SWFUpload and jQuery should both work fine with it, but anyway, it dies with strange errors that I don't understand. Any help appreciated...
|
8
|
+
|
5
9
|
== Install the gems
|
6
10
|
|
7
11
|
$ gem source -a http://gemcutter.org
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.16.
|
1
|
+
0.16.1
|
@@ -3,8 +3,10 @@ class PapermillController < ApplicationController
|
|
3
3
|
# Yet SwfUpload doesn't send the right header for request.xhr? to be true and thus fails to disable verify_authenticity_token automatically.
|
4
4
|
skip_before_filter :verify_authenticity_token, :only => [:create]
|
5
5
|
|
6
|
+
prepend_before_filter :load_asset, :only => ["show", "destroy", "update", "edit"]
|
7
|
+
prepend_before_filter :load_assets, :only => ["sort", "mass_delete", "mass_edit"]
|
8
|
+
|
6
9
|
def show
|
7
|
-
@asset = PapermillAsset.find_by_id_partition params
|
8
10
|
if @asset.create_thumb_file(params[:style])
|
9
11
|
redirect_to @asset.url(params[:style])
|
10
12
|
else
|
@@ -13,7 +15,6 @@ class PapermillController < ApplicationController
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def destroy
|
16
|
-
@asset = PapermillAsset.find params[:id]
|
17
18
|
render :update do |page|
|
18
19
|
if @asset.destroy
|
19
20
|
page << "jQuery('#papermill_asset_#{params[:id]}').remove()"
|
@@ -25,7 +26,6 @@ class PapermillController < ApplicationController
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def update
|
28
|
-
@asset = PapermillAsset.find params[:id]
|
29
29
|
render :update do |page|
|
30
30
|
if @asset.update_attributes(params[:papermill_asset])
|
31
31
|
page << %{ notify("#{ escape_javascript t("papermill.updated", :ressource => @asset.name)}", "notice") }
|
@@ -36,7 +36,6 @@ class PapermillController < ApplicationController
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def edit
|
39
|
-
@asset = PapermillAsset.find params[:id]
|
40
39
|
render :action => "edit", :layout => (params[:layout] || "none")
|
41
40
|
end
|
42
41
|
|
@@ -50,34 +49,40 @@ class PapermillController < ApplicationController
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def sort
|
53
|
-
|
54
|
-
|
52
|
+
@assets.each_with_index do |asset, index|
|
53
|
+
asset.update_attribute(:position, index + 1)
|
55
54
|
end
|
56
55
|
render :nothing => true
|
57
56
|
end
|
58
57
|
|
59
58
|
def mass_delete
|
60
59
|
render :update do |page|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
page << "jQuery('#papermill_asset_#{id}').remove()"
|
60
|
+
@assets.each do |asset|
|
61
|
+
if asset.destroy
|
62
|
+
page << "jQuery('#papermill_asset_#{asset.id}').remove()"
|
65
63
|
else
|
66
|
-
page << %{ notify('#{ escape_javascript t("papermill.not-deleted", :ressource =>
|
64
|
+
page << %{ notify('#{ escape_javascript t("papermill.not-deleted", :ressource => asset.name)}', 'error') }
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
70
|
def mass_edit
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@asset.update_attribute(params[:attribute], params[:value])
|
77
|
-
message << t("papermill.updated", :ressource => @asset.name)
|
71
|
+
@assets.each do |asset|
|
72
|
+
asset.update_attribute(params[:attribute], params[:value])
|
73
|
+
(message ||= []) << t("papermill.updated", :ressource => asset.name)
|
78
74
|
end
|
79
75
|
render :update do |page|
|
80
|
-
page << %{ notify('#{ escape_javascript message.join("<br />")}', "notice") }
|
76
|
+
page << %{ notify('#{ escape_javascript message.join("<br />")}', "notice") } if defined?(message)
|
81
77
|
end
|
82
78
|
end
|
79
|
+
|
80
|
+
private
|
81
|
+
def load_asset
|
82
|
+
@asset = PapermillAsset.find(params[:id] || (params[:id0] + params[:id1] + params[:id2]).to_i)
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_assets
|
86
|
+
@assets = (params[:papermill_asset] || []).map{ |id| PapermillAsset.find(id) }
|
87
|
+
end
|
83
88
|
end
|
@@ -1,19 +1,16 @@
|
|
1
|
-
<form onsubmit="jQuery.ajax({data:jQuery.param(jQuery(this).serializeArray()), dataType:'script', type:'post', url:'/papermill/<%= @asset.id %>'});
|
1
|
+
<form onsubmit="jQuery.ajax({data:jQuery.param(jQuery(this).serializeArray()), dataType:'script', type:'post', url:'/papermill/<%= @asset.id %>'}); close_popup(self); return false;" method="post" action="/papermill/<%= @asset.id %>">
|
2
2
|
<input type="hidden" value="put" name="_method"/>
|
3
|
-
|
4
3
|
<% fields_for :papermill_asset, @asset do |form| %>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<%= form.text_area :description %>
|
16
|
-
</p>
|
4
|
+
<% PapermillAsset.columns.map{|c| [c.name, c.type] }.reject{ |c| ["slug", "file_file_name", "file_content_type", "file_file_size", "position", "assetable_id", "assetable_type", "assetable_key", "type", "id", "created_at", "updated_at"].include?(c.first) }.each do |c| %>
|
5
|
+
<p>
|
6
|
+
<%= form.label c.first, t("papermill.#{c.first}") %><br />
|
7
|
+
<% if c.last == :text %>
|
8
|
+
<%= form.text_area c.first %>
|
9
|
+
<% else %>
|
10
|
+
<%= form.text_field c.first %>
|
11
|
+
<% end -%>
|
12
|
+
</p>
|
13
|
+
<% end %>
|
17
14
|
<%= submit_tag t('papermill.save') %>
|
18
15
|
<% end %>
|
19
16
|
</form>
|
@@ -21,6 +21,7 @@ en:
|
|
21
21
|
updated_at: "Updated at"
|
22
22
|
title: "Title"
|
23
23
|
copyright: "Copyright"
|
24
|
+
alt: "Alternative text"
|
24
25
|
description: "Description"
|
25
26
|
width: "Width"
|
26
27
|
height: "Height"
|
@@ -53,6 +54,7 @@ fr:
|
|
53
54
|
updated_at: "Mise à jour"
|
54
55
|
title: "Titre"
|
55
56
|
copyright: "Copyright"
|
57
|
+
alt: "Texte alternatif"
|
56
58
|
description: "Description"
|
57
59
|
width: "Largeur"
|
58
60
|
height: "Hauteur"
|
@@ -1,23 +1,26 @@
|
|
1
1
|
class <%= migration_name %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :papermill_assets do |t|
|
4
|
-
|
4
|
+
|
5
|
+
# Paperclip fields (required)
|
5
6
|
t.string :file_file_name
|
6
7
|
t.string :file_content_type
|
7
8
|
t.integer :file_file_size
|
9
|
+
|
10
|
+
# Papermill fields (required)
|
8
11
|
t.integer :position
|
9
12
|
t.integer :assetable_id
|
10
13
|
t.string :assetable_type
|
11
14
|
t.string :assetable_key
|
12
15
|
t.string :type
|
13
|
-
t.string :title
|
14
|
-
|
15
16
|
|
16
|
-
#
|
17
|
-
t.
|
18
|
-
t.string :copyright
|
17
|
+
# Custom fields (optionnals)
|
18
|
+
t.string :title
|
19
19
|
t.string :alt
|
20
|
+
t.string :copyright
|
21
|
+
t.text :description
|
20
22
|
t.timestamps
|
23
|
+
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
data/lib/papermill.rb
CHANGED
@@ -9,7 +9,7 @@ Formtastic::SemanticFormBuilder.send(:include, PapermillFormtasticExtensions) re
|
|
9
9
|
begin
|
10
10
|
require File.join(File.dirname(RAILS_ROOT), "config/initializers/papermill.rb")
|
11
11
|
rescue LoadError
|
12
|
-
require 'papermill/papermill_options'
|
12
|
+
require 'papermill/papermill_options.rb'
|
13
13
|
end
|
14
14
|
|
15
15
|
require 'paperclip' unless defined?(Paperclip)
|
@@ -3,10 +3,15 @@ class PapermillAsset < ActiveRecord::Base
|
|
3
3
|
before_destroy :destroy_files
|
4
4
|
before_create :set_position
|
5
5
|
|
6
|
+
attr_protected :position, :file_file_name
|
7
|
+
|
8
|
+
|
6
9
|
has_attached_file :file,
|
7
10
|
:path => "#{Papermill::options[:public_root]}/#{Papermill::options[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}",
|
8
11
|
:url => "/#{Papermill::options[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}"
|
9
12
|
|
13
|
+
before_post_process :set_real_file_name
|
14
|
+
|
10
15
|
Paperclip.interpolates :escaped_basename do |attachment, style|
|
11
16
|
Paperclip::Interpolations[:basename].call(attachment, style).to_url
|
12
17
|
end
|
@@ -22,7 +27,7 @@ class PapermillAsset < ActiveRecord::Base
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def Filename=(name)
|
25
|
-
|
30
|
+
@real_file_name = name
|
26
31
|
end
|
27
32
|
|
28
33
|
def create_thumb_file(style_name)
|
@@ -34,14 +39,18 @@ class PapermillAsset < ActiveRecord::Base
|
|
34
39
|
("%09d" % self.id).scan(/\d{3}/).join("/")
|
35
40
|
end
|
36
41
|
|
37
|
-
def self.find_by_id_partition(params)
|
38
|
-
self.find((params[:id0] + params[:id1] + params[:id2]).to_i)
|
39
|
-
end
|
40
|
-
|
41
42
|
def name
|
42
43
|
file_file_name
|
43
44
|
end
|
44
45
|
|
46
|
+
def basename
|
47
|
+
name.gsub(/#{extension}$/, "").strip
|
48
|
+
end
|
49
|
+
|
50
|
+
def extension
|
51
|
+
File.extname(name)
|
52
|
+
end
|
53
|
+
|
45
54
|
def width
|
46
55
|
Paperclip::Geometry.from_file(file).width
|
47
56
|
end
|
@@ -88,6 +97,11 @@ class PapermillAsset < ActiveRecord::Base
|
|
88
97
|
end
|
89
98
|
|
90
99
|
private
|
100
|
+
|
101
|
+
def set_real_file_name
|
102
|
+
self.file_file_name = @real_file_name
|
103
|
+
end
|
104
|
+
|
91
105
|
def set_position
|
92
106
|
self.position ||= PapermillAsset.first(:conditions => {:assetable_key => assetable_key, :assetable_type => assetable_type, :assetable_id => assetable_id}, :order => "position DESC" ).try(:position).to_i + 1
|
93
107
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# It MUST stand in your RAILS_ROOT/config/initializer folder
|
3
3
|
# It is explicitely early-loaded by Papermill
|
4
4
|
# Papermill::OPTIONS constant needs to be set before PapermillAsset is loaded, and PapermillAsset cannot be lazy-loaded
|
5
|
-
|
6
5
|
module Papermill
|
7
6
|
|
8
7
|
# All these options will be used as defaults. You can change them :
|
@@ -27,6 +26,7 @@ module Papermill
|
|
27
26
|
# Merges are recursive (for :gallery, :thumbnail and :swfupload sub-hashs)
|
28
27
|
|
29
28
|
unless defined?(OPTIONS)
|
29
|
+
|
30
30
|
OPTIONS = {
|
31
31
|
# Associated PapermillAsset subclass
|
32
32
|
:class_name => "PapermillAsset",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papermill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Benoit B\xC3\xA9n\xC3\xA9zech"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-14 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements: []
|
111
111
|
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.4
|
114
114
|
signing_key:
|
115
115
|
specification_version: 3
|
116
116
|
summary: Paperclip Swfupload UploadHelper wrapper
|