Class: Compass::SassExtensions::Sprites::SpriteMap
- Inherits:
-
Sass::Script::Value::Base
- Object
- Sass::Script::Value::Base
- Compass::SassExtensions::Sprites::SpriteMap
- Includes:
- ImageMethods, LayoutMethods, SpriteMethods, Sass::Script::Value::Helpers
- 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 ImageMethods
Constants included from SpriteMethods
Compass::SassExtensions::Sprites::SpriteMethods::SPRITE_VERSION
Instance Attribute Summary collapse
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#height ⇒ Object
Returns the value of attribute height.
-
#image_names ⇒ Object
Returns the value of attribute image_names.
-
#images ⇒ Object
Returns the value of attribute images.
-
#kwargs ⇒ Object
Returns the value of attribute kwargs.
-
#map ⇒ Object
Returns the value of attribute map.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.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. - .relative_name(sprite) ⇒ Object
Instance Method Summary collapse
-
#initialize(sprites, path, name, context, kwargs) ⇒ SpriteMap
constructor
A new instance of SpriteMap.
- #inspect ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #respond_to?(meth) ⇒ Boolean
- #sort_method ⇒ Object
- #to_s(kwargs = self.kwargs) ⇒ Object
Methods included from LayoutMethods
#compute_image_positions!, #diagonal?, #horizontal?, #layout, #smart?, #vertical?
Methods included from ImageMethods
#get_magic_selector_image, #has_active?, #has_focus?, #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
Constructor Details
#initialize(sprites, path, name, context, kwargs) ⇒ SpriteMap
Returns a new instance of SpriteMap.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 37 def initialize(sprites, path, name, context, kwargs) @image_names = sprites @path = path @name = name @kwargs = kwargs @kwargs['cleanup'] ||= bool(true) @kwargs['layout'] ||= identifier('vertical') @kwargs['sort_by'] ||= identifier('none') @images = nil @width = nil @height = nil @engine = nil @evaluation_context = context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 76 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
#engine ⇒ Object
Returns the value of attribute engine.
6 7 8 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6 def engine @engine end |
#height ⇒ Object
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_names ⇒ Object
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 |
#images ⇒ Object
Returns the value of attribute images.
6 7 8 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 6 def images @images end |
#kwargs ⇒ Object
Returns the value of attribute kwargs.
5 6 7 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5 def kwargs @kwargs end |
#map ⇒ Object
Returns the value of attribute map.
5 6 7 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5 def map @map end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 5 def path @path end |
#width ⇒ Object
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
16 17 18 19 20 21 22 23 24 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 16 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
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 26 def self.relative_name(sprite) sprite = File.(sprite) Compass.configuration.sprite_load_path.each do |path| path_with_slash = "#{File.(path)}/" if sprite.include?(path_with_slash) return sprite.gsub(path_with_slash, '') end end end |
Instance Method Details
#inspect ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 57 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
72 73 74 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 72 def respond_to?(meth) super || @evaluation_context.respond_to?(meth) end |
#sort_method ⇒ Object
53 54 55 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 53 def sort_method @kwargs['sort_by'].value end |
#to_s(kwargs = self.kwargs) ⇒ Object
68 69 70 |
# File 'lib/compass/sass_extensions/sprites/sprite_map.rb', line 68 def to_s(kwargs = self.kwargs) sprite_url(self).value end |