stash-magic 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -2
- data/spec.rb +2 -2
- data/stash_magic.gemspec +2 -2
- data/stash_magic.rb +9 -3
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -196,13 +196,13 @@ It is of course possible. StashMagic provides a hook called after_stash which ta
|
|
196
196
|
|
197
197
|
What you have to do is overwrite the hook. For example, say you want every attachment to have a 200x200 perfect squared version:
|
198
198
|
|
199
|
-
after_stash(attachment_name)
|
199
|
+
def after_stash(attachment_name)
|
200
200
|
image_magick(attachment_name, 'square.jpg') { im_resize(200, 200, '^') }
|
201
201
|
end
|
202
202
|
|
203
203
|
Of course you can do something different for any attachment. You just need to use the attachment name in a case statement for example. Or you can do something different depending on the type of file using the getters. For example:
|
204
204
|
|
205
|
-
after_stash(attachment_name)
|
205
|
+
def after_stash(attachment_name)
|
206
206
|
attachment_hash = self.send(attachment_name)
|
207
207
|
image_magick(attachment_name, 'square.jpg') { im_resize(200, 200, '^') } if attachment_hash[:type][/^image\//]
|
208
208
|
end
|
@@ -254,6 +254,7 @@ The project is speced with
|
|
254
254
|
- 0.0.1 Begins
|
255
255
|
- 0.0.2 Add im_negate to the ImageMagick builder
|
256
256
|
- 0.0.3 Fix image destruction when there is nothing to destroy
|
257
|
+
- 0.0.5 Remove ERB dependency
|
257
258
|
|
258
259
|
== Copyright
|
259
260
|
|
data/spec.rb
CHANGED
@@ -170,10 +170,10 @@ describe ::StashMagic do
|
|
170
170
|
|
171
171
|
it "Should be able to build image tags" do
|
172
172
|
@t = Treasure.create(:map => @img)
|
173
|
-
tag = @t.build_image_tag(:map,nil,:alt => 'Amazing Map')
|
173
|
+
tag = @t.build_image_tag(:map,nil,:alt => 'Amazing & Beautiful Map')
|
174
174
|
tag.should.match(/^<img\s.+\s\/>$/)
|
175
175
|
tag.should.match(/\ssrc="\/stash\/Treasure\/#{@t.id}\/map.jpg"\s/)
|
176
|
-
tag.should.match(/\salt="Amazing Map"\s/)
|
176
|
+
tag.should.match(/\salt="Amazing & Beautiful Map"\s/)
|
177
177
|
tag.should.match(/\stitle=""\s/)
|
178
178
|
end
|
179
179
|
|
data/stash_magic.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'stash-magic'
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.5"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
|
-
s.summary = "
|
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."
|
7
7
|
s.files = `git ls-files`.split("\n").sort
|
8
8
|
s.test_files = ['spec.rb']
|
data/stash_magic.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'erb'
|
3
2
|
|
4
3
|
# A replacement for our current attachment system
|
5
4
|
# New requirements being:
|
@@ -92,7 +91,7 @@ module StashMagic
|
|
92
91
|
alt = send(attachment_name+'_alternative_text') rescue nil
|
93
92
|
html_attributes = {:src => file_url(attachment_name, style), :title => title, :alt => alt}.update(html_attributes)
|
94
93
|
html_attributes = html_attributes.map do |k,v|
|
95
|
-
%{#{k.to_s}="#{
|
94
|
+
%{#{k.to_s}="#{html_escape(v.to_s)}"}
|
96
95
|
end.join(' ')
|
97
96
|
|
98
97
|
"<img #{html_attributes} />"
|
@@ -146,7 +145,7 @@ module StashMagic
|
|
146
145
|
FU.chmod(0777, url)
|
147
146
|
after_stash(k)
|
148
147
|
end
|
149
|
-
# Reset in case we access
|
148
|
+
# Reset in case we access two times the entry in the same session
|
150
149
|
# Like setting an attachment and destroying it consecutively
|
151
150
|
# Dummy ex: Model.create(:img => file).update(:img => nil)
|
152
151
|
@tempfile_path = nil
|
@@ -188,4 +187,11 @@ module StashMagic
|
|
188
187
|
end
|
189
188
|
end
|
190
189
|
|
190
|
+
private
|
191
|
+
|
192
|
+
# Stolen from ERB
|
193
|
+
def html_escape(s)
|
194
|
+
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
195
|
+
end
|
196
|
+
|
191
197
|
end
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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-03-03 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -67,6 +67,6 @@ rubyforge_project:
|
|
67
67
|
rubygems_version: 1.3.7
|
68
68
|
signing_key:
|
69
69
|
specification_version: 3
|
70
|
-
summary:
|
70
|
+
summary: File Attachment Made Simple
|
71
71
|
test_files:
|
72
72
|
- spec.rb
|