Module: Compass::Core::SassExtensions::Functions::Lists

### Home Classes Methods

### In Files

- lib/compass/core/sass_extensions/functions/lists.rb

### Methods

- #_compass_list
- #_compass_list_size
- #_compass_nth
- #_compass_slice
- #_compass_space_list
- #assert_list
- #blank
- #compact
- #first_value_of
- #reject

### Class/Module Index

Quicksearch

- Compass
- Compass::BrowserSupport
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Watch
- Compass::Core
- Compass::Core::CanIUse
- Compass::Core::SassExtensions
- Compass::Core::SassExtensions::Functions
- Compass::Core::SassExtensions::Functions::Colors
- Compass::Core::SassExtensions::Functions::Configuration
- Compass::Core::SassExtensions::Functions::Constants
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport
- Compass::Core::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::Core::SassExtensions::Functions::Display
- Compass::Core::SassExtensions::Functions::Enumerate
- Compass::Core::SassExtensions::Functions::Env
- Compass::Core::SassExtensions::Functions::Files
- Compass::Core::SassExtensions::Functions::FontFiles
- Compass::Core::SassExtensions::Functions::GradientSupport
- Compass::Core::SassExtensions::Functions::GradientSupport::Assertions
- Compass::Core::SassExtensions::Functions::GradientSupport::CSS3AngleToSVGConverter
- Compass::Core::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::Core::SassExtensions::Functions::GradientSupport::Functions
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient
- Compass::Core::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::Core::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::Core::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::Core::SassExtensions::Functions::ImageSize
- Compass::Core::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::Core::SassExtensions::Functions::ImageSize::JPEG
- Compass::Core::SassExtensions::Functions::InlineImage
- Compass::Core::SassExtensions::Functions::Lists
- Compass::Core::SassExtensions::Functions::Math
- Compass::Core::SassExtensions::Functions::SassDeclarationHelper
- Compass::Core::SassExtensions::Functions::Selectors
- Compass::Core::SassExtensions::Functions::Urls
- Compass::Core::SassExtensions::Functions::Urls::FontUrl
- Compass::Core::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::Core::SassExtensions::Functions::Urls::ImageUrl
- Compass::Core::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::Error
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::HasDeprecatedConstantsFromCore
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::Util
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Tree
- Sass::Tree::Node

No matching classes.

# Compass::Core::SassExtensions::Functions::Lists

### Public Instance Methods

_compass_list(arg) click to toggle source

Returns a list object from a value that was passed. This can be used to unpack a space separated list that got turned into a string by sass before it was passed to a mixin.

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 43
    def _compass_list(arg)
      if arg.is_a?(Sass::Script::Value::List)
        list(arg.value.dup, arg.separator)
      else
        list(arg, :space)
      end
    end

_compass_list_size(list) click to toggle source

Returns the size of the list.

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 62
    def _compass_list_size(list)
      assert_list list
      number(list.value.size)
    end

_compass_nth(list, place) click to toggle source

Get the nth value from a list

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 29
    def _compass_nth(list, place)
      assert_type list, :List
      if place.value == "first"
        list.value.first
      elsif place.value == "last"
        list.value.last
      else
        list.value[place.value - 1]
      end
    end

_compass_slice(list, start_index, end_index = nil) click to toggle source

slice a sublist from a list

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 68
    def _compass_slice(list, start_index, end_index = nil)
      end_index ||= number(-1)
      start_index = start_index.value
      end_index = end_index.value
      start_index -= 1 unless start_index < 0
      end_index -= 1 unless end_index < 0
      list(list.values[start_index..end_index], list.separator)
    end

_compass_space_list(list) click to toggle source

If the argument is a list, it will return a new list that is space delimited Otherwise it returns a new, single element, space-delimited list.

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 53
    def _compass_space_list(list)
      if list.is_a?(Sass::Script::Value::List)
        list(list.value.dup, :space)
      else
        list(list, :space)
      end
    end

blank(obj) click to toggle source

Returns true when the object is false, an empty string, or an empty list

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 4
    def blank(obj)
      case obj
      when Sass::Script::Value::Bool, Sass::Script::Value::Null
        bool(!obj.to_bool)
      when Sass::Script::Value::String
        bool(obj.value.strip.size == 0)
      when Sass::Script::Value::List
        bool(obj.value.size == 0 || obj.value.all?{|el| blank(el).to_bool})
      else
        bool(false)
      end
    end

compact(*args) click to toggle source

Returns a new list after removing any non-true values

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 18
    def compact(*args)
      sep = :comma
      if args.size == 1 && args.first.is_a?(Sass::Script::Value::List)
        list = args.first
        args = list.value
        sep = list.separator
      end
      list(args.reject{|a| !a.to_bool}, sep)
    end

first_value_of(list) click to toggle source

returns the first value of a space delimited list.

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 83
    def first_value_of(list)
      if list.is_a?(Sass::Script::Value::String)
        r = list.value.split(/\s+/).first
        list.type == :identifier ? identifier(r) : quoted_string(r)
      elsif list.is_a?(Sass::Script::Value::List)
        list.value.first
      else
        list
      end
    end

reject(list, *values) click to toggle source

removes the given values from the list.

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 78
    def reject(list, *values)
      list(list.value.reject{|v| values.any?{|o| v == o}}, list.separator)
    end

### Protected Instance Methods

assert_list(value) click to toggle source

    # File lib/compass/core/sass_extensions/functions/lists.rb, line 96
    def assert_list(value)
      unless value.is_a?(Sass::Script::Value::List)
        raise ArgumentError.new("#{value.inspect} is not a list")
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.