stash-magic 0.0.8 → 0.0.9

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 CHANGED
@@ -264,6 +264,7 @@ The project is speced with
264
264
  - 0.0.5 Remove ERB dependency
265
265
  - 0.0.7 Make it possible to overwrite the original image with another style in after_stash
266
266
  - 0.0.8 Default thumb does not break when file name has signs in the name
267
+ - 0.0.9 Fix a bug when Model#build_image_tag uses a symbol for the attachment name
267
268
 
268
269
  == Copyright
269
270
 
data/spec.rb CHANGED
@@ -25,6 +25,8 @@ class Treasure < ::Sequel::Model
25
25
  primary_key :id
26
26
  Integer :age
27
27
  String :map # jpeg
28
+ String :map_tooltip
29
+ String :map_alternative_text
28
30
  String :mappy # jpeg - Used to see if mappy files are not destroyed when map is (because it starts the same)
29
31
  String :instructions #pdf
30
32
  end
@@ -169,7 +171,16 @@ describe ::StashMagic do
169
171
  end
170
172
 
171
173
  it "Should be able to build image tags" do
172
- @t = Treasure.create(:map => @img)
174
+ @t = Treasure.create(:map => @img, :map_alternative_text => "Wonderful")
175
+ tag = @t.build_image_tag(:map)
176
+ tag.should.match(/^<img\s.+\s\/>$/)
177
+ tag.should.match(/\ssrc="\/stash\/Treasure\/#{@t.id}\/map.jpg"\s/)
178
+ tag.should.match(/\salt="Wonderful"\s/)
179
+ tag.should.match(/\stitle=""\s/)
180
+ end
181
+
182
+ it "Should be able to build image tags and override alt and title" do
183
+ @t = Treasure.create(:map => @img, :map_alternative_text => "Wonderful")
173
184
  tag = @t.build_image_tag(:map,nil,:alt => 'Amazing & Beautiful Map')
174
185
  tag.should.match(/^<img\s.+\s\/>$/)
175
186
  tag.should.match(/\ssrc="\/stash\/Treasure\/#{@t.id}\/map.jpg"\s/)
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.8"
3
+ s.version = "0.0.9"
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
@@ -37,7 +37,7 @@ module StashMagic
37
37
  return if upload_hash=="" # File in the form is unchanged
38
38
 
39
39
  if upload_hash.nil?
40
- destroy_files_for(name) unless self.send(name).nil?
40
+ destroy_files_for(name) unless self.__send__(name).nil?
41
41
  super('')
42
42
  else
43
43
 
@@ -78,7 +78,7 @@ module StashMagic
78
78
  # Returns the url of an attachment in a specific style(original if nil)
79
79
  # The argument 'full' means it returns the absolute path(used to save files)
80
80
  def file_url(attachment_name, style=nil, full=false)
81
- f = send(attachment_name)
81
+ f = __send__(attachment_name)
82
82
  return nil if f.nil?
83
83
  fn = style.nil? ? f[:name] : "#{attachment_name}.#{style}"
84
84
  "#{file_path(full)}/#{fn}"
@@ -87,8 +87,9 @@ module StashMagic
87
87
  # Build the image tag with all SEO friendly info
88
88
  # It's possible to add html attributes in a hash
89
89
  def build_image_tag(attachment_name, style=nil, html_attributes={})
90
- title = send(attachment_name+'_tooltip') rescue nil
91
- alt = send(attachment_name+'_alternative_text') rescue nil
90
+ title_field, alt_field = (attachment_name.to_s+'_tooltip').to_sym, (attachment_name.to_s+'_alternative_text').to_sym
91
+ title = __send__(title_field) if columns.include?(title_field)
92
+ alt = __send__(alt_field) if columns.include?(alt_field)
92
93
  html_attributes = {:src => file_url(attachment_name, style), :title => title, :alt => alt}.update(html_attributes)
93
94
  html_attributes = html_attributes.map do |k,v|
94
95
  %{#{k.to_s}="#{html_escape(v.to_s)}"}
@@ -153,7 +154,7 @@ module StashMagic
153
154
  end
154
155
 
155
156
  def after_stash(attachment_name)
156
- current = self.send(attachment_name)
157
+ current = self.__send__(attachment_name)
157
158
  convert(attachment_name, "-resize '100x75^' -gravity center -extent 100x75", 'stash_thumb.gif') if !current.nil? && current[:type][/^image\//]
158
159
  end
159
160
 
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
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-06-02 00:00:00 +01:00
18
+ date: 2011-07-05 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21