stash-magic 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/README.rdoc +8 -0
- data/spec.rb +9 -2
- data/stash_magic.gemspec +1 -1
- data/stash_magic.rb +3 -3
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -209,6 +209,13 @@ Of course you can do something different for any attachment. You just need to us
|
|
209
209
|
|
210
210
|
Will do the same but only if the mime type of the file starts with 'image/' (which means it's an image).
|
211
211
|
|
212
|
+
You can also discard the original size and keep resized version instead.
|
213
|
+
This is done by using `nil` as a style:
|
214
|
+
|
215
|
+
def after_stash(attachment_name)
|
216
|
+
image_magick(attachment_name) { im_resize(400,300) }
|
217
|
+
end
|
218
|
+
|
212
219
|
= How my files are then saved on my file system
|
213
220
|
|
214
221
|
I like to believe that one don't have to think about that as long as the module provides enough methods to do what you need to do.
|
@@ -255,6 +262,7 @@ The project is speced with
|
|
255
262
|
- 0.0.2 Add im_negate to the ImageMagick builder
|
256
263
|
- 0.0.3 Fix image destruction when there is nothing to destroy
|
257
264
|
- 0.0.5 Remove ERB dependency
|
265
|
+
- 0.0.7 Make it possible to overwrite the original image with another style in after_stash
|
258
266
|
|
259
267
|
== Copyright
|
260
268
|
|
data/spec.rb
CHANGED
@@ -233,8 +233,15 @@ describe ::StashMagic do
|
|
233
233
|
im_crop(200,100,20,10)
|
234
234
|
im_resize(200, 100, '^', 'North')
|
235
235
|
end.should=="-negate -crop 200x100+20+10 +repage -resize '200x100^' -gravity North -extent 200x100"
|
236
|
-
F.exists?(@t.file_url(:map,'test4.gif',true)).should==true
|
237
|
-
|
236
|
+
F.exists?(@t.file_url(:map,'test4.gif',true)).should==true
|
237
|
+
end
|
238
|
+
|
239
|
+
it "Should be possible to overwrite the original image" do
|
240
|
+
@t = Treasure.create(:map=>@img)
|
241
|
+
url = @t.file_url(:map,nil,true)
|
242
|
+
size_before = F.size(url)
|
243
|
+
@t.convert(:map, '-resize 100x75')
|
244
|
+
F.size(url).should.not==size_before
|
238
245
|
end
|
239
246
|
|
240
247
|
::FileUtils.rm_rf(Treasure::PUBLIC) if F.exists?(Treasure::PUBLIC)
|
data/stash_magic.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'stash-magic'
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.7"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "File Attachment Made Simple"
|
6
6
|
s.description = "A simple attachment system that also handles thumbnails or other styles via ImageMagick. Originaly tested on Sequel ORM but purposedly easy to plug to something else."
|
data/stash_magic.rb
CHANGED
@@ -101,11 +101,11 @@ module StashMagic
|
|
101
101
|
# = ImageMagick =
|
102
102
|
# ===============
|
103
103
|
# Basic
|
104
|
-
def convert(attachment_name, convert_steps="
|
104
|
+
def convert(attachment_name, convert_steps="", style=nil)
|
105
105
|
system "convert \"#{file_url(attachment_name, nil, true)}\" #{convert_steps} \"#{file_url(attachment_name, style, true)}\""
|
106
106
|
end
|
107
107
|
# IM String builder
|
108
|
-
def image_magick(attachment_name, style, &block)
|
108
|
+
def image_magick(attachment_name, style=nil, &block)
|
109
109
|
@image_magick_strings = []
|
110
110
|
instance_eval &block
|
111
111
|
convert_string = @image_magick_strings.join(' ')
|
@@ -154,7 +154,7 @@ module StashMagic
|
|
154
154
|
|
155
155
|
def after_stash(attachment_name)
|
156
156
|
current = self.send(attachment_name)
|
157
|
-
convert(attachment_name) if !current.nil? && current[:type][/^image\//]
|
157
|
+
convert(attachment_name, "-resize 100x75^ -gravity center -extent 100x75", 'stash_thumb.gif') if !current.nil? && current[:type][/^image\//]
|
158
158
|
end
|
159
159
|
|
160
160
|
def destroy_files_for(attachment_name, url=nil)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mickael Riga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|