utopia 0.9.33 → 0.9.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -192,7 +192,7 @@ module Utopia
192
192
  def call(env)
193
193
  request = Rack::Request.new(env)
194
194
  ext = File.extname(request.path_info)
195
- if @extensions.key? ext
195
+ if @extensions.key? ext.downcase
196
196
  path = Path.create(request.path_info).simplify
197
197
 
198
198
  if file = fetch_file(path)
data/lib/utopia/path.rb CHANGED
@@ -104,13 +104,23 @@ module Utopia
104
104
  end
105
105
 
106
106
  def basename(ext = nil)
107
- if ext
107
+ if ext == true
108
+ File.basename(components.last, extension)
109
+ elsif String === ext
108
110
  File.basename(components.last, ext)
109
111
  else
110
112
  components.last
111
113
  end
112
114
  end
113
115
 
116
+ def extension
117
+ if components.last
118
+ components.last.split(".").last
119
+ else
120
+ nil
121
+ end
122
+ end
123
+
114
124
  def dirname(count = 1)
115
125
  path = Path.new(components[0...-count])
116
126
 
@@ -9,44 +9,74 @@ require 'fileutils'
9
9
 
10
10
  class Utopia::Tags::Gallery
11
11
  module Processes
12
- def self.pdf_thumbnail(img)
13
- img = img.resize_to_fit(300, 300)
14
-
15
- shadow = img.dup
12
+ class Thumbnail
13
+ def initialize(size = [800, 800])
14
+ @size = size
15
+ end
16
16
 
17
- shadow = shadow.colorize(1, 1, 1, 'gray50')
18
- shadow.background_color = 'transparent'
19
- shadow.border!(10, 10, 'transparent')
17
+ def call(img)
18
+ img.resize_to_fit(*@size)
19
+ end
20
20
 
21
- shadow = shadow.gaussian_blur_channel(5, 5, Magick::AlphaChannel)
22
-
23
- shadow.composite(img, 5, 5, Magick::OverCompositeOp)
21
+ def default_extension(path)
22
+ ext = path.original.extension
23
+
24
+ case ext
25
+ when /pdf/i
26
+ return "png"
27
+ else
28
+ return ext.downcase
29
+ end
30
+ end
24
31
  end
32
+
33
+ class DocumentThumbnail < Thumbnail
34
+ def call(img)
35
+ img = super(img)
25
36
 
26
- def self.photo_thumbnail(img)
27
- img = img.resize_to_fit(300, 300)
37
+ shadow = img.dup
28
38
 
29
- shadow = img.dup
30
-
31
- shadow = shadow.colorize(1, 1, 1, '#999999ff')
32
- shadow.background_color = 'transparent'
33
- shadow.border!(10, 10, '#99999900')
39
+ shadow = shadow.colorize(1, 1, 1, 'gray50')
40
+ shadow.background_color = 'transparent'
41
+ shadow.border!(10, 10, 'transparent')
42
+
43
+ shadow = shadow.gaussian_blur_channel(5, 5, Magick::AlphaChannel)
44
+
45
+ shadow.composite(img, 5, 5, Magick::OverCompositeOp)
46
+ end
34
47
 
35
- shadow = shadow.gaussian_blur_channel(5, 5, Magick::AlphaChannel)
36
-
37
- shadow.composite(img, 5, 5, Magick::OverCompositeOp)
38
- end
39
-
40
- def self.thumbnail(img)
41
- img = img.resize_to_fit(300, 300)
48
+ def default_extension(path)
49
+ return "png"
50
+ end
42
51
  end
43
-
44
- def self.large(img)
45
- img.resize_to_fit(768, 768)
52
+
53
+ class PhotoThumbnail < Thumbnail
54
+ def call(img)
55
+ img = super(img)
56
+
57
+ shadow = img.dup
58
+
59
+ shadow = shadow.colorize(1, 1, 1, '#999999ff')
60
+ shadow.background_color = 'transparent'
61
+ shadow.border!(10, 10, '#99999900')
62
+
63
+ shadow = shadow.gaussian_blur_channel(5, 5, Magick::AlphaChannel)
64
+
65
+ shadow.composite(img, 5, 5, Magick::OverCompositeOp)
66
+ end
67
+
68
+ def default_extension(path)
69
+ return "png"
70
+ end
46
71
  end
47
72
  end
48
73
 
49
74
  CACHE_DIR = "_cache"
75
+ PROCESSES = {
76
+ :pdf_thumbnail => Processes::DocumentThumbnail.new([300, 300]),
77
+ :photo_thumbnail => Processes::PhotoThumbnail.new([300, 300]),
78
+ :large => Processes::Thumbnail.new([800, 800])
79
+ }
50
80
 
51
81
  class ImagePath
52
82
  def initialize(original_path)
@@ -113,7 +143,7 @@ class Utopia::Tags::Gallery
113
143
  end
114
144
 
115
145
  def images(options = {})
116
- options[:filter] ||= /(jpg|png)$/
146
+ options[:filter] ||= /(jpg|png)$/i
117
147
 
118
148
  paths = []
119
149
  local_path = @node.local_path(@path)
@@ -150,18 +180,26 @@ class Utopia::Tags::Gallery
150
180
  processes = processes.split(",").collect{|p| p.split(":")}
151
181
  end
152
182
 
153
- processes.each do |process, extension|
154
- process = process.to_sym
155
- image_path.extensions[process] = extension if extension
183
+ processes.each do |process_name, extension|
184
+ process_name = process_name.to_sym
185
+
186
+ process = PROCESSES[process_name]
187
+ extension ||= process.default_extension(image_path)
188
+
189
+ image_path.extensions[process_name] = extension if extension
190
+
191
+ local_processed_path = @node.local_path(image_path.processed(process_name))
156
192
 
157
- local_processed_path = @node.local_path(image_path.processed(process))
158
-
159
193
  unless File.exists? local_processed_path
160
194
  image = Magick::ImageList.new(local_original_path)
161
195
  image.scene = 0
162
196
 
163
- processed_image = Processes.send(process, image)
197
+ processed_image = process.call(image)
164
198
  processed_image.write(local_processed_path)
199
+
200
+ # Run GC to free up any memory.
201
+ processed_image = nil
202
+ GC.start if defined? GC
165
203
  end
166
204
  end
167
205
  end
@@ -175,9 +213,9 @@ class Utopia::Tags::Gallery
175
213
 
176
214
  options = {}
177
215
  options[:process] = state["process"]
178
- options[:filter] = Regexp.new("(#{state["filetypes"]})$") if state["filetypes"]
216
+ options[:filter] = Regexp.new("(#{state["filetypes"]})$", "i") if state["filetypes"]
179
217
 
180
- filter = Regexp.new(state["filter"]) if state["filter"]
218
+ filter = Regexp.new(state["filter"], Regexp::IGNORECASE) if state["filter"]
181
219
 
182
220
  transaction.tag("div", "class" => "gallery") do |node|
183
221
  images = gallery.images(options).sort do |a, b|
@@ -6,7 +6,7 @@ module Utopia
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 9
9
- TINY = 33
9
+ TINY = 34
10
10
 
11
11
  STRING = [MAJOR, MINOR, TINY].join('.')
12
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 33
9
- version: 0.9.33
8
+ - 34
9
+ version: 0.9.34
10
10
  platform: ruby
11
11
  authors:
12
12
  - Samuel Williams
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-22 00:00:00 +12:00
17
+ date: 2010-07-01 00:00:00 +12:00
18
18
  default_executable: utopia
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency