attachment_on_the_fly 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/README.rdoc +0 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/attachment_on_the_fly.gemspec +43 -0
- data/init.rb +1 -0
- data/lib/attachment_on_the_fly.rb +92 -0
- metadata +62 -0
data/README
ADDED
File without changes
|
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "attachment_on_the_fly"
|
5
|
+
gemspec.summary = "A Paperclip mix-in to allow auto-generation of resized images"
|
6
|
+
gemspec.description = "A Paperclip mix-in to allow auto-generation of resized images"
|
7
|
+
gemspec.email = "jefferey.sutherland@gmail.com"
|
8
|
+
gemspec.homepage = "http://github.com/drpentode/Attachment-on-the-Fly"
|
9
|
+
gemspec.authors = ["Jeff Sutherland"]
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{attachment_on_the_fly}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeff Sutherland"]
|
12
|
+
s.date = %q{2009-10-16}
|
13
|
+
s.description = %q{A Paperclip mix-in to allow auto-generation of resized images}
|
14
|
+
s.email = %q{jefferey.sutherland@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"README",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"attachment_on_the_fly.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/attachment_on_the_fly.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/drpentode/Attachment-on-the-Fly}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.5}
|
32
|
+
s.summary = %q{A Paperclip mix-in to allow auto-generation of resized images}
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
39
|
+
else
|
40
|
+
end
|
41
|
+
else
|
42
|
+
end
|
43
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'attachment_on_the_fly'
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# Methods to allow attachment modification on-the-fly ... a replacement for PhotoActiveRecord that integrates with Paperclip
|
3
|
+
# the paperclip attachment attribute should be called "attachment" on the model
|
4
|
+
#
|
5
|
+
Paperclip::Attachment.class_eval do
|
6
|
+
require "ftools"
|
7
|
+
require 'fileutils'
|
8
|
+
require 'tempfile'
|
9
|
+
|
10
|
+
# we respond to s_ and cls_
|
11
|
+
def respond_to?(method,*args, &block)
|
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
|
+
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
|
+
return true
|
15
|
+
end
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(symbol , *args, &block )
|
20
|
+
# We are looking for methods with S_[number]_[number]_(height | width | proportion)
|
21
|
+
# Height and width
|
22
|
+
# Check to see if file exist if so return string
|
23
|
+
# if not generate image and return string to file Fiel is in format S_Height_x_Width_FILE_NAME
|
24
|
+
image_name = nil
|
25
|
+
if symbol.to_s.match(/^s_[0-9]+_[0-9]+/) || symbol.to_s.match(/^cls_[0-9]+_[0-9]+/)
|
26
|
+
values = symbol.to_s.split("_")
|
27
|
+
height = values[1]
|
28
|
+
width = values[2]
|
29
|
+
image_name = generate_image("both", height.to_i, width.to_i)
|
30
|
+
elsif symbol.to_s.match(/^s_[0-9]+_[a-z]+/) || symbol.to_s.match(/^cls_[0-9]+_[a-z]+/)
|
31
|
+
values = symbol.to_s.split("_")
|
32
|
+
size = values[1]
|
33
|
+
who = values[2]
|
34
|
+
image_name = generate_image(who, size.to_i)
|
35
|
+
elsif symbol.to_s.match(/^s[0-9]+/) || symbol.to_s.match(/^cls[0-9]+/)
|
36
|
+
values = symbol.to_s.split("s")
|
37
|
+
size = values[1]
|
38
|
+
who = "width"
|
39
|
+
image_name = generate_image(who, size.to_i)
|
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
|
+
end
|
45
|
+
|
46
|
+
def generate_image(kind, height = 0, width = 0)
|
47
|
+
prefix = ""
|
48
|
+
|
49
|
+
if kind == "height"
|
50
|
+
prefix = "S_" + height.to_s + "_HEIGHT_"
|
51
|
+
elsif kind == "width"
|
52
|
+
width = height
|
53
|
+
prefix = "S_" + height.to_s + "_WIDTH_"
|
54
|
+
elsif kind == "both"
|
55
|
+
prefix = "S_" + height.to_s + "_" + height.to_s + "_"
|
56
|
+
end
|
57
|
+
|
58
|
+
path = instance.attachment.path
|
59
|
+
path_arr = path.split("/")
|
60
|
+
file_name = path_arr.pop
|
61
|
+
path = path_arr.join("/")
|
62
|
+
|
63
|
+
puts "attachment path " + path
|
64
|
+
|
65
|
+
original = path + "/" + instance.attachment.original_filename
|
66
|
+
newfilename = path + "/" + prefix + file_name
|
67
|
+
puts "new file name " + newfilename
|
68
|
+
|
69
|
+
return newfilename if File.exist?(newfilename)
|
70
|
+
|
71
|
+
puts "In file " + original
|
72
|
+
|
73
|
+
if !File.exist?(original)
|
74
|
+
return newfilename
|
75
|
+
end
|
76
|
+
|
77
|
+
puts "Out file " + newfilename
|
78
|
+
|
79
|
+
if kind == "height"
|
80
|
+
# resize_image infilename, outfilename , 0, height
|
81
|
+
`convert -colorspace RGB -geometry x#{height} -quality 100 #{original} #{newfilename} 2>&1 > /dev/null`
|
82
|
+
elsif kind == "width"
|
83
|
+
# resize_image infilename, outfilename, width
|
84
|
+
`convert -colorspace RGB -geometry #{width} -quality 100 #{original} #{newfilename} 2>&1 > /dev/null`
|
85
|
+
elsif kind == "both"
|
86
|
+
# resize_image infilename, outfilename, height, width
|
87
|
+
`convert -colorspace RGB -geometry #{height}x#{height} -quality 100 #{original} #{newfilename} 2>&1 > /dev/null`
|
88
|
+
end
|
89
|
+
puts newfilename
|
90
|
+
newfilename
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attachment_on_the_fly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Sutherland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-16 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Paperclip mix-in to allow auto-generation of resized images
|
17
|
+
email: jefferey.sutherland@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- README
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- attachment_on_the_fly.gemspec
|
31
|
+
- init.rb
|
32
|
+
- lib/attachment_on_the_fly.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/drpentode/Attachment-on-the-Fly
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: A Paperclip mix-in to allow auto-generation of resized images
|
61
|
+
test_files: []
|
62
|
+
|