Class: CSSquirt::ImageFileList

Inherits:
Rake::FileList
  • Object
show all
Defined in:
lib/cssquirt/file_list.rb

Instance Method Summary collapse

Instance Method Details

#to_css(prefix = "example", header = true) ⇒ Object

Public: return a CSS document of all images

prefix - an optional String to automatically prefix all class names with, useful

for namespacing, etc. Default: nil.

header - a optional Boolean value representing whether or not to include the

"generated by" credit in the header of the CSS document. Default: true.

Returns a CSS document as a String.



13
14
15
16
17
18
19
20
21
22
# File 'lib/cssquirt/file_list.rb', line 13

def to_css(prefix="example", header=true)
  css_classes = self.zip(self.to_images).map do |item|
    item_filelist,item_imagefile = item[0],item[1]
    item_imagefile.as_css_background_with_class( prefix + "-#{item_filelist.pathmap('%n')}" )
  end

  header_msg = "/* Generated with CSSquirt! (http://github.com/mroth/cssquirt/) */\n"
  header_msg = '' if header == false
  header_msg + css_classes.join("\n")
end

#to_imagesObject

Public: map the filelist to ImageFiles, handling any errors.

For now, this just reports errors to STDERR so they can be noted.

Returns an Array of ImageFiles.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cssquirt/file_list.rb', line 28

def to_images
  image_map = []
  self.each do |file|
    begin
      image_map << ImageFile.new(file)
    rescue Exception => e
     $stderr.puts "WARNING: skipped file - #{e.message}"
    end
  end
  image_map
end