attachment_on_the_fly 0.0.6 → 0.0.7
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/Rakefile +1 -0
- data/VERSION +1 -1
- data/attachment_on_the_fly.gemspec +15 -13
- data/lib/attachment_on_the_fly.rb +23 -23
- metadata +30 -9
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ begin
|
|
7
7
|
gemspec.email = "jefferey.sutherland@gmail.com"
|
8
8
|
gemspec.homepage = "http://github.com/drpentode/Attachment-on-the-Fly"
|
9
9
|
gemspec.authors = ["Jeff Sutherland"]
|
10
|
+
gemspec.add_dependency "paperclip"
|
10
11
|
end
|
11
12
|
rescue LoadError
|
12
13
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
@@ -1,44 +1,46 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{attachment_on_the_fly}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Sutherland"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-12-21}
|
13
13
|
s.description = %q{A Paperclip mix-in to allow auto-generation of resized images}
|
14
14
|
s.email = %q{jefferey.sutherland@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
"README",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"attachment_on_the_fly.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/attachment_on_the_fly.rb"
|
27
27
|
]
|
28
28
|
s.homepage = %q{http://github.com/drpentode/Attachment-on-the-Fly}
|
29
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
30
29
|
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.3.
|
30
|
+
s.rubygems_version = %q{1.3.7}
|
32
31
|
s.summary = %q{A Paperclip mix-in to allow auto-generation of resized images}
|
33
32
|
|
34
33
|
if s.respond_to? :specification_version then
|
35
34
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
35
|
s.specification_version = 3
|
37
36
|
|
38
|
-
if Gem::Version.new(Gem::
|
37
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
38
|
+
s.add_runtime_dependency(%q<paperclip>, [">= 0"])
|
39
39
|
else
|
40
|
+
s.add_dependency(%q<paperclip>, [">= 0"])
|
40
41
|
end
|
41
42
|
else
|
43
|
+
s.add_dependency(%q<paperclip>, [">= 0"])
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -3,25 +3,25 @@
|
|
3
3
|
# the paperclip attachment attribute should be called "attachment" on the model
|
4
4
|
#
|
5
5
|
Paperclip::Attachment.class_eval do
|
6
|
-
require 'ftools'
|
6
|
+
require 'ftools' if RUBY_VERSION < "1.9"
|
7
7
|
require 'fileutils'
|
8
8
|
require 'tempfile'
|
9
|
-
|
9
|
+
|
10
10
|
# we respond to s_ and cls_
|
11
11
|
def respond_to?(method,*args, &block)
|
12
12
|
if method.to_s.match(/^s_[0-9]+_[0-9]+/) || method.to_s.match(/^s_[0-9]+_[a-z]+/) || method.to_s.match(/^s[0-9]+/) ||
|
13
|
-
|
13
|
+
method.to_s.match(/^cls_[0-9]+_[0-9]+/) || method.to_s.match(/^cls_[0-9]+_[a-z]+/) || method.to_s.match(/^cls[0-9]+/)
|
14
14
|
return true
|
15
15
|
end
|
16
16
|
super
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def method_missing(symbol , *args, &block )
|
20
20
|
# We are looking for methods with S_[number]_[number]_(height | width | proportion)
|
21
21
|
# Height and width
|
22
22
|
# Check to see if file exist if so return string
|
23
23
|
# if not generate image and return string to file Fiel is in format S_Height_x_Width_FILE_NAME
|
24
|
-
|
24
|
+
image_name = nil
|
25
25
|
if symbol.to_s.match(/^s_[0-9]+_[0-9]+/) || symbol.to_s.match(/^cls_[0-9]+_[0-9]+/)
|
26
26
|
values = symbol.to_s.split("_")
|
27
27
|
height = values[1]
|
@@ -37,43 +37,43 @@ Paperclip::Attachment.class_eval do
|
|
37
37
|
size = values[1]
|
38
38
|
who = "width"
|
39
39
|
image_name = generate_image(who, size.to_i)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
else
|
41
|
+
# if our method string does not match, we kick things back up to super ... this keeps ActiveRecord chugging along happily
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
return image_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_image(kind, height = 0, width = 0)
|
49
49
|
prefix = ""
|
50
|
-
|
50
|
+
|
51
51
|
if kind == "height"
|
52
|
-
prefix = "S_" + height.to_s + "_HEIGHT_"
|
52
|
+
prefix = "S_" + height.to_s + "_HEIGHT_"
|
53
53
|
elsif kind == "width"
|
54
54
|
width = height
|
55
55
|
prefix = "S_" + height.to_s + "_WIDTH_"
|
56
56
|
elsif kind == "both"
|
57
57
|
prefix = "S_" + height.to_s + "_" + height.to_s + "_"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
path = instance.attachment.path
|
61
61
|
url = instance.attachment.url
|
62
|
-
|
62
|
+
|
63
63
|
path_arr = path.split("/")
|
64
64
|
file_name = path_arr.pop
|
65
65
|
path = path_arr.join("/")
|
66
|
-
|
66
|
+
|
67
67
|
url_arr = url.split("/")
|
68
68
|
url_file_name = url_arr.pop
|
69
69
|
url_path = url_arr.join("/")
|
70
|
-
|
70
|
+
|
71
71
|
original = path + "/" + instance.attachment.original_filename
|
72
72
|
newfilename = path + "/" + prefix + file_name
|
73
73
|
new_path = url_path + "/" + prefix + file_name
|
74
|
-
|
74
|
+
|
75
75
|
return new_path if File.exist?(newfilename)
|
76
|
-
|
76
|
+
|
77
77
|
if !File.exist?(original)
|
78
78
|
return new_path
|
79
79
|
end
|
@@ -91,4 +91,4 @@ Paperclip::Attachment.class_eval do
|
|
91
91
|
|
92
92
|
return new_path
|
93
93
|
end
|
94
|
-
end
|
94
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachment_on_the_fly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jeff Sutherland
|
@@ -9,10 +14,22 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-12-21 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: paperclip
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
16
33
|
description: A Paperclip mix-in to allow auto-generation of resized images
|
17
34
|
email: jefferey.sutherland@gmail.com
|
18
35
|
executables: []
|
@@ -35,26 +52,30 @@ homepage: http://github.com/drpentode/Attachment-on-the-Fly
|
|
35
52
|
licenses: []
|
36
53
|
|
37
54
|
post_install_message:
|
38
|
-
rdoc_options:
|
39
|
-
|
55
|
+
rdoc_options: []
|
56
|
+
|
40
57
|
require_paths:
|
41
58
|
- lib
|
42
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
43
61
|
requirements:
|
44
62
|
- - ">="
|
45
63
|
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
46
66
|
version: "0"
|
47
|
-
version:
|
48
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
49
69
|
requirements:
|
50
70
|
- - ">="
|
51
71
|
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
52
74
|
version: "0"
|
53
|
-
version:
|
54
75
|
requirements: []
|
55
76
|
|
56
77
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.3.
|
78
|
+
rubygems_version: 1.3.7
|
58
79
|
signing_key:
|
59
80
|
specification_version: 3
|
60
81
|
summary: A Paperclip mix-in to allow auto-generation of resized images
|