papermill 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -3
- data/Rakefile +2 -0
- data/TODO.txt +3 -2
- data/VERSION +1 -1
- data/app/controllers/papermill_controller.rb +3 -4
- data/app/views/papermill/_form.html.erb +1 -1
- data/app/views/papermill/crop.html.erb +46 -12
- data/lib/papermill.rb +8 -2
- data/lib/papermill/extensions.rb +0 -10
- data/lib/papermill/papermill.rb +2 -0
- data/lib/papermill/papermill_asset.rb +16 -5
- data/lib/papermill/papermill_initializer.rb +4 -4
- data/lib/papermill/papermill_options.rb +2 -2
- data/lib/papermill/papermill_paperclip_processor.rb +2 -0
- data/test/papermill_test.rb +0 -1
- metadata +12 -2
data/README.rdoc
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
= Papermill
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
* Asset management made easy, 10 minutes integration.
|
6
4
|
* All-you-can-eat glue around Polymorphic Paperclip table, SWFUpload & JQuery.
|
7
5
|
* Associate any image or list of images with any model and any key.
|
@@ -165,6 +163,8 @@ Copy static assets to your public directory:
|
|
165
163
|
|
166
164
|
Create the option file config/initializers/papermill.rb
|
167
165
|
./script/generate papermill_initializer
|
166
|
+
|
167
|
+
Go have a look to config/initializers/papermill.rb, lots of info there.
|
168
168
|
|
169
169
|
=== environment.rb:
|
170
170
|
|
@@ -172,7 +172,6 @@ Create the option file config/initializers/papermill.rb
|
|
172
172
|
Rails::Initializer.run do |config|
|
173
173
|
...
|
174
174
|
config.gem papermill
|
175
|
-
config.gem "mime-types", :lib => "mime/types" # required for windows OS
|
176
175
|
end
|
177
176
|
|
178
177
|
=== In your layout:
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'rake'
|
2
3
|
require 'rake/testtask'
|
3
4
|
require 'rake/rdoctask'
|
@@ -32,6 +33,7 @@ begin
|
|
32
33
|
gemspec.homepage = "http://github.com/bbenezech/papermill"
|
33
34
|
gemspec.authors = ["Benoit Bénézech"]
|
34
35
|
gemspec.add_dependency('paperclip', '>= 2.3.1.1')
|
36
|
+
gemspec.add_dependency('mime-types')
|
35
37
|
end
|
36
38
|
rescue LoadError
|
37
39
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/TODO.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
@@ -3,6 +3,8 @@ class PapermillController < ApplicationController
|
|
3
3
|
prepend_before_filter :load_assets, :only => [ "sort", "mass_delete", "mass_edit", "mass_thumbnail_reset" ]
|
4
4
|
|
5
5
|
def show
|
6
|
+
# first escaping is done by rails prior to route recognition, need to do a second one on MSWIN systems to get original one.
|
7
|
+
params[:style] = CGI::unescape(params[:style]) if RUBY_PLATFORM =~ /win/
|
6
8
|
if @asset.has_valid_url_key?(params[:url_key], params[:style]) && @asset.create_thumb_file(params[:style])
|
7
9
|
redirect_to @asset.url(params[:style])
|
8
10
|
else
|
@@ -29,10 +31,7 @@ class PapermillController < ApplicationController
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def update
|
32
|
-
if params[:target]
|
33
|
-
@asset.create_thumb_file(params[:target], params[:papermill_asset].merge({ :geometry => "original#" }))
|
34
|
-
end
|
35
|
-
|
34
|
+
@asset.create_thumb_file(params[:target], params[:papermill_asset].merge({ :geometry => "#{params[:target]}#" })) if params[:target]
|
36
35
|
render :update do |page|
|
37
36
|
if @asset.update_attributes(params[:papermill_asset])
|
38
37
|
page << %{ notify("#{@asset.name}", "#{ escape_javascript t("papermill.updated", :resource => @asset.name)}", "notice"); close_popup(self); }
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<% @asset.papermill_options[:editable_fields].each do |field| %>
|
6
6
|
<% key = field.keys.first %>
|
7
7
|
<p>
|
8
|
-
<%= form.label
|
8
|
+
<%= form.label(key, (field[key][:label] || t("papermill.#{key}")).to_s) %><br />
|
9
9
|
<% case field[key][:type]
|
10
10
|
when "text" %>
|
11
11
|
<%= form.text_area key %>
|
@@ -1,18 +1,44 @@
|
|
1
1
|
<%= image_tag(@asset.url, :id => "cropbox") %>
|
2
2
|
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
<style type="text/css">
|
4
|
+
.jc_coords form {
|
5
|
+
-moz-background-clip:border;
|
6
|
+
-moz-background-inline-policy:continuous;
|
7
|
+
-moz-background-origin:padding;
|
8
|
+
background:#CCCCCC none repeat scroll 0 0;
|
9
|
+
border-color:#C3C3C3 #8B8B8B #8B8B8B #C3C3C3;
|
10
|
+
border-style:solid;
|
11
|
+
border-width:1px;
|
12
|
+
margin:0.5em 0;
|
13
|
+
padding:0.5em;
|
14
|
+
}
|
15
|
+
.jc_coords label {
|
16
|
+
font-size:12px;
|
17
|
+
font-weight:bold;
|
18
|
+
margin-right:0.5em;
|
19
|
+
}
|
20
|
+
.jc_coords .submit, .jc_coords a {
|
21
|
+
margin-right: 0.5em;
|
22
|
+
}
|
23
|
+
</style>
|
24
|
+
|
25
|
+
<div class="jc_coords">
|
26
|
+
<form onsubmit="jQuery.ajax({data:jQuery.param(jQuery(this).serializeArray()), dataType:'script', type:'post', url:'/papermill/<%= @asset.id %>'}); return false;" method="post">
|
27
|
+
<input type="hidden" value="put" name="_method"/>
|
28
|
+
<input type="hidden" value="<%= params[:target] %>" name="target"/>
|
29
|
+
<% fields_for :papermill_asset, @asset do |f| %>
|
30
|
+
<label>W <%= f.text_field :crop_w, :id => :crop_w, :size => 4, :readonly => "readonly" %></label>
|
31
|
+
<label>H <%= f.text_field :crop_h, :id => :crop_h, :size => 4, :readonly => "readonly" %></label>
|
32
|
+
<%= f.hidden_field :crop_x, :id => :crop_x %>
|
33
|
+
<%= f.hidden_field :crop_y, :id => :crop_y %>
|
34
|
+
<%= f.submit I18n.t('papermill.save'), :class => "submit" %>
|
35
|
+
<%= link_to_function I18n.t("papermill.back"), "popup('#{edit_papermill_path(@asset)}')" %>
|
36
|
+
<% end -%>
|
37
|
+
</form>
|
38
|
+
</div>
|
13
39
|
|
14
40
|
<div style="margin:6px"></div>
|
15
|
-
|
41
|
+
|
16
42
|
|
17
43
|
<script type="text/javascript" charset="utf-8">
|
18
44
|
jQuery(function() {
|
@@ -29,5 +55,13 @@
|
|
29
55
|
jQuery("#crop_y").val(coords.y);
|
30
56
|
jQuery("#crop_w").val(coords.w);
|
31
57
|
jQuery("#crop_h").val(coords.h);
|
32
|
-
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
/* browser don't know about windows content size when loading facebox if image not in cache, fixing facebox left */
|
62
|
+
jQuery(document).bind('reveal.facebox', function() {
|
63
|
+
jQuery(document).unbind('reveal.facebox'); /* clear self (one-shot binding) */
|
64
|
+
jQuery('#facebox').css('left', jQuery(window).width() / 2 - (<%= @asset.width %> / 2));
|
65
|
+
});
|
66
|
+
|
33
67
|
</script>
|
data/lib/papermill.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
1
|
+
require "rbconfig"
|
2
|
+
begin
|
3
|
+
require "mime/types"
|
4
|
+
MIME_TYPE_LOADED = true
|
5
|
+
rescue
|
6
|
+
MIME_TYPE_LOADED = false
|
7
|
+
end
|
8
|
+
|
2
9
|
I18n.load_path = [File.join(File.dirname(__FILE__), "../config/locales/papermill.yml")] + I18n.load_path
|
3
10
|
require 'papermill/extensions'
|
4
11
|
require 'papermill/flash_session_cookie_middleware.rb'
|
5
12
|
|
6
13
|
Object.send :include, PapermillObjectExtensions
|
7
14
|
Hash.send :include, PapermillHashExtensions
|
8
|
-
File.send :include, PapermillFileExtensions
|
9
15
|
String.send :include, StringToUrlNotFound unless String.instance_methods.include? "to_url"
|
10
16
|
Formtastic::SemanticFormBuilder.send(:include, PapermillFormtasticExtensions) rescue NameError
|
11
17
|
|
data/lib/papermill/extensions.rb
CHANGED
@@ -21,16 +21,6 @@ module PapermillObjectExtensions
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
module PapermillFileExtensions
|
25
|
-
def get_content_type
|
26
|
-
begin
|
27
|
-
MIME::Types.type_for(self.original_filename).to_s
|
28
|
-
rescue NameError
|
29
|
-
`file --mime -br #{self.path}`.strip.split(";").first
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
24
|
module PapermillFormtasticExtensions
|
35
25
|
def image_upload_input(method, options)
|
36
26
|
self.label(method, options_for_label(options)) +
|
data/lib/papermill/papermill.rb
CHANGED
@@ -8,6 +8,8 @@ module Papermill
|
|
8
8
|
@options ||= BASE_OPTIONS.deep_merge(defined?(OPTIONS) ? OPTIONS : {})
|
9
9
|
end
|
10
10
|
|
11
|
+
MSWIN = (Config::CONFIG['host_os'] =~ /mswin|mingw/)
|
12
|
+
|
11
13
|
def self.compute_paperclip_path
|
12
14
|
path = []
|
13
15
|
path << (options[:use_id_partition] ? ":id_partition" : ":id")
|
@@ -5,8 +5,8 @@ class PapermillAsset < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
has_attached_file :file,
|
7
7
|
:processors => [:papermill_paperclip_processor],
|
8
|
-
:url => "
|
9
|
-
:path => "#{Papermill::options[:
|
8
|
+
:url => "#{Papermill::options[:papermill_url_prefix]}/#{Papermill::compute_paperclip_path.gsub(':style', ':escape_style_in_url')}",
|
9
|
+
:path => "#{Papermill::options[:papermill_path_prefix]}/#{Papermill::compute_paperclip_path.gsub(':style', ':escape_style_in_path')}"
|
10
10
|
|
11
11
|
before_post_process :set_file_name
|
12
12
|
|
@@ -21,14 +21,25 @@ class PapermillAsset < ActiveRecord::Base
|
|
21
21
|
attachment.instance.compute_url_key((style || "original").to_s)
|
22
22
|
end
|
23
23
|
|
24
|
-
Paperclip.interpolates :
|
25
|
-
|
24
|
+
Paperclip.interpolates :escape_style_in_url do |attachment, style|
|
25
|
+
# double escaping needed for windows (complains about '< > " | / \' ), to match escaped filesystem from front webserver pov
|
26
|
+
s = (style || "original").to_s
|
27
|
+
Papermill::MSWIN ? CGI::escape(CGI::escape(s)) : CGI::escape(s)
|
26
28
|
end
|
27
29
|
|
30
|
+
Paperclip.interpolates :escape_style_in_path do |attachment, style|
|
31
|
+
s = (style || "original").to_s
|
32
|
+
Papermill::MSWIN ? CGI::escape(s) : s
|
33
|
+
end
|
34
|
+
|
28
35
|
attr_accessor :crop_h, :crop_w, :crop_x, :crop_y
|
29
36
|
|
30
37
|
def Filedata=(data)
|
31
|
-
|
38
|
+
if !Papermill::MSWIN && !(mime = `file --mime -br #{File.new(data).path}`).blank? && !mime.starts_with?("cannot open")
|
39
|
+
data.content_type = mime.strip.split(";").first
|
40
|
+
elsif MIME_TYPE_LOADED && (mime = MIME::Types.type_for(data.original_filename))
|
41
|
+
data.content_type = mime.first.simplified
|
42
|
+
end
|
32
43
|
self.file = data
|
33
44
|
end
|
34
45
|
|
@@ -32,8 +32,8 @@ module Papermill
|
|
32
32
|
# :form_helper_elements => [:upload_button, :container, :dashboard],
|
33
33
|
|
34
34
|
# Dashboard elements
|
35
|
-
# You can remove/change order of HTML elements.
|
36
|
-
# :dashboard => [:mass_edit, :
|
35
|
+
# You can remove/change order of HTML elements. You can add :mass_thumbnail_reset to add a link to reset all thumbnails, although you shouldn't need it.
|
36
|
+
# :dashboard => [:mass_edit, :mass_delete ],
|
37
37
|
|
38
38
|
# Attributes editable at once for all assets in a gallery
|
39
39
|
# :mass_editable_fields => ["title", "copyright", "description"],
|
@@ -170,9 +170,9 @@ module Papermill
|
|
170
170
|
# :url_key_salt => "change-me-to-your-favorite-pet-name",
|
171
171
|
# :url_key_generator => Proc.new { |style, asset| Digest::SHA512.hexdigest("#{style}#{asset.id}#{Papermill::options[:url_key_salt]}")[0..10] },
|
172
172
|
|
173
|
-
# added
|
174
|
-
# :papermill_url_prefix => "system/papermill",
|
173
|
+
# added before path/url. Your front webserver will need to be able to find your assets
|
175
174
|
# :papermill_path_prefix => ":rails_root/public/system/papermill",
|
175
|
+
# :papermill_url_prefix => "/system/papermill",
|
176
176
|
|
177
177
|
# you can set it to false if you don't plan to have too many assets. (dangerous)
|
178
178
|
# :use_id_partition => true,
|
@@ -4,7 +4,7 @@ module Papermill
|
|
4
4
|
:inline_css => true,
|
5
5
|
:images_only => false,
|
6
6
|
:form_helper_elements => [:upload_button, :container, :dashboard],
|
7
|
-
:dashboard => [:mass_edit, :
|
7
|
+
:dashboard => [:mass_edit, :mass_delete],
|
8
8
|
:mass_editable_fields => ["title", "copyright", "description"],
|
9
9
|
:editable_fields => [
|
10
10
|
{:title => {:type => "string"}},
|
@@ -54,7 +54,7 @@ module Papermill
|
|
54
54
|
:url_key_salt => "change-me-please",
|
55
55
|
:url_key_generator => Proc.new { |style, asset| Digest::SHA512.hexdigest("#{style}#{asset.id}#{Papermill::options[:url_key_salt]}")[0..10] },
|
56
56
|
:use_id_partition => true,
|
57
|
-
:papermill_url_prefix => "system/papermill",
|
57
|
+
:papermill_url_prefix => "/system/papermill",
|
58
58
|
:papermill_path_prefix => ":rails_root/public/system/papermill",
|
59
59
|
}
|
60
60
|
end
|
data/test/papermill_test.rb
CHANGED
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.
|
4
|
+
version: 1.3.0
|
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-12-
|
12
|
+
date: 2009-12-15 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 2.3.1.1
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mime-types
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
25
35
|
description: Paperclip Swfupload UploadHelper wrapper
|
26
36
|
email: benoit.benezech@gmail.com
|
27
37
|
executables: []
|