### Home Classes Methods

### In Files

- lib/sass/script/value/helpers.rb

### Methods

- #bool
- #hex_color
- #hsl_color
- #identifier
- #list
- #map
- #null
- #number
- #parse_complex_selector
- #parse_compound_selector
- #parse_selector
- #quoted_string
- #rgb_color
- #unquoted_string

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Script::Value::Helpers

Provides helper functions for creating sass values from within ruby methods. @since `3.3.0`

### Constants

VALID_UNIT

  @private

### Public Instance Methods

bool(value) click to toggle source

Construct a Sass Boolean.

@param value [Object] A ruby object that will be tested for truthiness. @return [Sass::Script::Value::Bool] whether the ruby value is truthy.

    # File lib/sass/script/value/helpers.rb, line 9
    def bool(value)
      Bool.new(value)
    end

hex_color(value, alpha = nil) click to toggle source

Construct a Sass Color from a hex color string.

@param value [::String] A string representing a hex color.

    The leading hash ("#") is optional.

@param alpha [::Number] The alpha channel. A number between 0 and 1. @return [Sass::Script::Value::Color] the color object

    # File lib/sass/script/value/helpers.rb, line 19
    def hex_color(value, alpha = nil)
      Color.from_hex(value, alpha)
    end

hsl_color(hue, saturation, lightness, alpha = nil) click to toggle source

Construct a Sass Color from hsl values.

@param hue [::Number] The hue of the color in degrees.

    A non-negative number, usually less than 360.

@param saturation [::Number] The saturation of the color.

    Must be between 0 and 100 inclusive.

@param lightness [::Number] The lightness of the color.

    Must be between 0 and 100 inclusive.

@param alpha [::Number] The alpha channel. A number between 0 and 1.

@return [Sass::Script::Value::Color] the color object

    # File lib/sass/script/value/helpers.rb, line 34
    def hsl_color(hue, saturation, lightness, alpha = nil)
      attrs = {:hue => hue, :saturation => saturation, :lightness => lightness}
      attrs[:alpha] = alpha if alpha
      Color.new(attrs)
    end

identifier(str) click to toggle source
Alias for: unquoted_string
list(*elements) click to toggle source

@overload list(*elements, separator)

    Create a space-separated list from the arguments given.
    @param elements [Array<Sass::Script::Value::Base>] Each argument will be a list element.
    @param separator [Symbol] Either :space or :comma.
    @return [Sass::Script::Value::List] The space separated list.

@overload list(array, separator)

    Create a space-separated list from the array given.
    @param array [Array<Sass::Script::Value::Base>] A ruby array of Sass values
      to make into a list.
    @return [Sass::Script::Value::List] The space separated list.

    # File lib/sass/script/value/helpers.rb, line 80
    def list(*elements)
      unless elements.last.is_a?(Symbol)
        raise ArgumentError.new("A list type of :space or :comma must be specified.")
      end
      separator = elements.pop
      if elements.size == 1 && elements.first.is_a?(Array)
        elements = elements.first
      end
      Sass::Script::Value::List.new(elements, separator)
    end

map(hash) click to toggle source

Construct a Sass map.

@param hash [Hash<Sass::Script::Value::Base,

    Sass::Script::Value::Base>] A Ruby map to convert to a Sass map.

@return [Sass::Script::Value::Map] The map.

    # File lib/sass/script/value/helpers.rb, line 96
    def map(hash)
      Map.new(hash)
    end

null() click to toggle source

Create a sass null value.

@return [Sass::Script::Value::Null]

    # File lib/sass/script/value/helpers.rb, line 103
    def null
      Sass::Script::Value::Null.new
    end

number(number, unit_string = nil) click to toggle source

Construct a Sass Number from a ruby number.

@param number [::Number] A numeric value. @param unit_string [::String] A unit string of the form

    `numeral_unit1 * numeral_unit2 ... / denominator_unit1 * denominator_unit2 ...`
    this is the same format that is returned by
    {Sass::Script::Value::Number#unit_str the `unit_str` method}

@see Sass::Script::Value::Number#unit_str

@return [Sass::Script::Value::Number] The sass number representing the given ruby number.

    # File lib/sass/script/value/helpers.rb, line 65
    def number(number, unit_string = nil)
      Number.new(number, *parse_unit_string(unit_string))
    end

parse_complex_selector(value, name = nil, allow_parent_ref = false) click to toggle source

Parses a user-provided complex selector.

A complex selector can contain combinators but cannot contain commas.

@param value [Sass::Script::Value::String, Sass::Script::Value::List]

    The selector to parse. This can be either a string or a list of
    strings.

@param name [Symbol, nil]

    If provided, the name of the selector argument. This is used
    for error reporting.

@param allow_parent_ref [Boolean]

    Whether the parsed selector should allow parent references.

@return [Sass::Selector::Sequence] The parsed selector. @throw [ArgumentError] if the parse failed for any reason.

    # File lib/sass/script/value/helpers.rb, line 161
    def parse_complex_selector(value, name = nil, allow_parent_ref = false)
      selector = parse_selector(value, name, allow_parent_ref)
      return seq if selector.members.length == 1

      err = "#{value.inspect} is not a complex selector"
      err = "$#{name.to_s.gsub('_', '-')}: #{err}" if name
      raise ArgumentError.new(err)
    end

parse_compound_selector(value, name = nil, allow_parent_ref = false) click to toggle source

Parses a user-provided compound selector.

A compound selector cannot contain combinators or commas.

@param value [Sass::Script::Value::String] The selector to parse. @param name [Symbol, nil]

    If provided, the name of the selector argument. This is used
    for error reporting.

@param allow_parent_ref [Boolean]

    Whether the parsed selector should allow parent references.

@return [Sass::Selector::SimpleSequence] The parsed selector. @throw [ArgumentError] if the parse failed for any reason.

    # File lib/sass/script/value/helpers.rb, line 182
    def parse_compound_selector(value, name = nil, allow_parent_ref = false)
      assert_type value, :String, name
      selector = parse_selector(value, name, allow_parent_ref)
      seq = selector.members.first
      sseq = seq.members.first
      if selector.members.length == 1 && seq.members.length == 1 &&
          sseq.is_a?(Sass::Selector::SimpleSequence)
        return sseq
      end

      err = "#{value.inspect} is not a compound selector"
      err = "$#{name.to_s.gsub('_', '-')}: #{err}" if name
      raise ArgumentError.new(err)
    end

parse_selector(value, name = nil, allow_parent_ref = false) click to toggle source

Parses a user-provided selector.

@param value [Sass::Script::Value::String, Sass::Script::Value::List]

    The selector to parse. This can be either a string, a list of
    strings, or a list of lists of strings as returned by `&`.

@param name [Symbol, nil]

    If provided, the name of the selector argument. This is used
    for error reporting.

@param allow_parent_ref [Boolean]

    Whether the parsed selector should allow parent references.

@return [Sass::Selector::CommaSequence] The parsed selector. @throw [ArgumentError] if the parse failed for any reason.

    # File lib/sass/script/value/helpers.rb, line 136
    def parse_selector(value, name = nil, allow_parent_ref = false)
      str = normalize_selector(value, name)
      begin
        Sass::SCSS::StaticParser.new(str, nil, nil, 1, 1, allow_parent_ref).parse_selector
      rescue Sass::SyntaxError => e
        err = "#{value.inspect} is not a valid selector: #{e}"
        err = "$#{name.to_s.gsub('_', '-')}: #{err}" if name
        raise ArgumentError.new(err)
      end
    end

quoted_string(str) click to toggle source

Create a quoted string.

@param str [::String] A ruby string. @return [Sass::Script::Value::String] A quoted string.

    # File lib/sass/script/value/helpers.rb, line 111
    def quoted_string(str)
      Sass::Script::String.new(str, :string)
    end

rgb_color(red, green, blue, alpha = nil) click to toggle source

Construct a Sass Color from rgb values.

@param red [::Number] The red component. Must be between 0 and 255 inclusive. @param green [::Number] The green component. Must be between 0 and 255 inclusive. @param blue [::Number] The blue component. Must be between 0 and 255 inclusive. @param alpha [::Number] The alpha channel. A number between 0 and 1.

@return [Sass::Script::Value::Color] the color object

    # File lib/sass/script/value/helpers.rb, line 48
    def rgb_color(red, green, blue, alpha = nil)
      attrs = {:red => red, :green => green, :blue => blue}
      attrs[:alpha] = alpha if alpha
      Color.new(attrs)
    end

unquoted_string(str) click to toggle source

Create an unquoted string.

@param str [::String] A ruby string. @return [Sass::Script::Value::String] An unquoted string.

    # File lib/sass/script/value/helpers.rb, line 119
    def unquoted_string(str)
      Sass::Script::String.new(str, :identifier)
    end

Also aliased as: identifier

[Validate]

Generated with the Darkfish Rdoc Generator 2.