paperclip-remote 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.rdoc +27 -0
- data/lib/paperclip-remote.rb +1 -0
- data/lib/paperclip/remote.rb +44 -0
- data/lib/paperclip_remote.rb +1 -0
- data/rails/init.rb +1 -0
- metadata +91 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (C) 2011 Dimitrij Denissenko
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= Paperclip remote URL plugin
|
2
|
+
|
3
|
+
Allows fetching files/attachments from remote locations.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Just add <tt>gem paperclip-remote</tt> to your Gemfile.
|
8
|
+
|
9
|
+
Alternatively, run <tt>sudo gem install paperclip-remote</tt> and add
|
10
|
+
<tt>require 'paperclip_remote'</tt> to your app.
|
11
|
+
|
12
|
+
== Example
|
13
|
+
|
14
|
+
In the model, you can specify:
|
15
|
+
|
16
|
+
class User < ActiveRecord::Base
|
17
|
+
has_attached_file :photo, :remote => true
|
18
|
+
attr_accessible :photo, :photo_remote_url
|
19
|
+
end
|
20
|
+
|
21
|
+
In the form you can then have:
|
22
|
+
|
23
|
+
<%= f.label :photo, "Please update a photo" %>
|
24
|
+
<%= f.file_field :photo %>
|
25
|
+
<br/>
|
26
|
+
<%= f.label :photo_remote_url, "or specify a URL" %>
|
27
|
+
<%= f.text_field :photo_remote_url %>
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'paperclip_remote'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
# Allows fetching files from remote locations. Example:
|
5
|
+
#
|
6
|
+
# class User < ActiveRecord::Base
|
7
|
+
# has_attached_file :photo, :remote => true
|
8
|
+
# attr_accessible :photo, :photo_remote_url
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# In the form you can then have:
|
12
|
+
#
|
13
|
+
# <%= f.label :photo, "Please update a photo" %>
|
14
|
+
# <%= f.file_field :photo %>
|
15
|
+
# <br/>
|
16
|
+
# <%= f.label :photo_remote_url, "or specify a URL" %>
|
17
|
+
# <%= f.text_field :photo_remote_url %>
|
18
|
+
#
|
19
|
+
module Paperclip::Remote
|
20
|
+
|
21
|
+
def has_attached_file_with_remote(name, options = {})
|
22
|
+
has_attached_file_without_remote(name, options)
|
23
|
+
|
24
|
+
if attachment_definitions[name][:remote]
|
25
|
+
attr_accessor :"#{name}_remote_url"
|
26
|
+
|
27
|
+
before_validation do |record|
|
28
|
+
url = record.send(:"#{name}_remote_url")
|
29
|
+
if url.present? && (upload = open(URI.parse(url)) rescue nil)
|
30
|
+
upload.original_filename = File.basename(upload.base_uri.path)
|
31
|
+
send :"#{name}=", upload
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
module Paperclip::ClassMethods # :nodoc:
|
40
|
+
include Paperclip::Remote
|
41
|
+
|
42
|
+
alias_method :has_attached_file_without_remote, :has_attached_file
|
43
|
+
alias_method :has_attached_file, :has_attached_file_with_remote
|
44
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'paperclip/remote'
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'paperclip_remote'
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-remote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dimitrij Denissenko
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-17 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: paperclip
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Allows fetching attachments from remote locations
|
38
|
+
email: dimitrij@blacksquaremedia.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
- lib/paperclip_remote.rb
|
49
|
+
- lib/paperclip/remote.rb
|
50
|
+
- lib/paperclip-remote.rb
|
51
|
+
- rails/init.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: https://github.com/bsm/paperclip-remote
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 57
|
67
|
+
segments:
|
68
|
+
- 1
|
69
|
+
- 8
|
70
|
+
- 7
|
71
|
+
version: 1.8.7
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 3
|
81
|
+
- 6
|
82
|
+
version: 1.3.6
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.6.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Plugin for Paperclip
|
90
|
+
test_files: []
|
91
|
+
|