utopia 0.9.33 → 0.9.34
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/lib/utopia/middleware/static.rb +1 -1
- data/lib/utopia/path.rb +11 -1
- data/lib/utopia/tags/gallery.rb +74 -36
- data/lib/utopia/version.rb +1 -1
- metadata +3 -3
|
@@ -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
|
|
data/lib/utopia/tags/gallery.rb
CHANGED
|
@@ -9,44 +9,74 @@ require 'fileutils'
|
|
|
9
9
|
|
|
10
10
|
class Utopia::Tags::Gallery
|
|
11
11
|
module Processes
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
class Thumbnail
|
|
13
|
+
def initialize(size = [800, 800])
|
|
14
|
+
@size = size
|
|
15
|
+
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
def call(img)
|
|
18
|
+
img.resize_to_fit(*@size)
|
|
19
|
+
end
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
img = img.resize_to_fit(300, 300)
|
|
37
|
+
shadow = img.dup
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
45
|
-
img
|
|
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 |
|
|
154
|
-
|
|
155
|
-
|
|
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 =
|
|
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|
|
data/lib/utopia/version.rb
CHANGED
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 9
|
|
8
|
-
-
|
|
9
|
-
version: 0.9.
|
|
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-
|
|
17
|
+
date: 2010-07-01 00:00:00 +12:00
|
|
18
18
|
default_executable: utopia
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|