smartthumbs 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +19 -2
- data/lib/smartthumbs/thumbable.rb +12 -4
- data/lib/smartthumbs/version.rb +1 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -30,9 +30,9 @@ Afterwards you should create an initializer-script in config/initializers:
|
|
30
30
|
Smartthumbs needs to know all classes that you want to use smartthumbs with.
|
31
31
|
Pass them as an array of strings via :valid_classes .
|
32
32
|
|
33
|
-
By default smartthumbs generates urls like "/th
|
33
|
+
By default smartthumbs generates urls like "/th/klass-name/format/record-id.extension". If you only have a single class, you can set the default-class and prevent this class name from appearing in that url.
|
34
34
|
|
35
|
-
That's it,
|
35
|
+
That's it, you're ready to use smartthumbs.
|
36
36
|
|
37
37
|
## Examples
|
38
38
|
|
@@ -61,6 +61,23 @@ That's it, your ready to use smartthumbs.
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
|
65
|
+
Since version 0.0.4 it's possible to pass a lambda function as :formats. That makes it possible to store the formats inside of a model:
|
66
|
+
|
67
|
+
class ThumbFormat < ActiveRecord::Base
|
68
|
+
def config
|
69
|
+
["#{width}x#{height}", method.to_sym, orientation.try(:to_sym)]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Image < ActiveRecord::Base
|
74
|
+
smartthumbs :file => :file, :extension => "jpg", :formats => lambda{|format|
|
75
|
+
ThumbFormat.find_by_name(format).try(:config)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
64
81
|
### In your View
|
65
82
|
|
66
83
|
<%= thumb_tag, @image, "tiny", :class => "red-border" %>
|
@@ -19,9 +19,16 @@ module Smartthumbs
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
# returns
|
22
|
+
# returns the specific format-array for the key f
|
23
|
+
# e.g. ["100x200", :cut]
|
24
|
+
# The config value for formats can be a hash or sth that responds to +call+
|
25
|
+
# e.g. a lambda.
|
23
26
|
def st_format(f)
|
24
|
-
self.class.st_config[:formats]
|
27
|
+
if self.class.st_config[:formats].respond_to?(:call)
|
28
|
+
self.class.st_config[:formats].call(f.to_sym)
|
29
|
+
else
|
30
|
+
self.class.st_config[:formats][f]
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
# returns the file extension for the current image
|
@@ -62,8 +69,7 @@ module Smartthumbs
|
|
62
69
|
# returns the gravity for the current resizing process and
|
63
70
|
# provides some shrotcuts
|
64
71
|
def gravity
|
65
|
-
|
66
|
-
{
|
72
|
+
@gravity ||= {
|
67
73
|
:new => Magick::NorthWestGravity,
|
68
74
|
:n => Magick::NorthGravity,
|
69
75
|
:ne => Magick::NorthEastGravity,
|
@@ -74,6 +80,8 @@ module Smartthumbs
|
|
74
80
|
:s => Magick::SouthGravity,
|
75
81
|
:se => Magick::SouthEastGravity
|
76
82
|
}[st_format(@format).last]
|
83
|
+
|
84
|
+
@gravity ||= Magick::CenterGravity
|
77
85
|
end
|
78
86
|
|
79
87
|
# Does a thumb already exist?
|
data/lib/smartthumbs/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartthumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Pauly
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|