mm-attach-it 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -0
- data/README.rdoc +18 -0
- data/lib/attach_it/attach_it.rb +4 -2
- data/lib/attach_it/attachment_options.rb +3 -0
- data/lib/attach_it/version.rb +1 -1
- data/test/test_helper.rb +15 -0
- data/test/unit/test_attach_it.rb +16 -0
- metadata +4 -4
data/README
CHANGED
@@ -71,6 +71,23 @@ If you are using the file system to store files, you can specify the directory/f
|
|
71
71
|
|
72
72
|
OBS: The default directory is ’/:rails_root/public/system/:attachment/:id/:style/:filename’
|
73
73
|
|
74
|
+
|
75
|
+
Also you can interpolate any method result of the model
|
76
|
+
|
77
|
+
class Foo
|
78
|
+
include MongoMapper::Document
|
79
|
+
plugin AttachIt
|
80
|
+
has_attachment :photo, { :url => '/:model.say_greet/users/:model.say_farewell/:id/:filename', :path => ':rails_root/public/:model.say_greet/:model.say_farewell/users/:id/:filename' }
|
81
|
+
|
82
|
+
def say_greet
|
83
|
+
'hello'
|
84
|
+
end
|
85
|
+
|
86
|
+
def say_farewell
|
87
|
+
'bye'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
74
91
|
Where:
|
75
92
|
* :rails_root - is the root directory of your Rails application
|
76
93
|
* :environment - can be "production", "test" or "development"
|
@@ -80,6 +97,7 @@ Where:
|
|
80
97
|
* :style - if you specified the styles
|
81
98
|
* :filename - the name of the file
|
82
99
|
* :extension - the extension of the file
|
100
|
+
* :model.METHOD_NAME - where METHOD_NAME is any method of the model
|
83
101
|
|
84
102
|
=== View
|
85
103
|
|
data/README.rdoc
CHANGED
@@ -71,6 +71,23 @@ If you are using the file system to store files, you can specify the directory/f
|
|
71
71
|
|
72
72
|
OBS: The default directory is ’/:rails_root/public/system/:attachment/:id/:style/:filename’
|
73
73
|
|
74
|
+
|
75
|
+
Also you can interpolate any method result of the model
|
76
|
+
|
77
|
+
class Foo
|
78
|
+
include MongoMapper::Document
|
79
|
+
plugin AttachIt
|
80
|
+
has_attachment :photo, { :url => '/:model.say_greet/users/:model.say_farewell/:id/:filename', :path => ':rails_root/public/:model.say_greet/:model.say_farewell/users/:id/:filename' }
|
81
|
+
|
82
|
+
def say_greet
|
83
|
+
'hello'
|
84
|
+
end
|
85
|
+
|
86
|
+
def say_farewell
|
87
|
+
'bye'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
74
91
|
Where:
|
75
92
|
* :rails_root - is the root directory of your Rails application
|
76
93
|
* :environment - can be "production", "test" or "development"
|
@@ -80,6 +97,7 @@ Where:
|
|
80
97
|
* :style - if you specified the styles
|
81
98
|
* :filename - the name of the file
|
82
99
|
* :extension - the extension of the file
|
100
|
+
* :model.METHOD_NAME - where METHOD_NAME is any method of the model
|
83
101
|
|
84
102
|
=== View
|
85
103
|
|
data/lib/attach_it/attach_it.rb
CHANGED
@@ -72,8 +72,10 @@ module AttachIt
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def save_attachments
|
75
|
-
@attachment_options.
|
76
|
-
@attachment_options
|
75
|
+
unless @attachment_options.nil?
|
76
|
+
@attachment_options.keys.each do |name|
|
77
|
+
@attachment_options[name].save
|
78
|
+
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -114,6 +114,9 @@ class AttachmentOptions
|
|
114
114
|
result.gsub!(/\:class/, @class_name)
|
115
115
|
result.gsub!(/\:attachment/, @attachment)
|
116
116
|
result.gsub!(/(\/){2,}/, '/')
|
117
|
+
while result.match(/:model\.([A-Za-z\_]+)/)
|
118
|
+
result.sub!(/:model\.[A-Za-z\_]+/, @model.send($1))
|
119
|
+
end
|
117
120
|
result
|
118
121
|
end
|
119
122
|
|
data/lib/attach_it/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -116,6 +116,21 @@ class UserTwelve
|
|
116
116
|
has_attachment :avatar, { :styles => { :small => '150x150>', :medium => '300x300>' }, :storage => 'gridfs' }
|
117
117
|
end
|
118
118
|
|
119
|
+
class UserThirteen
|
120
|
+
include MongoMapper::Document
|
121
|
+
plugin AttachIt
|
122
|
+
key :name, String
|
123
|
+
has_attachment :avatar, { :url => '/:model.say_greet/users/:model.say_farewell/:id/:filename', :path => ':rails_root/public/:model.say_greet/:model.say_farewell/users/:id/:filename' }
|
124
|
+
|
125
|
+
def say_greet
|
126
|
+
'hello'
|
127
|
+
end
|
128
|
+
|
129
|
+
def say_farewell
|
130
|
+
'bye'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
119
134
|
class DocumentOne
|
120
135
|
include MongoMapper::Document
|
121
136
|
plugin AttachIt
|
data/test/unit/test_attach_it.rb
CHANGED
@@ -284,4 +284,20 @@ class TestAttachIt < Test::Unit::TestCase
|
|
284
284
|
|
285
285
|
end
|
286
286
|
|
287
|
+
context "Iterpolate model methods" do
|
288
|
+
setup do
|
289
|
+
@user = UserThirteen.new
|
290
|
+
@user.name = 'Myname'
|
291
|
+
@user.avatar = File.open(JpgImageFile, 'rb')
|
292
|
+
@user.save
|
293
|
+
end
|
294
|
+
|
295
|
+
should "show methods returns" do
|
296
|
+
assert_match('hello', @user.avatar.path)
|
297
|
+
assert_match('bye', @user.avatar.path)
|
298
|
+
assert_match('hello', @user.avatar.url)
|
299
|
+
assert_match('bye', @user.avatar.url)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
287
303
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-attach-it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adilson Chacon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: wand
|