Class: Utopia::Tags::Gallery::Container
- Inherits:
-
Object
- Object
- Utopia::Tags::Gallery::Container
- Includes:
- Enumerable
- Defined in:
- lib/utopia/tags/gallery/container.rb
Instance Method Summary collapse
- #each(options = {}) ⇒ Object
-
#initialize(node, path, processes = Processes::DEFAULT) ⇒ Container
constructor
A new instance of Container.
- #metadata ⇒ Object
- #process!(image_path, processes) ⇒ Object
Constructor Details
Instance Method Details
#each(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/utopia/tags/gallery/container.rb', line 99 def each( = {}) return to_enum(:each, ) unless block_given? [:filter] ||= /(jpg|png)$/i paths = [] local_path = @node.local_path(@path) Dir.entries(local_path).each do |filename| next unless filename.match([:filter]) path = Path.new(@path + filename) process!(path, [:process]) if [:process] yield path end end |
#metadata ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/utopia/tags/gallery/container.rb', line 89 def = @node.local_path(@path + "gallery.yaml") if File.exist? return YAML::load(File.read()) else return {} end end |
#process!(image_path, processes) ⇒ Object
118 119 120 121 122 123 124 125 126 127 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 154 155 |
# File 'lib/utopia/tags/gallery/container.rb', line 118 def process!(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(",").collect{|p| p.split(":")} end processes.each do |process_name, extension| process_name = process_name.to_sym process = @processes[process_name] extension ||= process.default_extension(image_path) image_path.extensions[process_name] = extension if extension local_processed_path = @node.local_path(image_path.processed(process_name)) unless File.exists? local_processed_path image = Magick::ImageList.new(local_original_path) image.scene = 0 processed_image = process.call(image) processed_image.write(local_processed_path) # Run GC to free up any memory. image = processed_image = nil GC.start if defined? GC end end end |