Class: Compass::SassExtensions::Sprites::SpriteMap

Inherits:
Sass::Script::Literal
  • Object
show all
Includes:
ImageMethods, LayoutMethods, SpriteMethods
Defined in:
lib/compass/sass_extensions/sprites/sprite_map.rb

Constant Summary

Constants included from LayoutMethods

LayoutMethods::DIAGONAL, LayoutMethods::HORIZONTAL, LayoutMethods::SMART, LayoutMethods::VERTICAL

Constants included from SpriteMethods

Compass::SassExtensions::Sprites::SpriteMethods::SPRITE_VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LayoutMethods

#calculate_diagonal_dimensions, #calculate_diagonal_positions, #calculate_horizontal_positions, #calculate_repeat_extra_width!, #calculate_smart_positions, #calulate_vertical_postions, #compute_image_positions!, #diagonal?, #height_for_horizontal_layout, #height_for_vertical_layout, #horizontal?, #layout, #smart?, #tile_images_that_repeat, #vertical?, #width_for_horizontal_layout, #width_for_vertical_layout

Methods included from ImageMethods

#has_active?, #has_hover?, #has_target?, #image_for, #sprite_names

Methods included from SpriteMethods

#cleanup_old_sprites, #compute_image_metadata!, #filename, #generate, #generation_required?, #image_filenames, #init_engine, #init_images, #log, #mtime, #name_and_hash, #outdated?, #relativize, #save!, #size, #uniqueness_hash, #validate!

Constructor Details

#initialize(sprites, path, name, context, kwargs) ⇒ SpriteMap

Returns a new instance of SpriteMap.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 35

def initialize(sprites, path, name, context, kwargs)
  @image_names = sprites
  @path = path
  @name = name
  @kwargs = kwargs
  @kwargs['cleanup'] ||= Sass::Script::Bool.new(true)
  @kwargs['layout'] ||= Sass::Script::String.new('vertical')
  @images = nil
  @width = nil
  @height = nil
  @engine = nil
  @evaluation_context = context
  validate!
  compute_image_metadata!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 70

def method_missing(meth, *args, &block)
  if @evaluation_context.respond_to?(meth)
    @evaluation_context.send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#engineObject

Returns the value of attribute engine.



6
7
8
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6

def engine
  @engine
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6

def height
  @height
end

#image_namesObject

Returns the value of attribute image_names.



5
6
7
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5

def image_names
  @image_names
end

#imagesObject

Returns the value of attribute images.



6
7
8
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6

def images
  @images
end

#kwargsObject

Returns the value of attribute kwargs.



5
6
7
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5

def kwargs
  @kwargs
end

#mapObject

Returns the value of attribute map.



5
6
7
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5

def map
  @map
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5

def name
  @name
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5

def path
  @path
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6

def width
  @width
end

Class Method Details

.from_uri(uri, context, kwargs) ⇒ Object

Initialize a new sprite object from a relative file path the path is relative to the images_path confguration option



15
16
17
18
19
20
21
22
23
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 15

def self.from_uri(uri, context, kwargs)
  uri = uri.value
  path, name = Compass::SpriteImporter.path_and_name(uri)
  files = Compass::SpriteImporter.files(uri)
  sprites = files.map do |sprite|
    relative_name(sprite)
  end
  new(sprites, path, name, context, kwargs)
end

.relative_name(sprite) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 25

def self.relative_name(sprite)
  sprite = File.expand_path(sprite)
  Compass.configuration.sprite_load_path.each do |path|
    path = File.expand_path(path)
    if sprite.include?(path)
      return sprite.gsub("#{path}/", "")
    end
  end
end

Instance Method Details

#inspectObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 51

def inspect
  puts 'images'
  @images.each do |img|
    puts img.file
  end
  puts "options"
  @kwargs.each do |k,v|
    puts "#{k}:#{v}"
  end
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 66

def respond_to?(meth)
  super || @evaluation_context.respond_to?(meth)
end

#to_s(kwargs = self.kwargs) ⇒ Object



62
63
64
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 62

def to_s(kwargs = self.kwargs)
  sprite_url(self).value
end