papermill 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +64 -56
- data/VERSION +1 -1
- data/app/controllers/papermill_controller.rb +0 -4
- data/generators/papermill_table/templates/migrate/papermill_migration.rb.erb +11 -6
- data/lib/papermill.rb +3 -0
- data/lib/papermill/flash_session_cookie_middleware.rb +16 -0
- data/lib/papermill/form_builder.rb +6 -1
- data/lib/papermill/papermill.rb +12 -8
- data/lib/papermill/papermill_asset.rb +6 -5
- data/lib/papermill/papermill_helper.rb +2 -2
- data/lib/papermill/papermill_paperclip_processor.rb +58 -0
- data/test/papermill_test.rb +13 -1
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -1,39 +1,47 @@
|
|
1
1
|
= Papermill
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
|
5
|
+
* Asset management made easy, 10 minutes integration.
|
6
|
+
* All-you-can-eat glue around Polymorphic Paperclip table, SWFUpload & JQuery.
|
7
|
+
* Associate any image or list of images with any model and any key.
|
8
|
+
|
9
|
+
== Install the gem
|
10
|
+
|
11
|
+
sudo gem install papermill
|
12
|
+
|
13
|
+
== Try the demo
|
14
|
+
|
15
|
+
rails -m http://github.com/bbenezech/papermill/raw/master/demo.txt papermill-example
|
6
16
|
|
7
17
|
=== Out-of-the-box OPTIONAL compatibility with :
|
8
18
|
|
9
|
-
Formtastic # use :as => :[image|asset](s)_upload
|
10
|
-
JGrowl # instead of alert for notifications
|
11
|
-
FaceBox/Shadowbox # instead of a pop_up for edit form
|
12
|
-
Stringex # (or any String#to_url) for asset filename/url generation
|
19
|
+
* Formtastic # use :as => :[image|asset](s)_upload
|
20
|
+
* JGrowl # instead of alert for notifications
|
21
|
+
* FaceBox/Shadowbox # instead of a pop_up for edit form
|
22
|
+
* Stringex # (or any String#to_url) for asset filename/url generation
|
13
23
|
|
14
24
|
=== Navigator minimal requirements:
|
15
25
|
|
16
|
-
IE6
|
26
|
+
* IE6+
|
27
|
+
* Flash 9+
|
28
|
+
* Javascript ON.
|
29
|
+
|
30
|
+
Check your audience.
|
17
31
|
|
18
32
|
=== Server requirements:
|
19
33
|
|
20
|
-
|
21
|
-
Rails 2.3 (rail's I18n, engine)
|
22
|
-
Paperclip 2.3 branch (installed by default as a gem dependency, will be loaded internally if needed)
|
23
|
-
|
34
|
+
* Makes internal use of JQuery (but loaded in compatibility mode by default, compatible with Prototype/whatever... JRails not needed.)
|
35
|
+
* Rails 2.3 (rail's I18n, engine)
|
36
|
+
* Paperclip 2.3 branch (installed by default as a gem dependency, will be loaded internally if needed => You can require your own version of Paperclip)
|
37
|
+
* Front web server serving static assets if present, and forwarding demand to rails if not. (Usually a no-brainer on any classic installation. Works with Webrick)
|
38
|
+
|
39
|
+
|
40
|
+
=== Windows environnement :
|
41
|
+
|
24
42
|
# Mime/Types library. Ex:
|
25
43
|
config.gem "mime-types", :lib => "mime/types"
|
26
44
|
|
27
|
-
Front web server serving static assets if present, and forwarding demand to rails if not. (Usually a no-brainer on any classic installation. Works with Webrick)
|
28
|
-
|
29
|
-
== Install the gem
|
30
|
-
|
31
|
-
$ sudo gem install papermill
|
32
|
-
|
33
|
-
== Try the demo
|
34
|
-
|
35
|
-
$ rails -m http://github.com/bbenezech/papermill/raw/master/demo.txt papermill-example
|
36
|
-
|
37
45
|
== Features
|
38
46
|
|
39
47
|
Loads of them
|
@@ -68,36 +76,25 @@ Loads of them
|
|
68
76
|
* :third_alias => {:geometry => '100:122', :my_other_keys => 'blblabla'} # if you have a customed Paperclip::Thumbnail processor, you can pass any values you need.
|
69
77
|
* Use them when you need them : my_asset.url(:big_alias)
|
70
78
|
|
71
|
-
== Papermill comes in 2 flavors:
|
72
|
-
|
73
|
-
=== Generic catch-all declaration
|
74
|
-
|
75
|
-
papermill options_hash # in your papermilled assetable model
|
76
|
-
@article.assets(:any_key, options_hash) # data access
|
77
|
-
|
78
|
-
=== Association specific declaration
|
79
|
-
|
80
|
-
papermill :my_association, options_hash # in your papermilled assetable model
|
81
|
-
@article.my_association # data access
|
82
|
-
|
83
|
-
== Usage:
|
84
|
-
|
85
79
|
=== Model declaration
|
86
80
|
|
87
81
|
You can have a generic association and as many declarative associations as you want in your model. Papermill will always use specific if found.
|
88
82
|
|
89
83
|
article.rb
|
84
|
+
|
90
85
|
class Article < ActiveRecord::Base
|
91
86
|
papermill :class_name => ColorAsset, other_options..
|
92
87
|
end
|
93
88
|
|
94
89
|
entry.rb
|
90
|
+
|
95
91
|
class Entry < ActiveRecord::Base
|
96
|
-
papermill :mug_shot, other_options..
|
92
|
+
papermill :mug_shot, other_options..
|
97
93
|
papermill :diaporama, :class_name => ColorAsset, other_options..
|
98
94
|
end
|
99
95
|
|
100
96
|
color_asset.rb # You should add columns to papermill_assets and use STI on PapermillAsset to extend defaults capabilities (or re-open PapermillAsset and monkey-patch it..)
|
97
|
+
|
101
98
|
class ColorAsset < PapermillAsset
|
102
99
|
named_scope :red, :conditions => {:color => 'red'}
|
103
100
|
end
|
@@ -105,6 +102,7 @@ color_asset.rb # You should add columns to papermill_assets and use STI on Pape
|
|
105
102
|
=== Form helpers
|
106
103
|
|
107
104
|
FormHelpers
|
105
|
+
|
108
106
|
form_for @article do
|
109
107
|
f.image_upload :cover_image, options_hash
|
110
108
|
f.images_upload :illustrations, options_hash
|
@@ -113,6 +111,7 @@ FormHelpers
|
|
113
111
|
end
|
114
112
|
|
115
113
|
Or with formtastic :
|
114
|
+
|
116
115
|
semantic_form_for @article do |f|
|
117
116
|
f.input @article, :cover_image, options_hash, :as => :image_upload
|
118
117
|
f.input @article, :illustrations, options_hash, :as => :images_upload
|
@@ -121,13 +120,15 @@ Or with formtastic :
|
|
121
120
|
end
|
122
121
|
|
123
122
|
FormTagHelpers
|
123
|
+
|
124
124
|
image_upload_tag @article, :cover_image, options_hash
|
125
125
|
images_upload_tag @article, :illustrations, options_hash
|
126
126
|
asset_upload_tag @article, :pdf, options_hash
|
127
127
|
image_upload_tag @article, :other_ressources, options_hash
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
|
129
|
+
For resources not linked to any assetable model :
|
130
|
+
image_upload_tag "#{current_organization.name}_logo"
|
131
|
+
|
131
132
|
=== Resource access
|
132
133
|
|
133
134
|
With generic papermill association, Papermill generates an #assets(:key, *args) named_scope
|
@@ -135,13 +136,14 @@ With generic papermill association, Papermill generates an #assets(:key, *args)
|
|
135
136
|
@article.assets(:illustrations, :order => "created_at DESC")
|
136
137
|
@article.assets(:illustrations).red.first
|
137
138
|
# etc.
|
138
|
-
|
139
|
-
With declarative papermill associations, Papermill generates an #<association_key>(*args) named_scope
|
139
|
+
|
140
|
+
With declarative papermill associations, Papermill also generates an #<association_key>(*args) named_scope
|
140
141
|
@entry.mug_shot.first
|
141
142
|
@entry.diaporama
|
142
143
|
@entry.diaporama(:order => "created_at DESC")
|
143
144
|
@entry.diaporama.red
|
144
145
|
# === @entry.diaporama(:conditions => {:color => "red"})
|
146
|
+
# === @entry.assets(:diaporama, :conditions => {:color => "red"})
|
145
147
|
# etc.
|
146
148
|
|
147
149
|
Or for non-assetable resources :
|
@@ -149,7 +151,7 @@ Or for non-assetable resources :
|
|
149
151
|
ColorAsset.all.red
|
150
152
|
|
151
153
|
=== Using PapermillAsset
|
152
|
-
|
154
|
+
|
153
155
|
@asset = @entry.mug_shot.first
|
154
156
|
image_tag @asset.url # original
|
155
157
|
image_tag @asset.url("100x>")
|
@@ -159,26 +161,32 @@ Or for non-assetable resources :
|
|
159
161
|
@asset.path # original
|
160
162
|
@asset.path("100x>")
|
161
163
|
# etc.
|
162
|
-
|
164
|
+
|
163
165
|
== Installation
|
164
166
|
|
165
167
|
=== Once gem is installed :
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
=== Then in environment.rb:
|
169
|
+
Generate the migration :
|
170
|
+
./script/generate papermill_table PapermillMigration
|
171
|
+
|
172
|
+
Edit its fields and migrate :
|
173
|
+
rake db:migrate
|
174
|
+
|
175
|
+
Copy static assets to your public directory:
|
176
|
+
./script/generate papermill_assets
|
176
177
|
|
178
|
+
Create the option hash in config/initializers/papermill.rb
|
179
|
+
./script/generate papermill_initializer
|
180
|
+
|
181
|
+
Then see config/initializers/papermill.rb for the option hash.
|
182
|
+
|
183
|
+
=== environment.rb:
|
184
|
+
|
177
185
|
...
|
178
186
|
Rails::Initializer.run do |config|
|
179
187
|
...
|
180
188
|
config.gem papermill
|
181
|
-
config.gem "mime-types", :lib => "mime/types" # required for windows
|
189
|
+
config.gem "mime-types", :lib => "mime/types" # required for windows OS
|
182
190
|
end
|
183
191
|
|
184
192
|
=== In your layout:
|
@@ -191,7 +199,7 @@ Or for non-assetable resources :
|
|
191
199
|
|
192
200
|
Papermill is fully I18n-able.
|
193
201
|
Copy config/locales/papermill.yml to your root config/locale folder to modify any wording in a any locale.
|
194
|
-
|
202
|
+
|
195
203
|
Copyright (c) 2009 Benoit Bénézech, released under the MIT license
|
196
|
-
|
204
|
+
|
197
205
|
http://rubyonrails.org/images/rails.png
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
@@ -1,8 +1,4 @@
|
|
1
1
|
class PapermillController < ApplicationController
|
2
|
-
# Create is protected because of the Ajax same origin policy.
|
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
|
-
skip_before_filter :verify_authenticity_token, :only => [:create]
|
5
|
-
|
6
2
|
prepend_before_filter :load_asset, :only => [ "show", "destroy", "update", "edit" ]
|
7
3
|
prepend_before_filter :load_assets, :only => [ "sort", "mass_delete", "mass_edit" ]
|
8
4
|
|
@@ -9,18 +9,23 @@ class <%= migration_name %> < ActiveRecord::Migration
|
|
9
9
|
|
10
10
|
# Papermill fields (required)
|
11
11
|
t.integer :position # sets are ordered by position
|
12
|
-
|
13
|
-
t.
|
14
|
-
|
12
|
+
|
13
|
+
t.belongs_to :assetable, :polymorphic => true
|
14
|
+
|
15
|
+
t.string :assetable_key
|
15
16
|
t.string :type # STI
|
16
|
-
t.string :title #
|
17
|
+
t.string :title # filename not transformed, without file extension, for your own use
|
17
18
|
|
18
|
-
#
|
19
|
+
# Example additionals fields (configure :mass_editable_fields/:editable_fields accordingly)
|
19
20
|
t.string :alt
|
20
21
|
t.string :copyright
|
21
22
|
t.text :description
|
22
23
|
t.timestamps
|
23
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
change_table :papermill_assets do |t|
|
27
|
+
t.index [:assetable_type, :assetable_id, :assetable_key, :position]
|
28
|
+
t.index [:assetable_key, :position] # for non assetable assets
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
data/lib/papermill.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
I18n.load_path = [File.join(File.dirname(__FILE__), "../config/locales/papermill.yml")] + I18n.load_path
|
2
2
|
require 'extensions'
|
3
|
+
require 'papermill/flash_session_cookie_middleware.rb'
|
4
|
+
|
3
5
|
Object.send :include, PapermillObjectExtensions
|
4
6
|
Hash.send :include, PapermillHashExtensions
|
5
7
|
File.send :include, PapermillFileExtensions
|
@@ -13,6 +15,7 @@ rescue LoadError
|
|
13
15
|
end
|
14
16
|
|
15
17
|
require 'paperclip' unless defined?(Paperclip)
|
18
|
+
require 'papermill/papermill_paperclip_processor'
|
16
19
|
require 'papermill/papermill'
|
17
20
|
require 'papermill/papermill_asset'
|
18
21
|
require 'papermill/form_builder'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
class FlashSessionCookieMiddleware
|
4
|
+
def initialize(app, session_key = '_session_id')
|
5
|
+
@app = app
|
6
|
+
@session_key = session_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
|
11
|
+
params = ::Rack::Request.new(env).params
|
12
|
+
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
|
13
|
+
end
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
@@ -109,7 +109,7 @@ module ActionView::Helpers::FormTagHelper
|
|
109
109
|
html[:upload_button] = %{<div id="#{id}-button-wrapper" class="papermill-button-wrapper" style="height: #{options[:swfupload][:button_height]}px;"><span id="browse_for_#{id}" class="swf_button"></span></div>}
|
110
110
|
html[:container] = @template.content_tag(:div, :id => id, :class => "#{(options[:thumbnail] ? "papermill-thumb-container" : "papermill-asset-container")} #{(options[:gallery] ? "papermill-multiple-items" : "papermill-unique-item")}") {
|
111
111
|
@template.render :partial => "papermill/asset", :collection => collection, :locals => { :thumbnail_style => options[:thumbnail] && options[:thumbnail][:style] }
|
112
|
-
}
|
112
|
+
}
|
113
113
|
|
114
114
|
if options[:gallery]
|
115
115
|
html[:dashboard] = {}
|
@@ -136,6 +136,10 @@ module ActionView::Helpers::FormTagHelper
|
|
136
136
|
|
137
137
|
@template.content_for :papermill_inline_js do %{
|
138
138
|
new SWFUpload({
|
139
|
+
post_params: {
|
140
|
+
"#{ActionController::Base.session_options[:key]}": "#{@template.cookies[ActionController::Base.session_options[:key]]}",
|
141
|
+
"authenticity_token": "#{@template.form_authenticity_token}"
|
142
|
+
},
|
139
143
|
upload_id: "#{id}",
|
140
144
|
upload_url: "#{@template.escape_javascript create_url}",
|
141
145
|
file_types: "#{options[:images_only] ? '*.jpg;*.jpeg;*.png;*.gif' : ''}",
|
@@ -153,6 +157,7 @@ module ActionView::Helpers::FormTagHelper
|
|
153
157
|
});
|
154
158
|
}
|
155
159
|
end
|
160
|
+
|
156
161
|
%{<div class="papermill">#{@timestamp_field.to_s + options[:form_helper_elements].map{|element| html[element] || ""}.join("\n")}</div>}
|
157
162
|
end
|
158
163
|
end
|
data/lib/papermill/papermill.rb
CHANGED
@@ -24,16 +24,20 @@ module Papermill
|
|
24
24
|
after_create :rebase_assets
|
25
25
|
has_many :papermill_assets, :as => "Assetable", :dependent => :destroy
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
[assoc_name, Papermill::options[:base_association_name].to_sym].uniq.each do |assoc|
|
28
|
+
define_method assoc do |*options|
|
29
|
+
scope = PapermillAsset.scoped(:conditions => {:assetable_id => self.id, :assetable_type => self.class.base_class.name})
|
30
|
+
if assoc != Papermill::options[:base_association_name]
|
31
|
+
scope = scope.scoped(:conditions => { :assetable_key => assoc.to_s })
|
32
|
+
elsif options.first && !options.first.is_a?(Hash)
|
33
|
+
scope = scope.scoped(:conditions => { :assetable_key => options.shift.to_s.nie })
|
34
|
+
end
|
35
|
+
scope = scope.scoped(options.shift) if options.first
|
36
|
+
scope
|
33
37
|
end
|
34
|
-
scope = scope.scoped(options.shift) if options.first
|
35
|
-
scope
|
36
38
|
end
|
39
|
+
ActionController::Dispatcher.middleware.delete(FlashSessionCookieMiddleware) rescue nil
|
40
|
+
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key]) rescue nil
|
37
41
|
end
|
38
42
|
|
39
43
|
def inherited(subclass)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class PapermillAsset < ActiveRecord::Base
|
2
2
|
|
3
3
|
before_destroy :destroy_files
|
4
|
-
before_create :set_position
|
4
|
+
before_create :set_position
|
5
5
|
|
6
6
|
has_attached_file :file,
|
7
|
+
:processors => [:papermill_paperclip_processor],
|
7
8
|
:path => "#{Papermill::options[:public_root]}/#{Papermill::options[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}",
|
8
9
|
:url => "/#{Papermill::options[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}"
|
9
10
|
|
@@ -12,9 +13,9 @@ class PapermillAsset < ActiveRecord::Base
|
|
12
13
|
validates_attachment_presence :file
|
13
14
|
|
14
15
|
belongs_to :assetable, :polymorphic => true
|
15
|
-
default_scope :order => '
|
16
|
+
default_scope :order => 'assetable_type, assetable_id, assetable_key, position'
|
16
17
|
|
17
|
-
named_scope :key, lambda { |assetable_key| { :conditions => ['assetable_key = ?', assetable_key] }}
|
18
|
+
named_scope :key, lambda { |assetable_key| { :conditions => ['assetable_key = ?', assetable_key.to_s] }}
|
18
19
|
|
19
20
|
def Filedata=(data)
|
20
21
|
data.content_type = data.get_content_type # SWFUpload content-type fix
|
@@ -27,7 +28,7 @@ class PapermillAsset < ActiveRecord::Base
|
|
27
28
|
|
28
29
|
def create_thumb_file(style_name)
|
29
30
|
FileUtils.mkdir_p File.dirname(file.path(style_name))
|
30
|
-
FileUtils.mv(Paperclip::
|
31
|
+
FileUtils.mv(Paperclip::PapermillPaperclipProcessor.make(file, self.class.compute_style(style_name)).path, file.path(style_name))
|
31
32
|
end
|
32
33
|
|
33
34
|
def id_partition
|
@@ -100,7 +101,7 @@ class PapermillAsset < ActiveRecord::Base
|
|
100
101
|
end
|
101
102
|
|
102
103
|
def set_position
|
103
|
-
self.position ||= PapermillAsset.
|
104
|
+
self.position ||= PapermillAsset.maximum(:position, :conditions => { :assetable_type => assetable_type, :assetable_id => assetable_id, :assetable_key => assetable_key } ).to_i + 1
|
104
105
|
end
|
105
106
|
|
106
107
|
def destroy_files
|
@@ -9,10 +9,10 @@ module PapermillHelper
|
|
9
9
|
# If you loaded jQuery and need to load only jQueryUI, call papermill_javascript_tag(:with_jqueryui_only => true)
|
10
10
|
def papermill_javascript_tag(options = {})
|
11
11
|
html = []
|
12
|
-
if options[:with_jquery] || options[:
|
12
|
+
if options[:with_jquery] || options[:with_jqueryui_only]
|
13
13
|
html << %{<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>} if options[:with_jquery]
|
14
14
|
html << %{<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>} if options[:with_jquery] || options[:with_jqueryui_only]
|
15
|
-
html << %{<script type="text/javascript">jQuery.noConflict();</script>} if options[:with_jquery] == "no_conflict"
|
15
|
+
html << %{<script type="text/javascript">jQuery.noConflict();</script>} if options[:with_jquery].to_s == "no_conflict"
|
16
16
|
end
|
17
17
|
html << %{<script type="text/javascript">}
|
18
18
|
["SWFUPLOAD_PENDING", "SWFUPLOAD_LOADING"].each do |js_constant|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Paperclip
|
2
|
+
|
3
|
+
# Handles thumbnailing images that are uploaded.
|
4
|
+
class PapermillPaperclipProcessor < Thumbnail
|
5
|
+
|
6
|
+
attr_reader :crop_h, :crop_w, :crop_x, :crop_y, :copyright
|
7
|
+
|
8
|
+
def initialize(file, options = {}, attachment = nil)
|
9
|
+
@crop_h, @crop_w, @crop_x, @crop_y = options[:crop_h], options[:crop_w], options[:crop_x], options[:crop_y]
|
10
|
+
|
11
|
+
if options[:geometry] =~ /©/
|
12
|
+
options[:geometry], *@copyright = options[:geometry].split("©")
|
13
|
+
@copyright = @copyright.join("©").nie || options[:copyright] || @attachment.instance.respond_to?(:copyright) && @attachment.instance.copyright
|
14
|
+
end
|
15
|
+
|
16
|
+
if options[:geometry] =~ /#.+/
|
17
|
+
|
18
|
+
# <@target_geometry.width>x<@target_geometry.height>#<@crop_w>x<@crop_h>:<@crop_x>:<@crop_y>
|
19
|
+
# <@target_geometry.width>x<@target_geometry.height>#<@crop_w>x<@crop_h>
|
20
|
+
# <@target_geometry.width>x<@target_geometry.height>#<@crop_x>:<@crop_y>
|
21
|
+
|
22
|
+
options[:geometry], manual_crop = options[:geometry].split("#")
|
23
|
+
|
24
|
+
crop_dimensions, @crop_x, @crop_y = manual_crop.split("+")
|
25
|
+
|
26
|
+
if crop_dimensions =~ /x/
|
27
|
+
@crop_w, @crop_h = crop_dimensions.split("x")
|
28
|
+
else
|
29
|
+
@crop_x, @crop_y = crop_dimensions, @crop_x
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
options[:geometry] = (options[:geometry].nie || "#{@crop_x}x#{@crop_y}") + "#"
|
34
|
+
|
35
|
+
unless @crop_w && @crop_h
|
36
|
+
@target_geometry = Geometry.parse(options[:geometry])
|
37
|
+
@crop_w ||= @target_geometry.try(:width).to_i
|
38
|
+
@crop_h ||= @target_geometry.try(:height).to_i
|
39
|
+
end
|
40
|
+
end
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def transformation_command
|
45
|
+
puts "crop_command= #{crop_command ? super.sub(/ -crop \S+/, crop_command) : super}"
|
46
|
+
|
47
|
+
crop_command ? super.sub(/ -crop \S+/, crop_command) : super
|
48
|
+
end
|
49
|
+
|
50
|
+
def crop_command
|
51
|
+
if @crop_h || @crop_x
|
52
|
+
" -crop '%dx%d+%d+%d'" % [ @crop_w, @crop_h, @crop_x, @crop_y ].map(&:to_i)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
data/test/papermill_test.rb
CHANGED
@@ -76,12 +76,24 @@ class PapermillTest < Test::Unit::TestCase
|
|
76
76
|
assert_equal @article.my_assets.map(&:id), [3,4]
|
77
77
|
assert_equal @article.my_assets(:order => "position DESC").map(&:id), [4,3]
|
78
78
|
assert_equal @article.my_assets(:order => "position DESC", :limit => 1).map(&:id), [4]
|
79
|
+
|
80
|
+
assert_equal @article.assets(:my_assets).map(&:id), [3,4]
|
81
|
+
assert_equal @article.assets(:my_assets, :order => "position DESC").map(&:id), [4,3]
|
82
|
+
assert_equal @article.assets(:my_assets, :order => "position DESC", :limit => 1).map(&:id), [4]
|
83
|
+
|
84
|
+
assert_equal @article.papermill_assets.key(:my_assets).map(&:id), [3,4]
|
85
|
+
assert_equal @article.papermill_assets.key(:my_assets).all(:order => "position DESC").map(&:id), [4,3]
|
86
|
+
assert_equal @article.papermill_assets.key(:my_assets).all(:order => "position DESC", :limit => 1).map(&:id), [4]
|
79
87
|
end
|
80
88
|
|
81
|
-
def
|
89
|
+
def test_namedscope_for_global_associations
|
82
90
|
assert_equal @article.assets(:asset1).map(&:id), [2,1]
|
83
91
|
assert_equal @article.assets(:asset1, :order => "position DESC").map(&:id), [1,2]
|
84
92
|
assert_equal @article.assets(:asset1, :order => "position DESC", :limit => 1).map(&:id), [1]
|
93
|
+
|
94
|
+
assert_equal @article.papermill_assets.key(:asset1).map(&:id), [2,1]
|
95
|
+
assert_equal @article.papermill_assets.key(:asset1).all(:order => "position DESC").map(&:id), [1,2]
|
96
|
+
assert_equal @article.papermill_assets.key(:asset1).all(:order => "position DESC", :limit => 1).map(&:id), [1]
|
85
97
|
end
|
86
98
|
|
87
99
|
def test_id_partition
|
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: 1.1.
|
4
|
+
version: 1.1.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-25 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,11 +57,13 @@ files:
|
|
57
57
|
- install.rb
|
58
58
|
- lib/extensions.rb
|
59
59
|
- lib/papermill.rb
|
60
|
+
- lib/papermill/flash_session_cookie_middleware.rb
|
60
61
|
- lib/papermill/form_builder.rb
|
61
62
|
- lib/papermill/papermill.rb
|
62
63
|
- lib/papermill/papermill_asset.rb
|
63
64
|
- lib/papermill/papermill_helper.rb
|
64
65
|
- lib/papermill/papermill_options.rb
|
66
|
+
- lib/papermill/papermill_paperclip_processor.rb
|
65
67
|
- public/.DS_Store
|
66
68
|
- public/papermill/README
|
67
69
|
- public/papermill/images/background.png
|
@@ -110,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
requirements: []
|
111
113
|
|
112
114
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.3.
|
115
|
+
rubygems_version: 1.3.5
|
114
116
|
signing_key:
|
115
117
|
specification_version: 3
|
116
118
|
summary: Paperclip Swfupload UploadHelper wrapper
|