README.rdoc in papermill-1.4.3 vs README.rdoc in papermill-2.0.0.pre
- old
+ new
@@ -106,58 +106,37 @@
Maybe you don't want users to use your application as a thumbnailing farm for their own uploaded images, or you have protected members areas and you don't want users to 'browse' others members file.
* Brute solution: pass :use_url_key to true in the options (config/initializers/papermill.rb). A crypted hash unique to your application and to each asset and to the requested style will be added to the URL. No more happy-guessing of anything. Do that first before going live, or you'll have to migrate all assets...
* pass :alias_only to true. This will disable the possibility to generate thumbnails with a papermill string in the url, but won't do anything for the member area thing. Plus you will have to use aliases only, form helpers included (pass :thumbnail => { :style => :some_alias })
-=== Restricted-area/back-office
-
-Go to the options and look for :
- :authorize_create => true,
- :authorize_update_and_destroy => true,
- :authorize_multiple_modification => true,
-
-You will find a quick & dirty solution to pass your authorizations rules in before_filters, before any asset gets hurt.
-
== Usage
Assetable is the class that has_many papermill_assets (i.e. the class with the papermill declaration)
=== Assetable declaration
You can have a generic association and as many declarative associations as you want in your model. Papermill will always use specific if found.
-article.rb
-
- class Article < ActiveRecord::Base
- papermill :class_name => ColorAsset, other_options.. # generic, will use ColorAsset instead of PapermillAsset (ColorAsset must be an STIed PapermillAsset)
+ class Article
+ papermill :images
+ papermill :pdf_version
+ papermill :cover_image
+ papermill :illustrations
end
-entry.rb
-
- class Entry < ActiveRecord::Base
- papermill :mug_shot, other_options.. # specific association on :mug_shot
- papermill :diaporama, :class_name => ColorAsset, other_options.. # specific association on :diaporama will use ColorAssets
- end
-
-color_asset.rb # You can add columns to papermill_assets and use STI on PapermillAsset to extend defaults abilities (or re-open PapermillAsset/monkey-patch it/use a polymorphic association on PapermillAsset to extend it with behaviors..)
-
- class ColorAsset < PapermillAsset
- named_scope :red, :conditions => {:color => 'red'}
- end
-
=== Form helpers
Example form:
form_for @assetable do
# I need a simple asset upload field :
f.asset_upload :pdf_version
# Now I need to be able to upload as many documents as I need, and sort them at will
# no document should be bigger than 1MB (respect the quoting!)
- # and I don't want any dashboard mass_edit feature, just mass_delete (delete all)
- f.assets_upload :documentation, :swfupload => { :file_size_limit => "'1 MB'" }, :dashboard => [:mass_delete]
+ # and I don't want the mass_edit feature
+ f.assets_upload :documentation, :swfupload => { :file_size_limit => "'1 MB'" }, :mass_edit => false
# I need to display *one* cover *image*, format will be 200x200
# targetted_size will give the uploader hints when cropping the image after upload : desired display size and wanted aspect-ratio.
# Better than cropping automatically in the center if the character's head is in the upper-left corner..
# :thumbnail => { :width & :height } set the dimensions of the preview thumbnail
@@ -193,14 +172,10 @@
With FormTagHelpers, use (image_upload_tag | images_upload_tag | asset_upload_tag | assets_upload_tag) @assetable, :key, options
image_upload_tag @article, :cover_image, :targetted_size => "200x200"
-For resources not linked to any assetable model, you can use upload_tags without any Assetable
-
- image_upload_tag "#{current_organization.name}_logo", :targetted_size => "200x200"
-
=== Asset editing
* double-click on any uploaded asset in any form-helper to access & edit his properties
* then double-click image to crop it if it's an image. You'll then access a Jcrop window. Pass :targetted_size => "widthxheigth" to lock aspect-ratio and default the selection size to widthxheigth.
@@ -290,31 +265,18 @@
:name => "thumbnail_watermarked_and_copyrighted"
)
=== Resource access
-Papermill generates an #assets(:key, *args) named_scope
- @article.assets(:illustrations)
- @article.assets(:illustrations, :order => "created_at DESC")
- @article.assets(:illustrations).red.first
- # etc.
+Papermill generates an #<association_key> association
-With declarative papermill associations, Papermill also generates an #<association_key>(*args) named_scope
- @entry.mug_shot.first
- @entry.diaporama
- @entry.diaporama(:order => "created_at DESC")
- @entry.diaporama.red
- # === @entry.diaporama(:conditions => {:color => "red"})
- # === @entry.assets(:diaporama, :conditions => {:color => "red"})
+ @entry.mug_shots.first
+ @entry.diaporamas.each do |image| ..
# etc.
-
-Or for non-assetable resources :
- PapermillAsset.key("#{current_organization.name}_logo").first
- ColorAsset.all.red
-
+
=== Using PapermillAsset
- @asset = @entry.mug_shot.first
+ @asset = @entry.mug_shots.first
image_tag @asset.url # original
image_tag @asset.url("100x>") # assuming asset is an image
image_tag @asset.url(:big) # assuming you have a :big alias
@asset.name
@asset.content_type
\ No newline at end of file