papermill 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +38 -17
- data/VERSION +1 -1
- data/app/controllers/papermill_controller.rb +31 -15
- data/app/views/papermill/_asset.html.erb +1 -1
- data/app/views/papermill/_form.html.erb +15 -8
- data/app/views/papermill/edit.html.erb +4 -4
- data/lib/papermill/form_builder.rb +3 -11
- data/lib/papermill/papermill.rb +2 -6
- data/lib/papermill/papermill_asset.rb +17 -15
- data/lib/papermill/papermill_options.rb +8 -0
- data/public/papermill/papermill.css +2 -0
- data/public/papermill/papermill.js +23 -37
- metadata +2 -3
- data/installation-template.txt +0 -113
data/README.rdoc
CHANGED
@@ -1,27 +1,49 @@
|
|
1
1
|
= Papermill
|
2
2
|
|
3
|
-
Asset management made easy.
|
3
|
+
Asset management made easy, 10 minutes integration.
|
4
|
+
All-you-can-eat glue around Polymorphic Paperclip table, SWFUpload & JQuery.
|
5
|
+
Associate any image or list of images with any model and any key.
|
4
6
|
|
5
|
-
|
7
|
+
=== Out-of-the-box OPTIONAL compatibility with :
|
8
|
+
|
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
|
13
|
+
|
14
|
+
=== Navigator minimal requirements:
|
15
|
+
|
16
|
+
IE6+, Flash 9+, Javascript ON. Check your audience.
|
17
|
+
|
18
|
+
=== Server requirements:
|
19
|
+
|
20
|
+
makes internal use of JQuery (but loaded in compatibility mode by default, compatible with Prototype/whatever... JRails not needed.)
|
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
|
+
Windows environnement :
|
24
|
+
# Mime/Types library. Ex:
|
25
|
+
config.gem "mime-types", :lib => "mime/types"
|
26
|
+
|
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
|
6
30
|
|
7
|
-
$ gem source -a http://gemcutter.org
|
8
31
|
$ sudo gem install papermill
|
9
32
|
|
10
33
|
== Try the demo
|
11
34
|
|
12
|
-
$
|
13
|
-
$ rails -m http://github.com/bbenezech/papermill/raw/master/installation-template.txt papermill-example
|
35
|
+
$ rails -m http://github.com/bbenezech/papermill/raw/master/demo.txt papermill-example
|
14
36
|
|
15
37
|
== Features
|
16
38
|
|
17
39
|
Loads of them
|
18
40
|
|
19
|
-
=== Ajax uploading form helpers through SWFUpload
|
41
|
+
=== Ajax uploading form helpers through SWFUpload => [image|asset](s)_upload
|
20
42
|
|
21
|
-
* image_upload =>
|
22
|
-
* images_upload => sortable image gallery
|
23
|
-
* asset_upload =>
|
24
|
-
* assets_upload => sortable asset list
|
43
|
+
* image_upload => one image, with thumbnail preview
|
44
|
+
* images_upload => sortable image thumbnail gallery
|
45
|
+
* asset_upload => one asset
|
46
|
+
* assets_upload => sortable asset list
|
25
47
|
|
26
48
|
=== Choose thumbnail size for images previews :
|
27
49
|
|
@@ -39,12 +61,12 @@ Loads of them
|
|
39
61
|
* thumbnails are generated the first time they are asked-for, and only in the requested size.
|
40
62
|
* no need to register thumbnail size anywhere: my_asset.url("100x100>")
|
41
63
|
|
42
|
-
=== Alias handling, declaration application-wide
|
64
|
+
=== Alias handling, declaration application-wide (in config/initializers/papermill.rb, after you do a ./script/generate papermill_initializer)
|
43
65
|
|
44
66
|
* :big_alias => {:geometry => "1000x>"}
|
45
67
|
* :other_alias => "100x>"
|
46
68
|
* :third_alias => {:geometry => '100:122', :my_other_keys => 'blblabla'} # if you have a customed Paperclip::Thumbnail processor, you can pass any values you need.
|
47
|
-
*
|
69
|
+
* Use them when you need them : my_asset.url(:big_alias)
|
48
70
|
|
49
71
|
== Papermill comes in 2 flavors:
|
50
72
|
|
@@ -106,7 +128,7 @@ FormTagHelpers
|
|
106
128
|
# For resources not linked to any assetable model :
|
107
129
|
image_upload_tag #{current_organization.name}_logo
|
108
130
|
|
109
|
-
===
|
131
|
+
=== Resource access
|
110
132
|
|
111
133
|
With generic papermill association, Papermill generates an #assets(:key, *args) named_scope
|
112
134
|
@article.assets(:illustrations)
|
@@ -123,7 +145,7 @@ With declarative papermill associations, Papermill generates an #<association_ke
|
|
123
145
|
# etc.
|
124
146
|
|
125
147
|
Or for non-assetable resources :
|
126
|
-
PapermillAsset.
|
148
|
+
PapermillAsset.key("#{current_organization.name}_logo").first
|
127
149
|
ColorAsset.all.red
|
128
150
|
|
129
151
|
=== Using PapermillAsset
|
@@ -131,7 +153,7 @@ Or for non-assetable resources :
|
|
131
153
|
@asset = @entry.mug_shot.first
|
132
154
|
image_tag @asset.url # original
|
133
155
|
image_tag @asset.url("100x>")
|
134
|
-
image_tag @asset.url(:big) # assuming you have a :big alias
|
156
|
+
image_tag @asset.url(:big) # assuming you have a :big alias
|
135
157
|
@asset.name
|
136
158
|
@asset.content_type
|
137
159
|
@asset.path # original
|
@@ -156,8 +178,7 @@ Or for non-assetable resources :
|
|
156
178
|
Rails::Initializer.run do |config|
|
157
179
|
...
|
158
180
|
config.gem papermill
|
159
|
-
|
160
|
-
config.gem "mime-types", :lib => "mime/types"
|
181
|
+
config.gem "mime-types", :lib => "mime/types" # required for windows only
|
161
182
|
end
|
162
183
|
|
163
184
|
=== In your layout:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
@@ -3,32 +3,35 @@ 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"]
|
6
|
+
prepend_before_filter :load_asset, :only => [ "show", "destroy", "update", "edit" ]
|
7
|
+
prepend_before_filter :load_assets, :only => [ "sort", "mass_delete", "mass_edit" ]
|
8
8
|
|
9
9
|
def show
|
10
10
|
if @asset.create_thumb_file(params[:style])
|
11
11
|
redirect_to @asset.url(params[:style])
|
12
12
|
else
|
13
|
-
render :nothing => true, :status =>
|
13
|
+
render :nothing => true, :status => 404
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def destroy
|
18
18
|
render :update do |page|
|
19
19
|
if @asset.destroy
|
20
|
-
page <<
|
20
|
+
page << %{ jQuery("#papermill_asset_#{params[:id]}").remove(); }
|
21
21
|
else
|
22
|
-
page <<
|
23
|
-
page << %{ notify("#{ escape_javascript t(
|
22
|
+
page << %{ jQuery("#papermill_asset_#{params[:id]}").show(); }
|
23
|
+
page << %{ notify("#{ escape_javascript t('papermill.not-deleted', :ressource => @asset.name) }", "error"); }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def update
|
29
29
|
render :update do |page|
|
30
|
-
@asset.update_attributes(params[:papermill_asset])
|
31
|
-
|
30
|
+
if @asset.update_attributes(params[:papermill_asset])
|
31
|
+
page << %{ notify("#{ escape_javascript t("papermill.updated", :ressource => @asset.name)}", "notice"); close_popup(self); }
|
32
|
+
else
|
33
|
+
page << %{ jQuery("#error").html("#{ escape_javascript @asset.errors.full_messages.join('<br>') }"); jQuery("#error").show(); }
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -38,8 +41,16 @@ class PapermillController < ApplicationController
|
|
38
41
|
|
39
42
|
def create
|
40
43
|
@asset = params[:asset_class].constantize.new(params.reject{|k, v| !(PapermillAsset.columns.map(&:name)+["Filedata", "Filename"]).include?(k)})
|
41
|
-
@asset.save
|
42
|
-
|
44
|
+
if @asset.save
|
45
|
+
PapermillAsset.find(:all, :conditions => { :assetable_id => @asset.assetable_id, :assetable_type => @asset.assetable_type, :assetable_key => @asset.assetable_key }).each do |asset|
|
46
|
+
asset.destroy unless asset == @asset
|
47
|
+
end if !!params[:gallery]
|
48
|
+
render :partial => "papermill/asset", :object => @asset, :locals => { :gallery => params[:gallery], :thumbnail_style => params[:thumbnail_style] }
|
49
|
+
else
|
50
|
+
render :update do |page|
|
51
|
+
page << %{ notify("#{ escape_javascript(@asset.errors.join('<br />')) }", "warning"); }
|
52
|
+
end
|
53
|
+
end
|
43
54
|
end
|
44
55
|
|
45
56
|
def sort
|
@@ -52,19 +63,24 @@ class PapermillController < ApplicationController
|
|
52
63
|
def mass_delete
|
53
64
|
render :update do |page|
|
54
65
|
@assets.each do |asset|
|
55
|
-
asset.destroy
|
56
|
-
page << "jQuery('#papermill_asset_#{asset.id}').remove()"
|
66
|
+
page << %{ jQuery("#papermill_asset_#{asset.id}").remove(); } if asset.destroy
|
57
67
|
end
|
58
68
|
end
|
59
69
|
end
|
60
70
|
|
61
71
|
def mass_edit
|
72
|
+
ok_messages = []
|
73
|
+
ko_messages = []
|
62
74
|
@assets.each do |asset|
|
63
|
-
asset.
|
64
|
-
|
75
|
+
if asset.update_attributes({params[:attribute] => params[:value]})
|
76
|
+
ok_messages << t("papermill.updated", :ressource => asset.name)
|
77
|
+
else
|
78
|
+
ko_messages << "#{asset.name} -> #{asset.errors.full_messages.to_sentence}"
|
79
|
+
end
|
65
80
|
end
|
66
81
|
render :update do |page|
|
67
|
-
page << %{ notify(
|
82
|
+
page << %{ notify("#{ escape_javascript ok_messages.join('\n') }", "notice"); } unless ok_messages.empty?
|
83
|
+
page << %{ notify("#{ escape_javascript ko_messages.join('\n') }", "error"); } unless ko_messages.empty?
|
68
84
|
end
|
69
85
|
end
|
70
86
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%- dom_id = "papermill_asset_#{asset.id}" -%>
|
2
2
|
<%- delete_link = %{<a onclick="if(confirm('#{escape_javascript t("papermill.delete-confirmation", :resource => asset.name)}')){ jQuery.ajax({async:true, beforeSend:function(request){jQuery('##{dom_id}').hide();}, dataType:'script', error:function(request){jQuery('##{dom_id}').show();}, type:'delete', url:'#{papermill_url(asset)}'})}; return false;" href="#" class="delete"><img title="#{escape_javascript t("papermill.delete", :ressource => asset.name)}" src="/papermill/images/delete.png" alt="delete"/></a>} %>
|
3
3
|
|
4
|
-
<div id="<%= dom_id %>" class="asset" title="<%= t("papermill.#{thumbnail_style ? "thumbnail-" : ""}edit-title", :ressource => asset.name) %>" onDblClick="popup(jQuery(this).attr('rel')); return false;" rel="<%= edit_papermill_url(asset) %>">
|
4
|
+
<div id="<%= dom_id %>" class="asset" title="<%= t("papermill.#{(thumbnail_style) ? "thumbnail-" : ""}edit-title", :ressource => asset.name) %>" onDblClick="popup(jQuery(this).attr('rel')); return false;" rel="<%= edit_papermill_url(asset) %>">
|
5
5
|
<%= delete_link %>
|
6
6
|
<%- if thumbnail_style -%>
|
7
7
|
<%= render :partial => "papermill/thumbnail_asset", :object => asset, :locals => {:thumbnail_style => thumbnail_style} %>
|
@@ -1,16 +1,23 @@
|
|
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 %>'}); return false;" method="post" class="edit_papermill_asset">
|
2
2
|
<input type="hidden" value="put" name="_method"/>
|
3
|
+
<div id="error" style="display:none;"></div>
|
3
4
|
<% fields_for :papermill_asset, @asset do |form| %>
|
4
|
-
<%
|
5
|
+
<% @asset.assetable_papermill_options[:editable_fields].each do |field| %>
|
6
|
+
<% key = field.keys.first %>
|
5
7
|
<p>
|
6
|
-
<%= form.label
|
7
|
-
<%
|
8
|
-
|
8
|
+
<%= form.label key, field[key][:label] || t("papermill.#{key}") %><br />
|
9
|
+
<% case field[key][:type]
|
10
|
+
when "text" %>
|
11
|
+
<%= form.text_area key %>
|
12
|
+
<% when "string" %>
|
13
|
+
<%= form.text_field key %>
|
14
|
+
<% when "boolean" -%>
|
15
|
+
<%= form.check_box key %>
|
9
16
|
<% else %>
|
10
|
-
<%= form.text_field
|
17
|
+
<%= form.text_field key %>
|
11
18
|
<% end -%>
|
12
19
|
</p>
|
13
20
|
<% end %>
|
14
|
-
<%= submit_tag t('papermill.save') %>
|
15
21
|
<% end %>
|
16
|
-
|
22
|
+
<%= submit_tag t('papermill.save') %>
|
23
|
+
</form>
|
@@ -8,10 +8,10 @@
|
|
8
8
|
<tr><td class="left-cell"><%= t("papermill.name") %> </td><td><%= @asset.name %></td></tr>
|
9
9
|
<tr><td class="left-cell"><%= t("papermill.content_type") %></td><td><%= @asset.content_type %></td></tr>
|
10
10
|
<tr><td class="left-cell"><%= t("papermill.size") %> </td><td><%= number_to_human_size(@asset.size.to_i) %></td></tr>
|
11
|
-
<% if @asset.image? %>
|
12
|
-
|
13
|
-
|
14
|
-
<% end %>
|
11
|
+
<% if @asset.image? %>
|
12
|
+
<tr><td class="left-cell"><%= t("papermill.width") %> </td><td><%= @asset.width.to_i %>px</td></tr>
|
13
|
+
<tr><td class="left-cell"><%= t("papermill.height") %> </td><td><%= @asset.height.to_i %>px</td></tr>
|
14
|
+
<% end %>
|
15
15
|
<tr><td class="left-cell"><%= t("papermill.created_at") %> </td><td><%= I18n.l(@asset.created_at) %></td></tr>
|
16
16
|
<tr><td class="left-cell"><%= t("papermill.updated_at") %> </td><td><%= I18n.l(@asset.updated_at) %></td></tr>
|
17
17
|
</table>
|
@@ -35,21 +35,13 @@ module ActionView::Helpers::FormTagHelper
|
|
35
35
|
|
36
36
|
private
|
37
37
|
def papermill_upload_tag(key, options)
|
38
|
-
if key.nil? &&
|
38
|
+
if key.nil? && options[:assetable]
|
39
39
|
key = options[:assetable]
|
40
40
|
options[:assetable] = nil
|
41
41
|
end
|
42
42
|
|
43
43
|
assetable = options[:assetable] || @template.instance_variable_get("@#{@object_name}")
|
44
|
-
options = (
|
45
|
-
if assetable && (association = (assetable.class.papermill_associations[key.to_sym] || assetable.class.papermill_associations[Papermill::options[:base_association_name]]))
|
46
|
-
association.deep_merge(options)
|
47
|
-
elsif assetable.nil?
|
48
|
-
Papermill::options.deep_merge(options)
|
49
|
-
else
|
50
|
-
raise PapermillException.new("Can't find '#{key.to_s}' association for '#{assetable.class.to_s}'.\n\n##{assetable.class.to_s.underscore}.rb\nYou can take on of these actions: \n1. set either a catchall papermill association: 'papermill {your_option_hash}'\n2. or a specific association: 'papermill :#{key.to_s}, {your_option_hash}'")
|
51
|
-
end
|
52
|
-
)
|
44
|
+
options = PapermillAsset.assetable_papermill_options(assetable.class.name, key)
|
53
45
|
|
54
46
|
assetable_id = assetable && (assetable.id || assetable.timestamp) || nil
|
55
47
|
assetable_type = assetable && assetable.class.base_class.name || nil
|
@@ -116,7 +108,7 @@ module ActionView::Helpers::FormTagHelper
|
|
116
108
|
|
117
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>}
|
118
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")}") {
|
119
|
-
@template.render :partial => "papermill/asset", :collection => collection, :locals => { :thumbnail_style =>
|
111
|
+
@template.render :partial => "papermill/asset", :collection => collection, :locals => { :thumbnail_style => options[:thumbnail] && options[:thumbnail][:style] }
|
120
112
|
}
|
121
113
|
|
122
114
|
if options[:gallery]
|
data/lib/papermill/papermill.rb
CHANGED
@@ -22,7 +22,7 @@ module Papermill
|
|
22
22
|
include Papermill::InstanceMethods
|
23
23
|
before_destroy :destroy_assets
|
24
24
|
after_create :rebase_assets
|
25
|
-
has_many :papermill_assets, :as => "Assetable"
|
25
|
+
has_many :papermill_assets, :as => "Assetable", :dependent => :destroy, :order => 'assetable_key ASC, position ASC'
|
26
26
|
|
27
27
|
define_method assoc_name do |*options|
|
28
28
|
scope = PapermillAsset.scoped(:conditions => {:assetable_id => self.id, :assetable_type => self.class.base_class.name})
|
@@ -56,11 +56,7 @@ module Papermill
|
|
56
56
|
|
57
57
|
def rebase_assets
|
58
58
|
PapermillAsset.all(:conditions => { :assetable_id => self.timestamp, :assetable_type => self.class.base_class.name }).each do |asset|
|
59
|
-
|
60
|
-
asset.destroy
|
61
|
-
else
|
62
|
-
asset.update_attribute(:assetable_id, self.id)
|
63
|
-
end
|
59
|
+
asset.created_at < 2.hours.ago ? asset.destroy : asset.update_attribute(:assetable_id, self.id)
|
64
60
|
end
|
65
61
|
end
|
66
62
|
end
|
@@ -12,7 +12,9 @@ class PapermillAsset < ActiveRecord::Base
|
|
12
12
|
validates_attachment_presence :file
|
13
13
|
|
14
14
|
belongs_to :assetable, :polymorphic => true
|
15
|
-
default_scope :order => 'position'
|
15
|
+
default_scope :order => 'assetable_key ASC, position ASC'
|
16
|
+
|
17
|
+
named_scope :key, lambda { |assetable_key| { :conditions => ['assetable_key = ?', assetable_key] }
|
16
18
|
|
17
19
|
def Filedata=(data)
|
18
20
|
data.content_type = data.get_content_type # SWFUpload content-type fix
|
@@ -68,23 +70,23 @@ class PapermillAsset < ActiveRecord::Base
|
|
68
70
|
file_content_type
|
69
71
|
end
|
70
72
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def save(*params)
|
76
|
-
if super(*params)
|
77
|
-
if params.last.is_a?(Hash) && params.last[:unique] && assetable_key
|
78
|
-
PapermillAsset.find(:all, :conditions => {:assetable_id => assetable_id, :assetable_type => assetable_type, :assetable_key => assetable_key }).each do |asset|
|
79
|
-
asset.destroy unless asset == self
|
80
|
-
end
|
81
|
-
end
|
82
|
-
true
|
73
|
+
def self.assetable_papermill_options(assetable_class, assetable_key)
|
74
|
+
if assetable_class
|
75
|
+
assoc = assetable_class.constantize.papermill_associations
|
76
|
+
assoc[assetable_key.try(:to_sym)] || assoc[Papermill::options[:base_association_name]]
|
83
77
|
else
|
84
|
-
|
78
|
+
Papermill::options
|
85
79
|
end
|
86
80
|
end
|
87
81
|
|
82
|
+
def assetable_papermill_options
|
83
|
+
self.class.assetable_papermill_options(assetable_type, assetable_key)
|
84
|
+
end
|
85
|
+
|
86
|
+
def image?
|
87
|
+
content_type.split("/")[0] == "image"
|
88
|
+
end
|
89
|
+
|
88
90
|
def self.cleanup
|
89
91
|
self.all(:conditions => ["id < 0 AND created_at < ?", DateTime.now.yesterday]).each &:destroy
|
90
92
|
end
|
@@ -105,7 +107,7 @@ class PapermillAsset < ActiveRecord::Base
|
|
105
107
|
FileUtils.rm_r(File.dirname(path).chomp("original")) rescue true
|
106
108
|
end
|
107
109
|
|
108
|
-
def self.compute_style(style
|
110
|
+
def self.compute_style(style)
|
109
111
|
style = Papermill::options[:aliases][style.to_sym] || Papermill::options[:aliases][style.to_s] || !Papermill::options[:alias_only] && style
|
110
112
|
[Symbol, String].include?(style.class) ? {:geometry => style.to_s} : style
|
111
113
|
end
|
@@ -48,6 +48,14 @@ module Papermill
|
|
48
48
|
|
49
49
|
# Attributes editable at once for all assets in a gallery
|
50
50
|
:mass_editable_fields => ["title", "copyright", "description"],
|
51
|
+
|
52
|
+
# Attributes you can edit in the form. You can use :type and :label
|
53
|
+
:editable_fields => [
|
54
|
+
{:title => {:type => "string"}},
|
55
|
+
{:alt => {:type => "string"}},
|
56
|
+
{:copyright => {:type => "string"}},
|
57
|
+
{:description => {:type => "text" }},
|
58
|
+
],
|
51
59
|
|
52
60
|
# FormHelper gallery options
|
53
61
|
# If :inline_css is true, css will be generated automatically and added through @content_for_papermill_inline_css (papermill_stylesheet_tag includes it)
|
@@ -9,6 +9,8 @@
|
|
9
9
|
#papermill-box #footer { text-align:center; font-size:10px; padding:5px }
|
10
10
|
#papermill-box #read-write { margin:10px 0 0 5px; }
|
11
11
|
|
12
|
+
#papermill-box #error { color:red; padding:10px; margin:10px; border:1px dashed green; background-color:#DDD; }
|
13
|
+
|
12
14
|
#papermill-box .right-cell {}
|
13
15
|
#papermill-box .left-cell {font-weight:bold; padding-right:10px; text-align:right;}
|
14
16
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
popup = function(url) {
|
2
|
-
window.open (url, "Papermill", config='height=
|
2
|
+
window.open (url, "Papermill", config='height=600, width=900, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
|
3
3
|
}
|
4
4
|
|
5
5
|
close_popup = function(source) {
|
@@ -43,7 +43,7 @@ close_popup = function(source) {
|
|
43
43
|
*/
|
44
44
|
|
45
45
|
notify = function(message, type) {
|
46
|
-
if(type != "notice") { alert(
|
46
|
+
if(type != "notice") { alert(message) }
|
47
47
|
}
|
48
48
|
|
49
49
|
/*
|
@@ -57,6 +57,8 @@ notify = function(message, type) {
|
|
57
57
|
if(type == "error") { jQuery.noticeAdd({ text: message, stayTime: 20000, stay: false, type: type }) }
|
58
58
|
}
|
59
59
|
|
60
|
+
Or you can just update div's in your application (like dynamic rails flash)
|
61
|
+
|
60
62
|
*/
|
61
63
|
|
62
64
|
var Upload = {
|
@@ -108,27 +110,18 @@ var Upload = {
|
|
108
110
|
jQuery('#' + file.id + ' .progress span').width(percent + '%');
|
109
111
|
},
|
110
112
|
upload_error: function(file, errorCode, message) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
default:
|
117
|
-
notify("An error occurred while sending the file" + errorCode, "error");
|
118
|
-
return;
|
119
|
-
}
|
120
|
-
} catch (ex) {
|
113
|
+
switch (errorCode) {
|
114
|
+
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
|
115
|
+
notify("Too many files selected", "error"); break;
|
116
|
+
default:
|
117
|
+
notify("An error occurred while sending the file", "error");
|
121
118
|
}
|
119
|
+
jQuery("#"+file.id).remove();
|
122
120
|
},
|
123
121
|
|
124
122
|
upload_success: function(file, data)
|
125
123
|
{
|
126
|
-
|
127
|
-
notify(data, "warning");
|
128
|
-
jQuery('#' + file.id).remove();
|
129
|
-
} else {
|
130
|
-
jQuery('#' + file.id).replaceWith(jQuery(data));
|
131
|
-
}
|
124
|
+
jQuery('#' + file.id).replaceWith(jQuery(data));
|
132
125
|
},
|
133
126
|
upload_complete: function(file)
|
134
127
|
{
|
@@ -139,26 +132,19 @@ var Upload = {
|
|
139
132
|
},
|
140
133
|
|
141
134
|
file_queue_error: function(file, errorCode, message) {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
|
154
|
-
notify("File is not an allowed file type", "error");
|
155
|
-
return;
|
156
|
-
default:
|
157
|
-
notify("An error occurred while sending the file" + errorCode, "error");
|
158
|
-
return;
|
159
|
-
}
|
160
|
-
} catch (e) {
|
135
|
+
switch (errorCode) {
|
136
|
+
case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
|
137
|
+
notify("Too many files selected", "error"); break;
|
138
|
+
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
|
139
|
+
notify("File is too big", "error"); break;
|
140
|
+
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
|
141
|
+
notify("File is empty. Please select another file", "error"); break;
|
142
|
+
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
|
143
|
+
notify("File is not an allowed file type", "error"); break;
|
144
|
+
default:
|
145
|
+
notify("An error occurred while sending the file", "error");
|
161
146
|
}
|
147
|
+
jQuery("#"+file.id).remove();
|
162
148
|
}
|
163
149
|
}
|
164
150
|
|
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.0.
|
4
|
+
version: 1.0.5
|
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-19 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- generators/papermill_table/templates/migrate/papermill_migration.rb.erb
|
55
55
|
- init.rb
|
56
56
|
- install.rb
|
57
|
-
- installation-template.txt
|
58
57
|
- lib/extensions.rb
|
59
58
|
- lib/papermill.rb
|
60
59
|
- lib/papermill/form_builder.rb
|
data/installation-template.txt
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
gem 'papermill'
|
2
|
-
|
3
|
-
generate :papermill_table, "PapermillMigration"
|
4
|
-
generate :papermill_assets
|
5
|
-
generate :papermill_initializer
|
6
|
-
generate :scaffold, "article title:string"
|
7
|
-
rake "db:migrate"
|
8
|
-
|
9
|
-
file "app/models/article.rb", <<-END
|
10
|
-
class Article < ActiveRecord::Base
|
11
|
-
validates_presence_of :title
|
12
|
-
papermill :thumbnail => {:width => 100, :height => 75} # catch-all for non-specified associations, will create assets/asset methods.
|
13
|
-
papermill :image_gallery, :class_name => ImageAsset, :images_only => true, :thumbnail => {:width => 75, :height => 100}
|
14
|
-
# image_gallery association (set with define_method)
|
15
|
-
end
|
16
|
-
END
|
17
|
-
|
18
|
-
file "app/models/image_asset.rb", <<-END
|
19
|
-
class ImageAsset < PapermillAsset
|
20
|
-
validates_attachment_content_type :file, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/gif']
|
21
|
-
end
|
22
|
-
END
|
23
|
-
|
24
|
-
file "app/views/articles/edit.html.erb", <<-END
|
25
|
-
<h1>Editing article</h1>
|
26
|
-
<%= render :partial => "form" %>
|
27
|
-
<%= link_to 'Show', @article %> |
|
28
|
-
<%= link_to 'Back', articles_path %>
|
29
|
-
END
|
30
|
-
|
31
|
-
file "app/views/articles/new.html.erb", <<-END
|
32
|
-
<h1>New article</h1>
|
33
|
-
<%= render :partial => "form" %>
|
34
|
-
<%= link_to 'Back', articles_path %>
|
35
|
-
END
|
36
|
-
|
37
|
-
file "app/views/articles/_form.html.erb", <<-END
|
38
|
-
<% form_for(@article) do |f| %>
|
39
|
-
<%= f.error_messages %><br /><br />
|
40
|
-
<%= f.label :title %><br />
|
41
|
-
<%= f.text_field :title %><br /><br />
|
42
|
-
<%= f.label :image_gallery %><br />
|
43
|
-
<%= f.images_upload(:image_gallery) %><br /><br />
|
44
|
-
<%= f.label :my_other_image %><br />
|
45
|
-
<%= f.image_upload(:my_other_image) %> <br /><br />
|
46
|
-
<%= f.label :my_assets %><br />
|
47
|
-
<%= f.assets_upload(:my_assets) %><br /><br />
|
48
|
-
<%= f.label :my_other_asset %><br />
|
49
|
-
<%= f.asset_upload(:my_other_asset) %><br /><br />
|
50
|
-
<%= f.submit 'Send' %>
|
51
|
-
<% end %>
|
52
|
-
END
|
53
|
-
|
54
|
-
file "app/views/articles/show.html.erb", <<-END
|
55
|
-
<p>
|
56
|
-
<b>Title:</b>
|
57
|
-
<%=h @article.title %>
|
58
|
-
</p>
|
59
|
-
<br /><br />
|
60
|
-
<b>@article.image_gallery.each :</b>
|
61
|
-
<p>
|
62
|
-
<% @article.image_gallery.each do |image| %>
|
63
|
-
<%= link_to(image_tag(image.url("100x100#")), image.url) %>
|
64
|
-
<% end %>
|
65
|
-
</p>
|
66
|
-
<br /><br />
|
67
|
-
<b>@article.assets(:my_other_image).first :</b>
|
68
|
-
<p>
|
69
|
-
<% image = @article.assets(:my_other_image).first %>
|
70
|
-
<%= link_to(image_tag(image.url("100x100#")), image.url) if image %>
|
71
|
-
</p>
|
72
|
-
<br /><br />
|
73
|
-
<b>@article.assets(:my_assets).each :</b>
|
74
|
-
<p>
|
75
|
-
<ul>
|
76
|
-
<% @article.assets(:my_assets).each do |asset| %>
|
77
|
-
<li><%= link_to asset.name, asset.url %></li>
|
78
|
-
<% end %>
|
79
|
-
</ul>
|
80
|
-
</p>
|
81
|
-
<br /><br />
|
82
|
-
<b>@article.assets(:my_other_asset).first :</b>
|
83
|
-
<p>
|
84
|
-
<% asset = @article.assets(:my_other_asset).first %>
|
85
|
-
<%= link_to(asset.name, asset.url) if asset %>
|
86
|
-
</p>
|
87
|
-
|
88
|
-
<%= link_to 'Edit', edit_article_path(@article) %> |
|
89
|
-
<%= link_to 'Back', articles_path %>
|
90
|
-
END
|
91
|
-
|
92
|
-
|
93
|
-
file "app/views/layouts/application.html.erb", <<-END
|
94
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
95
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
96
|
-
|
97
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
98
|
-
<head>
|
99
|
-
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
100
|
-
<title>Papermill Demo</title>
|
101
|
-
<%= stylesheet_link_tag 'scaffold' %>
|
102
|
-
<%= papermill_stylesheet_tag %>
|
103
|
-
</head>
|
104
|
-
<body>
|
105
|
-
<%= yield %>
|
106
|
-
<%= papermill_javascript_tag :with_jquery => true %>
|
107
|
-
</body>
|
108
|
-
</html>
|
109
|
-
END
|
110
|
-
|
111
|
-
run "rm app/views/layouts/articles.html.erb"
|
112
|
-
run "rm public/index.html"
|
113
|
-
route "map.root :controller => 'articles'"
|