Class: Middleman::Images::Manipulator
- Inherits:
-
Object
- Object
- Middleman::Images::Manipulator
- Defined in:
- lib/middleman-images/manipulator.rb
Instance Method Summary collapse
- #add(image) ⇒ Object
-
#initialize(app, ignore_original) ⇒ Manipulator
constructor
A new instance of Manipulator.
- #manipulate_resource_list(resources) ⇒ Object
- #preserve_original(resource) ⇒ Object
Constructor Details
#initialize(app, ignore_original) ⇒ Manipulator
Returns a new instance of Manipulator.
4 5 6 7 8 9 10 11 |
# File 'lib/middleman-images/manipulator.rb', line 4 def initialize(app, ignore_original) @app = app @images = [] @required_originals = [] @ignore_original = ignore_original @inspected_at = {} @destination_paths = [] end |
Instance Method Details
#add(image) ⇒ Object
13 14 15 16 |
# File 'lib/middleman-images/manipulator.rb', line 13 def add(image) images << image unless @destination_paths.include?(image.destination_path) @destination_paths << image.destination_path end |
#manipulate_resource_list(resources) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/middleman-images/manipulator.rb', line 22 def manipulate_resource_list(resources) app.logger.info "== Images: Registering images to process. This may take a while…" resources.each do |resource| next unless inspect?(resource) app.logger.debug "== Images: Inspecting #{resource.destination_path} for images to process." begin # We inspect templates by triggering the render method on them. This way our # image_tag and image_path helpers will get called and register the images. resource.render({}, {}) rescue => e app.logger.debug e app.logger.debug "== Images: There was an error inspecting #{resource.destination_path}. Images for this resource will not be processed." end end app.logger.info "== Images: All images have been registered." ignore_orginal_resources(resources) if ignore_original resources + images end |
#preserve_original(resource) ⇒ Object
18 19 20 |
# File 'lib/middleman-images/manipulator.rb', line 18 def preserve_original(resource) required_originals << resource.source_file end |