Module: Compass::SassExtensions::Sprites::LayoutMethods

### Home Classes Methods

### In Files

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

### Methods

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

### 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::LayoutMethods

### Constants

DIAGONAL
HORIZONTAL
SMART
VERTICAL

### Public Instance Methods

calculate_diagonal_dimensions() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 101
    def calculate_diagonal_dimensions
      @width = @images.inject(0) {|sum, img| sum + img.width}
      @height = @images.inject(0) {|sum, img| sum + img.height}
    end

calculate_diagonal_positions() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 106
    def calculate_diagonal_positions
      previous = nil
      @images.each_with_index do |image, index|
        if previous.nil?
          previous = image
          image.top = @height - image.height
          image.left = 0
          next
        end
        image.top = previous.top - image.height
        image.left = previous.left + previous.width
        previous = image
      end
    end

calculate_horizontal_positions() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 121
    def calculate_horizontal_positions
      @images.each_with_index do |image, index|
        image.top = image.position.unit_str == '%' ? (@height - image.height) * (image.position.value / 100.0) : image.position.value
        next if index == 0
        last_image = @images[index-1]
        image.left = last_image.left + last_image.width + [image.spacing, last_image.spacing].max
      end
    end

calculate_repeat_extra_width!() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 77
    def calculate_repeat_extra_width!
      require 'rational' #for ruby 1.8.7
      m = @images.inject(1) {|m,img| img.repeat_x? ? m.lcm(img.width) : m}
      remainder = @width % m
      @width += (m - remainder) unless remainder.zero?
    end

calculate_smart_positions() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 84
    def calculate_smart_positions
      fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
      current_y = 0
      fitter.fit!.each do |row|
        current_x = 0
        row.images.each_with_index do |image, index|
          image.left = current_x
          image.top = current_y
          current_x += image.width
        end
        current_y += row.height
      end
      @width = fitter.width
      @height = fitter.height
    end

calulate_vertical_postions() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 130
    def calulate_vertical_postions
      @images.each_with_index do |image, index|
        image.left = (image.position.unit_str == "%" ? (@width - image.width) * (image.position.value / 100.0) : image.position.value).to_i
        next if index == 0
        last_image = @images[index-1]
        image.top = last_image.top + last_image.height + [image.spacing,  last_image.spacing].max
      end
    end

compute_image_positions!() click to toggle source

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

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 32
    def compute_image_positions!
      case layout
      when SMART
        calculate_smart_positions
      when DIAGONAL
        calculate_diagonal_dimensions
        calculate_diagonal_positions
      when HORIZONTAL
        @height = height_for_horizontal_layout
        calculate_horizontal_positions
        @width = width_for_horizontal_layout
      else
        @images.sort! do |a,b|
          if (b.size <=> a.size) === 0
            a.name <=> b.name
          else
            b.size <=> a.size
          end
        end

        @width = width_for_vertical_layout
        calulate_vertical_postions
        @height = height_for_vertical_layout
        if @images.any?(&:repeat_x?)
          calculate_repeat_extra_width!
          tile_images_that_repeat
         end
      end
    end

diagonal?() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 18
    def diagonal?
      layout == DIAGONAL
    end

height_for_horizontal_layout() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 144
    def height_for_horizontal_layout
      @height = @images.map {|image| image.height + image.offset}.max
    end

height_for_vertical_layout() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 139
    def height_for_vertical_layout
      last = @images.last
      last.top + last.height
    end

horizontal?() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 14
    def horizontal?
      layout == HORIZONTAL
    end

layout() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 26
    def layout
      @layout ||= @kwargs.get_var('layout').value
    end

smart?() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 10
    def smart?
      layout == SMART
    end

tile_images_that_repeat() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 62
    def tile_images_that_repeat
      @images.map {|img| img if img.repeat_x?}.compact.each do |image|
        x = image.left - (image.left / image.width).ceil * image.width
          while x < @width do
            begin
              img = image.dup
              img.top = image.top
              img.left = x.to_i
              @images << img
              x += image.width
            end
          end
        end
    end

vertical?() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 22
    def vertical?
      layout == VERTICAL
    end

width_for_horizontal_layout() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 148
    def width_for_horizontal_layout
      @images.inject(0) { |sum, image| sum += (image.width + image.spacing) }
    end

width_for_vertical_layout() click to toggle source

    # File lib/compass/sass_extensions/sprites/layout_methods.rb, line 152
    def width_for_vertical_layout
      @images.map { |image| image.width + image.offset }.max
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.