Module: Laze::Plugins::ImageCheck

Defined in:
lib/laze/plugins/image_check.rb

Overview

This plugin checks your stylesheets for missing images and spits out a log warning message when an image file referenced in your stylesheets could not be found.

This plugin is a decorator for StylesheetRenderer and fires after StylesheetRenderer#render.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applies_to?(kind) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


10
11
12
# File 'lib/laze/plugins/image_check.rb', line 10

def self.applies_to?(kind) #:nodoc:
  kind == 'Laze::Renderers::StylesheetRenderer'
end

Instance Method Details

#render(locals = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/laze/plugins/image_check.rb', line 14

def render(locals = {})
  Laze.debug 'Checking for missing stylesheet images'
  super.scan(/url\(\s*('|")?\s*(.+?)\s*\1?\s*\)/) do |match|
    filename = match[1].split("?", 2).first
    if %w(.gif .png .jpg .jpeg).include?(File.extname(filename))
      path = File.expand_path(File.join(Secretary.current.options[:source], 'input', options[:locals][:path], filename))
      unless File.exists?(path)
        Laze.warn "Image #{path} not found (#{options[:locals][:filename]})."
      end
    end
  end
end