BBenezech-papermill 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -4,7 +4,8 @@ class PapermillController < ApplicationController
4
4
 
5
5
  def show
6
6
  begin
7
- asset = PapermillAsset.find(params[:id])
7
+ complete_id = (params[:id0] + params[:id1] + params[:id2]).to_i
8
+ asset = PapermillAsset.find(complete_id)
8
9
  raise if asset.nil? || params[:style] == "original"
9
10
  style = Papermill::PAPERMILL_DEFAULTS[:aliases][params[:style]] || !Papermill::PAPERMILL_DEFAULTS[:alias_only] && params[:style]
10
11
  raise unless style
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
2
  map.resources :papermill, :collection => { :sort => :post }
3
- map.connect "#{Papermill::PAPERMILL_DEFAULTS[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING}", :controller => "papermill", :action => "show"
3
+ map.connect "#{Papermill::PAPERMILL_DEFAULTS[:papermill_prefix]}/#{Papermill::PAPERCLIP_INTERPOLATION_STRING.gsub(":id_partition", ":id0/:id1/:id2")}", :controller => "papermill", :action => "show"
4
4
  end
@@ -9,18 +9,6 @@ class PapermillAsset < ActiveRecord::Base
9
9
 
10
10
  named_scope :key, lambda { |key| { :conditions => { :assetable_key => key } } }
11
11
 
12
- Paperclip::Attachment.interpolations[:assetable_type] = proc do |attachment, style|
13
- attachment.instance.assetable_type.underscore.pluralize
14
- end
15
-
16
- Paperclip::Attachment.interpolations[:assetable_id] = proc do |attachment, style|
17
- attachment.instance.assetable_id
18
- end
19
-
20
- Paperclip::Attachment.interpolations[:assetable_key] = proc do |attachment, style|
21
- attachment.instance.assetable_key.to_url
22
- end
23
-
24
12
  Paperclip::Attachment.interpolations[:escaped_basename] = proc do |attachment, style|
25
13
  Paperclip::Attachment.interpolations[:basename].call(attachment, style).to_url
26
14
  end
@@ -38,6 +26,10 @@ class PapermillAsset < ActiveRecord::Base
38
26
  self.file = data
39
27
  end
40
28
 
29
+ def id_partition
30
+ ("%09d" % self.id).scan(/\d{3}/).join("/")
31
+ end
32
+
41
33
  def name
42
34
  file_file_name
43
35
  end
@@ -51,20 +43,20 @@ class PapermillAsset < ActiveRecord::Base
51
43
  end
52
44
 
53
45
  def content_type
54
- file_content_type.split("/") if file_content_type
46
+ file_content_type && file_content_type.split("/")
55
47
  end
56
48
 
57
49
  def image?
58
- content_type.first == "image" && content_type[1]
50
+ content_type && content_type.first == "image" && content_type[1]
59
51
  end
60
52
 
61
53
  def interpolated_path(with = {}, up_to = nil)
62
- Papermill::papermill_interpolated_path({":id" => self.id, ":assetable_id" => self.assetable_id, ":assetable_type" => self.assetable_type.underscore.pluralize}.merge(with), up_to)
54
+ Papermill::papermill_interpolated_path({":id_partition" => self.id_partition}.merge(with), up_to)
63
55
  end
64
56
 
65
57
  # before_filter
66
58
  def destroy_files
67
- system "rm -rf #{self.interpolated_path({}, ':id')}/" if image?
59
+ system "rm -rf #{Papermill::papermill_interpolated_path({":id_partition" => self.id_partition}, ':id_partition')}/" if image?
68
60
  true
69
61
  end
70
62
  end
@@ -45,7 +45,7 @@ module Papermill
45
45
  :button_image_url => '/images/papermill/upload-blank.png',
46
46
  :button_width => 61,
47
47
  :button_height => 22,
48
- # Wording and CSS processed through an Adobe Flash styler. Result is so-so. Feel free to put a CSS button overlayed directly on the SWF button. See swfupload website.
48
+ # Wording and CSS processed through an Adobe Flash styler. Result is terrible. Feel free to put a CSS button overlayed directly on the SWF button. See swfupload website.
49
49
  :button_text => %{<span class="button-text">#{I18n.t("upload-button-wording", :scope => :papermill)}</span>},
50
50
  :button_text_style => %{.button-text { color: red; font-size: 12pt; font-weight: bold; }},
51
51
  :button_disabled => "false",
@@ -56,7 +56,7 @@ module Papermill
56
56
  # See swfupload.js for details.
57
57
  },
58
58
  :images_only => false, # set to true to forbid upload of anything else than images
59
- :file_size_limit_mb => 10, # file max size, MegaBytes
59
+ :file_size_limit_mb => 10, # file max size
60
60
  :button_after_container => false, # set to true to move the upload button below the container
61
61
 
62
62
  # DO NOT CHANGE THESE IN YOUR CLASSES. Only application wide (routes depend on it..)
@@ -67,12 +67,12 @@ module Papermill
67
67
  # path to the root of your public directory
68
68
  :public_root => ":rails_root/public",
69
69
  # added to :public_root as the root folder for all papermill items
70
- :papermill_prefix => "papermill"
70
+ :papermill_prefix => "system/papermill"
71
71
  }.deep_merge( Papermill.const_defined?("OPTIONS") ? Papermill::OPTIONS : {} )
72
72
 
73
73
 
74
- PAPERCLIP_INTERPOLATION_STRING = ":assetable_type/:assetable_id/:id/:style/:escaped_basename.:extension"
75
-
74
+ PAPERCLIP_INTERPOLATION_STRING = ":id_partition/:style/:escaped_basename.:extension"
75
+
76
76
  def self.included(base)
77
77
  base.extend(ClassMethods)
78
78
  end
@@ -114,7 +114,6 @@ module Papermill
114
114
  @papermill_associations.merge!({assoc => {:class => asset_class}})
115
115
  @papermill_options = Papermill::PAPERMILL_DEFAULTS.deep_merge(options)
116
116
  before_destroy :destroy_assets
117
- after_destroy :remove_papermill_folder
118
117
  after_create :rebase_assets
119
118
  # reinventing the wheel because ActiveRecord chokes on :finder_sql with associations
120
119
  # TODO Clean the mess
@@ -151,24 +150,15 @@ module Papermill
151
150
  @timestamp ||= "-#{(Time.now.to_f * 1000).to_i.to_s[4..-1]}"
152
151
  end
153
152
 
154
- def interpolated_path(with = {}, up_to = nil)
155
- Papermill::papermill_interpolated_path({
156
- ":assetable_type" => self.class.sti_name.underscore.pluralize,
157
- ":assetable_id" => self.id
158
- }.merge(with), up_to)
159
- end
160
-
161
153
  private
162
154
 
163
155
  def destroy_assets
164
156
  PapermillAsset.find(:all, :conditions => {:assetable_id => self.id, :assetable_type => self.class.sti_name}).each do |asset|
165
157
  asset.destroy
166
158
  end
167
- true
168
159
  end
169
160
 
170
161
  def rebase_assets
171
- return true unless timestamp
172
162
  PapermillAsset.find(:all, :conditions => {:assetable_id => self.timestamp, :assetable_type => self.class.sti_name}).each do |asset|
173
163
  if asset.created_at < 2.hours.ago
174
164
  asset.destroy
@@ -176,13 +166,7 @@ module Papermill
176
166
  asset.update_attribute(:assetable_id, self.id)
177
167
  end
178
168
  end
179
- system "mv #{interpolated_path({':assetable_id' => timestamp}, ':assetable_id')}/ #{interpolated_path({}, ':assetable_id')}/"
180
- true
181
- end
182
-
183
- def remove_papermill_folder
184
- system "rm -rf #{interpolated_path({}, ':assetable_id')}/"
185
- true
186
169
  end
170
+
187
171
  end
188
172
  end
data/papermill.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{papermill}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Benoit B\303\251n\303\251zech"]
@@ -2,6 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class PapermillTest < ActiveSupport::TestCase
4
4
  # Replace this with your real tests.
5
+
5
6
  test "the truth" do
6
7
  assert true
7
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BBenezech-papermill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Benoit B\xC3\xA9n\xC3\xA9zech"
@@ -63,6 +63,7 @@ files:
63
63
  - uninstall.rb
64
64
  has_rdoc: false
65
65
  homepage: http://github.com/BBenezech/papermill
66
+ licenses:
66
67
  post_install_message:
67
68
  rdoc_options:
68
69
  - --charset=UTF-8
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  requirements: []
84
85
 
85
86
  rubyforge_project:
86
- rubygems_version: 1.2.0
87
+ rubygems_version: 1.3.5
87
88
  signing_key:
88
89
  specification_version: 3
89
90
  summary: Paperclip wrapper