Class: Ace::ImageThumbnailerFilter
- Inherits:
-
Filter
- Object
- Filter
- Ace::ImageThumbnailerFilter
show all
- Defined in:
- lib/ace/filters/image_thumbnailer.rb
Instance Method Summary
collapse
Methods inherited from Filter
#initialize
Constructor Details
This class inherits a constructor from Ace::Filter
Instance Method Details
#call(item, content) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ace/filters/image_thumbnailer.rb', line 30
def call(item, content)
puts "~ [THUMB] #{item.original_path}"
doc = Nokogiri::HTML(content)
doc.css("thumbnail").each do |thumb|
original_image_path = "content" + thumb[:src]
thumbnail_path = to_thumb("output" + thumb[:src])
generate_thumbnail(original_image_path, thumbnail_path, thumb[:src], thumb[:size] || 550)
thumb.replace(thumbnail_nodeset(thumb[:src], doc))
end
doc.to_s
end
|
#thumbnail_nodeset(link, doc) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/ace/filters/image_thumbnailer.rb', line 21
def thumbnail_nodeset(link, doc)
link_node = Nokogiri::XML::Node.new("a", doc)
image_node = Nokogiri::XML::Node.new("img", doc)
link_node.set_attribute("href", link)
image_node.set_attribute("src", to_thumb(link))
image_node.parent = link_node
return link_node
end
|
#to_thumb(path) ⇒ Object
17
18
19
|
# File 'lib/ace/filters/image_thumbnailer.rb', line 17
def to_thumb(path)
path.to_s.sub(/\.(\w+)$/, '_thumb.\1')
end
|