Class: Utopia::Tags::Gallery
- Inherits:
-
Object
- Object
- Utopia::Tags::Gallery
- Defined in:
- lib/utopia/tags/gallery.rb
Defined Under Namespace
Classes: ImagePath
Constant Summary collapse
- PROCESSES =
{ :photo_thumbnail => lambda do |img| img = img.resize_to_fit(300, 300) shadow = img.flop shadow = shadow.colorize(1, 1, 1, "gray50") shadow.background_color = "white" shadow.border!(10, 10, "white") shadow = shadow.blur_image(0, 5) shadow.composite(img, 5, 5, Magick::OverCompositeOp) end, :thumbnail => lambda do |img| img = img.resize_to_fit(300, 300) end, :large => lambda{|img| img.resize_to_fit(768, 768)} }
- CACHE_DIR =
"_cache"
Class Method Summary collapse
Instance Method Summary collapse
- #images(options = {}) ⇒ Object
-
#initialize(node, path) ⇒ Gallery
constructor
A new instance of Gallery.
- #metadata ⇒ Object
- #processed_image(image_path, processes) ⇒ Object
Constructor Details
Class Method Details
.call(transaction, state) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/utopia/tags/gallery.rb', line 155 def self.call(transaction, state) gallery = new(transaction.[-2].node, Utopia::Path.create(state["path"] || "./")) = gallery. .default = {} tag_name = state["tag"] || "img" = {} [:process] = state["process"] filter = Regexp.new(state["filter"]) if state["filter"] transaction.tag("div", "class" => "gallery") do |node| images = gallery.images().sort do |a, b| if ([a.original.basename]["order"] && [b.original.basename]["order"]) [a.original.basename]["order"] <=> [b.original.basename]["order"] else a.original.basename <=> b.original.basename end end images.each do |path| next if filter and !filter.match(path.original.basename) alt_text = [path.original.basename]["caption"] transaction.tag(tag_name, "src" => path, "alt" => alt_text) end end end |
Instance Method Details
#images(options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/utopia/tags/gallery.rb', line 101 def images( = {}) [:filter] ||= /(\.jpg|\.png)$/ paths = [] local_path = @node.local_path(@path) Utopia::LOG.debug("Scanning #{local_path}") Dir.entries(local_path).each do |filename| next unless filename.match([:filter]) Utopia::LOG.debug("Filename #{filename} matched filter...") fullpath = File.join(local_path, filename) paths << ImagePath.new(@path + filename) end if [:process] paths.each do |path| processed_image(path, [:process]) end end return paths end |
#metadata ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/utopia/tags/gallery.rb', line 91 def = @node.local_path(@path + "gallery.yaml") if File.exist? return YAML::load(File.read()) else return {} end end |
#processed_image(image_path, processes) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/utopia/tags/gallery.rb', line 128 def processed_image(image_path, processes) # Create the local cache directory if it doesn't exist already local_cache_path = @node.local_path(image_path.cache_root) unless File.exist? local_cache_path FileUtils.mkdir local_cache_path end # Calculate the new name for the processed image local_original_path = @node.local_path(image_path.original) if processes.kind_of? String processes = processes.split(",") end processes.each do |process| local_processed_path = @node.local_path(image_path.processed(process)) unless File.exists? local_processed_path image = Magick::ImageList.new(local_original_path) processed_image = PROCESSES[process.to_sym].call(image) processed_image.write(local_processed_path) end end end |