### Home Classes Methods

### In Files

- lib/compass/sass_extensions/functions/sprites.rb

### Namespace

- MODULE Compass::SassExtensions::Functions::Sprites::VariableReader

### Methods

- #convert_sprite_name
- #inline_sprite
- #missing_image!
- #missing_sprite!
- #reversed_color_names
- #sprite
- #sprite_does_not_have_parent
- #sprite_file
- #sprite_has_selector
- #sprite_image
- #sprite_map
- #sprite_map_name
- #sprite_names
- #sprite_path
- #sprite_position
- #sprite_url
- #verify_map
- #verify_sprite

### Class/Module Index

Quicksearch

- Compass
- Compass::Actions
- Compass::AppIntegration
- Compass::AppIntegration::Helpers
- Compass::AppIntegration::Rails
- Compass::AppIntegration::StandAlone
- Compass::AppIntegration::StandAlone::ConfigurationDefaults
- Compass::AppIntegration::StandAlone::Installer
- Compass::BrowserSupport
- Compass::Commands
- Compass::Commands::Base
- Compass::Commands::CleanProject
- Compass::Commands::CleanProjectOptionsParser
- Compass::Commands::CompileProjectOptionsParser
- Compass::Commands::ConfigurationOptionsParser
- Compass::Commands::CreateProject
- Compass::Commands::CreateProjectOptionsParser
- Compass::Commands::Default
- Compass::Commands::DefaultOptionsParser
- Compass::Commands::ExtensionCommand
- Compass::Commands::ExtensionOptionsParser
- Compass::Commands::ExtensionsOptionParser
- Compass::Commands::GenerateGridBackground
- Compass::Commands::GridBackgroundOptionsParser
- Compass::Commands::Help
- Compass::Commands::HelpOptionsParser
- Compass::Commands::Imports
- Compass::Commands::InstallerCommand
- Compass::Commands::Interactive
- Compass::Commands::InteractiveOptionsParser
- Compass::Commands::ListFrameworks
- Compass::Commands::MemoryDebugger
- Compass::Commands::PrintVersion
- Compass::Commands::ProjectBase
- Compass::Commands::ProjectStats
- Compass::Commands::Registry
- Compass::Commands::Sprite
- Compass::Commands::SpriteOptionsParser
- Compass::Commands::StampPattern
- Compass::Commands::StampPatternOptionsParser
- Compass::Commands::StatsOptionsParser
- Compass::Commands::StructureOptionsParser
- Compass::Commands::UnpackExtension
- Compass::Commands::UpdateProject
- Compass::Commands::ValidateProject
- Compass::Commands::ValidationOptionsParser
- Compass::Commands::VersionOptionsParser
- Compass::Commands::WatchProject
- Compass::Commands::WatchProjectOptionsParser
- Compass::Commands::WriteConfiguration
- Compass::Compiler
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Comments
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::FileData
- Compass::Configuration::Helpers
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Serialization
- Compass::Error
- Compass::Exec
- Compass::Exec::CommandOptionParser
- Compass::Exec::GlobalOptionsParser
- Compass::Exec::Helpers
- Compass::Exec::ProjectOptionsParser
- Compass::Exec::SubCommandUI
- Compass::Exec::SwitchUI
- Compass::FilesystemConflict
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::GridBuilder
- Compass::Installers
- Compass::Installers::BareInstaller
- Compass::Installers::Base
- Compass::Installers::Manifest
- Compass::Installers::Manifest::Entry
- Compass::Installers::ManifestInstaller
- Compass::Installers::TemplateContext
- Compass::Logger
- Compass::MissingDependency
- Compass::NullLogger
- Compass::PNG
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::SassExtensions::Functions::Colors
- Compass::SassExtensions::Functions::Constants
- Compass::SassExtensions::Functions::CrossBrowserSupport
- Compass::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::SassExtensions::Functions::Display
- Compass::SassExtensions::Functions::Enumerate
- Compass::SassExtensions::Functions::Env
- Compass::SassExtensions::Functions::FontFiles
- Compass::SassExtensions::Functions::GradientSupport
- Compass::SassExtensions::Functions::GradientSupport::Assertions
- Compass::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::SassExtensions::Functions::GradientSupport::Functions
- Compass::SassExtensions::Functions::GradientSupport::Gradient
- Compass::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::SassExtensions::Functions::ImageSize
- Compass::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::SassExtensions::Functions::ImageSize::JPEG
- Compass::SassExtensions::Functions::InlineImage
- Compass::SassExtensions::Functions::Lists
- Compass::SassExtensions::Functions::Math
- Compass::SassExtensions::Functions::Selectors
- Compass::SassExtensions::Functions::Sprites
- Compass::SassExtensions::Functions::Sprites::VariableReader
- Compass::SassExtensions::Functions::Urls
- Compass::SassExtensions::Functions::Urls::FontUrl
- Compass::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::SassExtensions::Functions::Urls::ImageUrl
- Compass::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::SassExtensions::Sprites
- Compass::SassExtensions::Sprites::ChunkyPngEngine
- Compass::SassExtensions::Sprites::Engine
- Compass::SassExtensions::Sprites::Image
- Compass::SassExtensions::Sprites::ImageMethods
- Compass::SassExtensions::Sprites::ImageRow
- Compass::SassExtensions::Sprites::LayoutMethods
- Compass::SassExtensions::Sprites::RowFitter
- Compass::SassExtensions::Sprites::SpriteMap
- Compass::SassExtensions::Sprites::SpriteMethods
- Compass::SpriteException
- Compass::SpriteImporter
- Compass::Sprites
- Compass::Sprites::Binding
- Compass::Stats
- Compass::Stats::CssFile
- Compass::Stats::SassFile
- Compass::Stats::StatsVisitor
- Compass::TestCase
- Compass::Util
- Compass::Version
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Tree
- Sass::Tree::Node
- QuickCache

No matching classes.

# Compass::SassExtensions::Functions::Sprites

### Constants

VALID_SELECTORS
ZERO

### Public Instance Methods

inline_sprite(map) click to toggle source

Returns the sprite file as an inline image

    @include "icon/*.png";
     #{$icon-sprite-base-class} {
       background-image: inline-sprite($icon-sprites);
      }

    # File lib/compass/sass_extensions/functions/sprites.rb, line 30
    def inline_sprite(map)
      verify_map(map, "sprite-url")
      map.generate
      inline_image(sprite_path(map))
    end

sprite(map, sprite, offset_x = ZERO, offset_y = ZERO) click to toggle source

Returns the image and background position for use in a single shorthand property:

    $icons: sprite-map("icons/*.png"); // contains icons/new.png among others.
    background: sprite($icons, new) no-repeat;

Becomes:

    background: url('/images/icons.png?12345678') 0 -24px no-repeat;

    # File lib/compass/sass_extensions/functions/sprites.rb, line 60
    def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO)
      sprite = convert_sprite_name(sprite)
      verify_map(map)
      unless sprite.is_a?(Sass::Script::String)
        raise Sass::SyntaxError, %(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
      end
      url = sprite_url(map)
      position = sprite_position(map, sprite, offset_x, offset_y)
      Sass::Script::List.new([url] + position.value, :space)
    end

sprite_does_not_have_parent(map, sprite) click to toggle source

Returns boolean if sprite has a parent

    # File lib/compass/sass_extensions/functions/sprites.rb, line 96
    def sprite_does_not_have_parent(map, sprite)
      sprite = convert_sprite_name(sprite)
      verify_map map
      verify_sprite sprite
      Sass::Script::Bool.new map.image_for(sprite.value).parent.nil?
    end

sprite_file(map, sprite) click to toggle source

Returns the path to the original image file for the sprite with the given name

    # File lib/compass/sass_extensions/functions/sprites.rb, line 83
    def sprite_file(map, sprite)
      sprite = convert_sprite_name(sprite)
      verify_map(map, "sprite")
      verify_sprite(sprite)
      if image = map.image_for(sprite.value)
        Sass::Script::String.new(image.file)
      else
        missing_image!(map, sprite)
      end
    end

sprite_has_selector(map, sprite, selector) click to toggle source

Returns boolean if sprite has the selector

    # File lib/compass/sass_extensions/functions/sprites.rb, line 106
    def sprite_has_selector(map, sprite, selector)
      sprite = convert_sprite_name(sprite)
      verify_map map
      verify_sprite sprite
      unless VALID_SELECTORS.include?(selector.value)
        raise Sass::SyntaxError, "Invalid Selctor did you mean one of: #{VALID_SELECTORS.join(', ')}"
      end
      Sass::Script::Bool.new map.send(:"has_#{selector.value}?", sprite.value)
    end

sprite_image(*args) click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 173
    def sprite_image(*args)
      raise Sass::SyntaxError, %(The sprite-image() function has been replaced by sprite(). See http://compass-style.org/help/tutorials/spriting/ for more information.)
    end

sprite_map(glob, kwargs = {}) click to toggle source

Creates a Compass::SassExtensions::Sprites::SpriteMap object. A sprite map, when used in a property is the same as calling sprite-url. So the following background properties are equivalent:

    $icons: sprite-map("icons/*.png");
    background: sprite-url($icons) no-repeat;
    background: $icons no-repeat;

The sprite map object will generate the sprite map image, if necessary, the first time it is converted to a url. Simply constructing it has no side-effects.

    # File lib/compass/sass_extensions/functions/sprites.rb, line 46
    def sprite_map(glob, kwargs = {})
      kwargs.extend VariableReader
      Compass::SassExtensions::Sprites::SpriteMap.from_uri(glob, self, kwargs)
    end

sprite_map_name(map) click to toggle source

Returns the name of a sprite map The name is derived from the folder than contains the sprites.

    # File lib/compass/sass_extensions/functions/sprites.rb, line 76
    def sprite_map_name(map)
      verify_map(map, "sprite-map-name")
      Sass::Script::String.new(map.name)
    end

sprite_names(map) click to toggle source

Returns a list of all sprite names

    # File lib/compass/sass_extensions/functions/sprites.rb, line 14
    def sprite_names(map)
      Sass::Script::List.new(map.sprite_names.map { |f| Sass::Script::String.new(f) }, ' ')
    end

sprite_path(map) click to toggle source

Returns the system path of the sprite file

    # File lib/compass/sass_extensions/functions/sprites.rb, line 20
    def sprite_path(map)
      Sass::Script::String.new(map.name_and_hash)
    end

sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO) click to toggle source

Returns the position for the original image in the sprite. This is suitable for use as a value to background-position:

    $icons: sprite-map("icons/*.png");
    background-position: sprite-position($icons, new);

Might generate something like:

    background-position: 0 -34px;

You can adjust the background relative to this position by passing values for `$offset-x` and `$offset-y`:

    $icons: sprite-map("icons/*.png");
    background-position: sprite-position($icons, new, 3px, -2px);

Would change the above output to:

    background-position: 3px -36px;

    # File lib/compass/sass_extensions/functions/sprites.rb, line 146
    def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO)
      assert_type offset_x, :Number
      assert_type offset_y, :Number
      sprite = convert_sprite_name(sprite)
      verify_map(map, "sprite-position")
      unless sprite && sprite.is_a?(Sass::Script::String)
        raise Sass::SyntaxError, %(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
      end
      image = map.image_for(sprite.value)
      unless image
        missing_image!(map, sprite)
      end
      if offset_x.unit_str == "%"
        x = offset_x # CE: Shouldn't this be a percentage of the total width?
      else
        x = offset_x.value - image.left
        x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
      end
      y = offset_y.value - image.top
      y = Sass::Script::Number.new(y, y == 0 ? [] : ["px"])
      Sass::Script::List.new([x, y],:space)
    end

sprite_url(map) click to toggle source

Returns a url to the sprite image.

    # File lib/compass/sass_extensions/functions/sprites.rb, line 120
    def sprite_url(map)
      verify_map(map, "sprite-url")
      map.generate
      generated_image_url(Sass::Script::String.new("#{map.path}-s#{map.uniqueness_hash}.png"))
    end

### Protected Instance Methods

convert_sprite_name(sprite) click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 187
    def convert_sprite_name(sprite)
      case sprite
        when Sass::Script::Color
          Sass::Script::String.new(reversed_color_names[sprite.rgb])
        when Sass::Script::Bool
          Sass::Script::String.new(sprite.to_s)
        else
          sprite
      end
    end

missing_image!(map, sprite) click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 210
    def missing_image!(map, sprite)
      raise Sass::SyntaxError, "No sprite called #{sprite} found in sprite map #{map.path}/#{map.name}. Did you mean one of: #{map.sprite_names.join(", ")}"
    end

missing_sprite!(function_name) click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 214
    def missing_sprite!(function_name)
      raise Sass::SyntaxError, %(The first argument to #{function_name}() must be a sprite map. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
    end

reversed_color_names() click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 179
    def reversed_color_names
      if Sass::Script::Color.const_defined?(:HTML4_COLORS_REVERSE)
        Sass::Script::Color::HTML4_COLORS_REVERSE
      else
        Sass::Script::Color::COLOR_NAMES_REVERSE
      end
    end

verify_map(map, error = "sprite") click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 198
    def verify_map(map, error = "sprite")
      unless map.is_a?(Compass::SassExtensions::Sprites::SpriteMap)
        missing_sprite!(error)
      end
    end

verify_sprite(sprite) click to toggle source

    # File lib/compass/sass_extensions/functions/sprites.rb, line 204
    def verify_sprite(sprite)
      unless sprite.is_a?(Sass::Script::String)
        raise Sass::SyntaxError, %(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.