papermill 0.12.2 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  log/*.log
3
3
  tmp/**/*
4
4
  config/database.yml
5
- db/*.sqlite3
5
+ db/*.sqlite3
6
+ papermill.gemspec
@@ -58,7 +58,7 @@ See papermill_module.rb for the complete list of options.
58
58
  ...
59
59
  config.gem papermill
60
60
 
61
- # You can set options that will be set application-wide :
61
+ # You can set application-wide options inside or before Rails::Initializer :
62
62
  module Papermill
63
63
  OPTIONS = {
64
64
  :thumbnail => {
@@ -78,6 +78,9 @@ See papermill_module.rb for the complete list of options.
78
78
  # You can use stringex's String#to_url (papermill will use its own String#to_url if none exists)
79
79
  config.gem 'stringex'
80
80
  ...
81
+ # You can use Mime-Type to get the correct mime type from upload - flash garbles it.. (default is a UNIX call to "file --mime")
82
+ # needed for Windows OS
83
+ config.gem "mime-types", :lib => "mime/types"
81
84
  end
82
85
 
83
86
  === In your assetable model:
@@ -116,7 +119,7 @@ See papermill_module.rb for the complete list of options.
116
119
  @assetable.assets(:my_other_asset).first.try(:url)
117
120
 
118
121
  Also see http://github.com/bbenezech/papermill/raw/master/installation-template.txt
119
- Have a look at the API here http://rdoc.info/projects/BBenezech/papermill
122
+ Have a look at the API here http://rdoc.info/projects/bbenezech/papermill
120
123
 
121
124
  === Translations:
122
125
 
@@ -126,8 +129,7 @@ Copy config/locales/papermill.yml to your root config/locale folder to modify an
126
129
 
127
130
  == Word of caution:
128
131
 
129
- Beta. Wait for gem 1.0.0 for the production ready thing.
130
- This is xNIX only (system("rm ...")).
132
+ Beta. Wait for gem 1.0.0 for the production ready thing. But since gem 0.12.2, things should go smoothly.
131
133
  Rails 2.3
132
134
 
133
135
 
data/Rakefile CHANGED
@@ -32,8 +32,6 @@ begin
32
32
  gemspec.homepage = "http://github.com/bbenezech/papermill"
33
33
  gemspec.authors = ["Benoit Bénézech"]
34
34
  gemspec.add_dependency('thoughtbot-paperclip', '>= 2.3.1')
35
- gemspec.add_dependency('mime-types', '>= 1.16')
36
- gemspec.add_dependency('acts_as_list', '>= 0.1.2')
37
35
  end
38
36
  rescue LoadError
39
37
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/TODO.txt CHANGED
@@ -1,7 +1,6 @@
1
1
  * non-regression tests
2
- * use aliases in form helpers
3
- * doc&test about crop
4
- * better CSS for edit
5
- * reorganize edit with forms
2
+ Edit views :
3
+ * better CSS
4
+ * use forms
6
5
  * use Jcrop
7
- * use Picnic API
6
+ * try Picnic API
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.2
1
+ 0.13.0
@@ -1,24 +1,25 @@
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 failed to disable verify_authenticity_token automatically.
4
+ skip_before_filter :verify_authenticity_token, :only => [:create]
2
5
 
3
- skip_before_filter :verify_authenticity_token
4
-
5
6
  def show
6
- complete_id = (params[:id0] + params[:id1] + params[:id2]).to_i
7
- asset = PapermillAsset.find(complete_id)
8
- raise if asset.nil? || params[:style] == "original"
9
- style = Papermill::PAPERMILL_DEFAULTS[:aliases][params[:style]] || !Papermill::PAPERMILL_DEFAULTS[:alias_only] && params[:style]
10
- raise unless style
11
- style = {:geometry => style} unless style.is_a? Hash # new Paperclip API
12
-
13
- if asset.image?
14
- temp_thumbnail = Paperclip::Thumbnail.make(asset_file = asset.file, style)
15
- new_parent_folder_path = File.dirname(new_image_path = asset_file.path(params[:style]))
16
- FileUtils.mkdir_p new_parent_folder_path unless File.exists? new_parent_folder_path
17
- FileUtils.cp temp_thumbnail.path, new_image_path
18
- redirect_to asset.url(params[:style])
19
- else
20
- redirect_to asset.url
21
- end
7
+ complete_id = (params[:id0] + params[:id1] + params[:id2]).to_i
8
+ asset = PapermillAsset.find(complete_id)
9
+ raise if asset.nil? || params[:style] == "original"
10
+ style = Papermill::PAPERMILL_DEFAULTS[:aliases][params[:style]] || !Papermill::PAPERMILL_DEFAULTS[:alias_only] && params[:style]
11
+ raise unless style
12
+ style = {:geometry => style} unless style.is_a? Hash # new Paperclip API
13
+
14
+ if asset.image?
15
+ temp_thumbnail = Paperclip::Thumbnail.make(asset_file = asset.file, style)
16
+ new_parent_folder_path = File.dirname(new_image_path = asset_file.path(params[:style]))
17
+ FileUtils.mkdir_p new_parent_folder_path unless File.exists? new_parent_folder_path
18
+ FileUtils.cp temp_thumbnail.path, new_image_path
19
+ redirect_to asset.url(params[:style])
20
+ else
21
+ redirect_to asset.url
22
+ end
22
23
  end
23
24
 
24
25
  def destroy
@@ -58,6 +59,7 @@ class PapermillController < ApplicationController
58
59
  @old_asset = asset_class.find(:first, :conditions => params.reject{|k, v| !["assetable_key", "assetable_type", "assetable_id"].include?(k)})
59
60
  end
60
61
  @asset = asset_class.new(params.reject{|k, v| !(PapermillAsset.columns.map(&:name)+["swfupload_file"]).include?(k)})
62
+ @asset.position = asset_class.find(:first, :conditions => params.reject{|k, v| !["assetable_key", "assetable_type", "assetable_id"].include?(k)}, :order => "position DESC" ).try(:position).to_i + 1
61
63
 
62
64
  if @asset.save
63
65
  @old_asset.destroy if @old_asset
@@ -1,7 +1,7 @@
1
1
  <%- dom_id = "papermill_asset_#{asset.id}" -%>
2
2
  <%- delete_link = %{<a onclick="if(confirm('#{escape_javascript I18n.t("delete-confirmation", :scope => :papermill, :resource => asset.name)}')){ $.ajax({async:true, beforeSend:function(request){$('##{dom_id}').hide();}, dataType:'script', error:function(request){$('##{dom_id}').show();}, type:'delete', url:'#{papermill_url(asset)}'})}; return false;" href="#" class="delete"><img title="#{escape_javascript t("delete", :scope => "papermill", :ressource => asset.name)}" src="/papermill/images/delete.png" alt="delete"/></a>} %>
3
3
 
4
- <li id="<%= dom_id %>" onDblClick="popup(jQuery(this).attr('rel')); return false;" rel="<%= edit_papermill_url(asset) %>" title="<%= t("#{thumbnail_style ? "thumbnail-" : ""}edit-title", :scope => "papermill", :ressource => asset.name) %>">
4
+ <li id="<%= dom_id %>" title="<%= t("#{thumbnail_style ? "thumbnail-" : ""}edit-title", :scope => "papermill", :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 +1 @@
1
- <%= link_to(raw_asset.name, edit_papermill_url(raw_asset), :class => "name") -%>
1
+ <%= link_to(raw_asset.name, edit_papermill_url(raw_asset), :class => "name", :onClick => "popup(jQuery(this).attr('rel')); return false;", :rel => edit_papermill_url(raw_asset)) -%>
@@ -3,4 +3,4 @@
3
3
  <% else %>
4
4
  <span class="name" title="<%= thumbnail_asset.name %>"><%= truncate(thumbnail_asset.name, :length => 15) %></span>
5
5
  <span class="infos"><%= thumbnail_asset.content_type.join('/') %></span>
6
- <% end %>
6
+ <% end %>
@@ -4,8 +4,8 @@ en:
4
4
  updated: "'{{ressource}}' updated"
5
5
  not-deleted: "'{{ressource}}' could not be deleted"
6
6
  not-found: "Asset #{{ressource}} not found"
7
- edit-title: "Double-click to edit '{{ressource}}'"
8
- thumbnail-edit-title: "Click to edit '{{ressource}}'"
7
+ edit-title: "Click to edit '{{ressource}}'"
8
+ thumbnail-edit-title: "Double-click to edit '{{ressource}}'"
9
9
  upload-button-wording: "Upload..."
10
10
  delete: "Remove {{ressource}}"
11
11
  delete-confirmation: "Delete '{{resource}}'?"
@@ -35,8 +35,8 @@ fr:
35
35
  updated: "{{ressource}} mis(e) à jour"
36
36
  not-deleted: "{{ressource}} n'a pas pu être supprimée"
37
37
  not-found: "Asset #{{ressource}} non trouvé"
38
- edit-title: "Double-cliquer pour éditer '{{ressource}}'"
39
- thumbnail-edit-title: "Cliquer pour éditer '{{ressource}}'"
38
+ edit-title: "Cliquer pour éditer '{{ressource}}'"
39
+ thumbnail-edit-title: "Double-cliquer pour éditer '{{ressource}}'"
40
40
  upload-button-wording: "Charger.."
41
41
  delete: "Supprimer {{ressource}}"
42
42
  delete-confirmation: "Êtes-vous sûr de vouloir supprimer '{{resource}}' ?"
@@ -1,6 +1,6 @@
1
1
  class PapermillException < Exception; end
2
2
 
3
- module HashExtensions
3
+ module PapermillHashExtensions
4
4
  def deep_merge(hash)
5
5
  target = dup
6
6
  hash.keys.each do |key|
@@ -13,19 +13,29 @@ module HashExtensions
13
13
  target
14
14
  end
15
15
  end
16
- module StringExtensions
16
+ module PapermillStringExtensions
17
17
  def simple_sql_sanitizer
18
18
  gsub(/\\/, '\&\&').gsub(/'/, "''")
19
19
  end
20
20
  end
21
- module StringToUrlNotFound
21
+ module PapermillStringToUrlNotFound
22
22
  def to_url
23
23
  gsub(/[^a-zA-Z0-9]/, "-").gsub(/-+/, "-").gsub(/^-|-$/, "").downcase
24
24
  end
25
25
  end
26
- module ObjectExtensions
26
+ module PapermillObjectExtensions
27
27
  # Nil if empty.
28
28
  def nie
29
29
  self.blank? ? nil : self
30
30
  end
31
31
  end
32
+ module PapermillFileExtensions
33
+
34
+ def get_content_type
35
+ begin
36
+ MIME::Types.type_for(self.original_filename).to_s
37
+ rescue NameError
38
+ `file --mime -br #{self.path}`.strip.split(";").first
39
+ end
40
+ end
41
+ end
@@ -1,9 +1,10 @@
1
1
  I18n.load_path = [File.join(File.dirname(__FILE__), "../config/locales/papermill.yml")] + I18n.load_path
2
2
  require 'core_extensions'
3
- Object.send :include, ObjectExtensions
4
- Hash.send :include, HashExtensions
5
- String.send :include, StringExtensions
6
- String.send :include, StringToUrlNotFound unless String.instance_methods.include? "to_url"
3
+ Object.send :include, PapermillObjectExtensions
4
+ Hash.send :include, PapermillHashExtensions
5
+ File.send :include, PapermillFileExtensions
6
+ String.send :include, PapermillStringExtensions
7
+ String.send :include, PapermillStringToUrlNotFound unless String.instance_methods.include? "to_url"
7
8
  require 'papermill/papermill_module'
8
9
  require 'papermill/papermill_asset'
9
10
  require 'papermill/form_builder'
@@ -66,6 +66,7 @@ module ActionView::Helpers::FormTagHelper
66
66
  html = []
67
67
 
68
68
  asset_class = options[:class_name] && options[:class_name].to_s.constantize || association && association[:class] || PapermillAsset
69
+
69
70
  url_options = {
70
71
  :controller => "/papermill",
71
72
  :action => "create",
@@ -1,24 +1,20 @@
1
1
  require 'paperclip'
2
- require 'mime/types'
3
- require 'acts_as_list'
4
2
 
5
3
  class PapermillAsset < ActiveRecord::Base
6
- acts_as_list :scope => 'assetable_key'
7
-
8
4
  belongs_to :assetable, :polymorphic => true
9
5
  before_destroy :destroy_files
10
6
 
11
- Paperclip.interpolates(:escaped_basename) do |attachment, style|
7
+ Paperclip.interpolates :escaped_basename do |attachment, style|
12
8
  Paperclip::Interpolations[:basename].call(attachment, style).to_url
13
9
  end
14
10
 
15
- has_attached_file :file,
11
+ has_attached_file :file,
16
12
  :path => "#{Papermill::PAPERMILL_DEFAULTS[:public_root]}/#{Papermill::PAPERMILL_DEFAULTS[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}",
17
13
  :url => "/#{Papermill::PAPERMILL_DEFAULTS[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}"
18
14
  validates_attachment_presence :file
19
15
 
20
16
  def swfupload_file=(data)
21
- data.content_type = MIME::Types.type_for(data.original_filename).to_s
17
+ data.content_type = data.get_content_type
22
18
  self.file = data
23
19
  end
24
20
 
@@ -55,7 +51,7 @@ class PapermillAsset < ActiveRecord::Base
55
51
  end
56
52
 
57
53
  def destroy_files
58
- system "rm -rf #{Papermill::papermill_interpolated_path({":id_partition" => self.id_partition}, ':id_partition')}/"
54
+ FileUtils.rm_r "#{Papermill::papermill_interpolated_path({":id_partition" => self.id_partition}, ':id_partition')}/"
59
55
  true
60
56
  end
61
57
  end
@@ -31,7 +31,7 @@
31
31
  .papermill-asset-container { border:1px solid #EEE; padding:3px; }
32
32
  .papermill-asset-container li { display:block; height:22px; }
33
33
  .papermill-asset-container .swfupload .name { margin-left:21px; }
34
- .papermill-asset-container .name { float:left; }
34
+ .papermill-asset-container .name { float:left; margin-top:5px; }
35
35
  .papermill-asset-container .status { margin-left:5px; float:left; }
36
36
  .papermill-asset-container .progress { float:left; margin-top:6px; margin-left:5px; width:100px; }
37
37
  .papermill-asset-container .delete { float:left; margin-top:2px; margin-right:5px; }
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.12.2
4
+ version: 0.13.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-10-07 00:00:00 +02:00
12
+ date: 2009-10-16 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,26 +22,6 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.3.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: "1.16"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: acts_as_list
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.1.2
44
- version:
45
25
  description: Paperclip Swfupload UploadHelper wrapper
46
26
  email: benoit.benezech@gmail.com
47
27
  executables: []