Module: Compass::SassExtensions::Sprites::SpriteMethods

### Home Classes Methods

### In Files

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

### Methods

- #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!

### 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::Sprites::SpriteMethods

### Constants

SPRITE_VERSION

  Changing this string will invalidate all previously generated sprite images. We should do so only when the packing algorithm changes

### Public Instance Methods

cleanup_old_sprites() click to toggle source

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 70
    def cleanup_old_sprites
      Dir[File.join(Compass.configuration.images_path, "#{path}-s*.png")].each do |file|
        log :remove, file
        FileUtils.rm file
        Compass.configuration.run_sprite_removed(file)
      end
    end

compute_image_metadata!() click to toggle source

Calculates the overal image dimensions collects image sizes and input parameters for each sprite Calculates the height

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 13
    def compute_image_metadata!
      @width = 0
      init_images
      compute_image_positions!
      init_engine
    end

filename() click to toggle source

The on-the-disk filename of the sprite

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 48
    def filename
      File.join(Compass.configuration.generated_images_path, name_and_hash)
    end

generate() click to toggle source

Generate a sprite image if necessary

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 57
    def generate
      if generation_required?
        if kwargs.get_var('cleanup').value
          cleanup_old_sprites
        end
        engine.construct_sprite
        Compass.configuration.run_sprite_generated(engine.canvas)
        save!
      else
        log :unchanged, filename
      end
    end

generation_required?() click to toggle source

Does this sprite need to be generated

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 79
    def generation_required?
      !File.exists?(filename) || outdated? ||  options[:force]
    end

image_filenames() click to toggle source

All the full-path filenames involved in this sprite

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 111
    def image_filenames
      @images.map(&:file)
    end

init_engine() click to toggle source

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 20
    def init_engine
      @engine = eval("::Compass::SassExtensions::Sprites::#{modulize}Engine.new(nil, nil, nil)")
      @engine.width = @width
      @engine.height = @height
      @engine.images = @images
    end

init_images() click to toggle source

Creates the Sprite::Image objects for each image and calculates the width

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 28
    def init_images
      @images = image_names.collect do |relative_file|
        Image.new(self, relative_file, kwargs)
      end
    end

log(action, filename, *extra) click to toggle source

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 133
    def log(action, filename, *extra)
      if options[:compass] && options[:compass][:logger] && !options[:quiet]
        options[:compass][:logger].record(action, relativize(filename), *extra)
      end
    end

mtime() click to toggle source

Mtime of the sprite file

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 124
    def mtime
      @mtime ||= File.mtime(filename)
    end

name_and_hash() click to toggle source

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 43
    def name_and_hash
      "#{path}-s#{uniqueness_hash}.png"
    end

outdated?() click to toggle source

Checks whether this sprite is outdated

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 116
    def outdated?
      if File.exists?(filename)
        return @images.any? {|image| image.mtime.to_i > self.mtime.to_i }
      end
      true
    end

relativize(path) click to toggle source

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 52
    def relativize(path)
      Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s rescue path
    end

save!() click to toggle source

Saves the sprite engine

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 101
    def save!
      FileUtils.mkdir_p(File.dirname(filename))
      saved = engine.save(filename)
      log :create, filename
      Compass.configuration.run_sprite_saved(filename)
      @mtime = nil if saved
      saved
    end

size() click to toggle source

Calculate the size of the sprite

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 129
    def size
      [width, height]
    end

uniqueness_hash() click to toggle source

Returns the uniqueness hash for this sprite object

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 84
    def uniqueness_hash
      @uniqueness_hash ||= begin
        sum = Digest::MD5.new
        sum << SPRITE_VERSION
        sum << path
        sum << layout
        images.each do |image|
          [:relative_file, :height, :width, :repeat, :spacing, :position, :digest].each do |attr|
            sum << image.send(attr).to_s
          end
        end
        sum.hexdigest[0...10]
      end
      @uniqueness_hash
    end

validate!() click to toggle source

Validates that the sprite_names are valid sass

    # File lib/compass/sass_extensions/sprites/sprite_methods.rb, line 35
    def validate!
      for sprite_name in sprite_names
        unless sprite_name =~ /\A#{Sass::SCSS::RX::IDENT}\Z/
          raise Sass::SyntaxError, "#{sprite_name} must be a legal css identifier"
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.