Sha256: 16c7e879220dc55521e7dfeb198295289ea0f721a1bced3a8d71e7d5a51fce33

Contents?: true

Size: 1.75 KB

Versions: 280

Compression:

Stored size: 1.75 KB

Contents

module Sass::Script
  # A SassScript parse node representing a unary operation,
  # such as `-$b` or `not true`.
  #
  # Currently only `-`, `/`, and `not` are unary operators.
  class UnaryOperation < Node
    # @param operand [Script::Node] The parse-tree node
    #   for the object of the operator
    # @param operator [Symbol] The operator to perform
    def initialize(operand, operator)
      @operand = operand
      @operator = operator
      super()
    end

    # @return [String] A human-readable s-expression representation of the operation
    def inspect
      "(#{@operator.inspect} #{@operand.inspect})"
    end

    # @see Node#to_sass
    def to_sass(opts = {})
      operand = @operand.to_sass(opts)
      if @operand.is_a?(Operation) ||
          (@operator == :minus &&
           (operand =~ Sass::SCSS::RX::IDENT) == 0)
        operand = "(#{@operand.to_sass(opts)})"
      end
      op = Lexer::OPERATORS_REVERSE[@operator]
      op + (op =~ /[a-z]/ ? " " : "") + operand
    end

    # Returns the operand of the operation.
    #
    # @return [Array<Node>]
    # @see Node#children
    def children
      [@operand]
    end

    protected

    # Evaluates the operation.
    #
    # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
    # @return [Literal] The SassScript object that is the value of the operation
    # @raise [Sass::SyntaxError] if the operation is undefined for the operand
    def _perform(environment)
      operator = "unary_#{@operator}"
      literal = @operand.perform(environment)
      literal.send(operator)
    rescue NoMethodError => e
      raise e unless e.name.to_s == operator.to_s
      raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
    end
  end
end

Version data entries

280 entries across 279 versions & 6 rubygems

Version Path
haml_ejs-0.0.1 vendor/sass/lib/sass/script/unary_operation.rb
haml-3.1.3 vendor/sass/lib/sass/script/unary_operation.rb
sass-3.1.5 lib/sass/script/unary_operation.rb
haml-3.2.0.alpha.8 vendor/sass/lib/sass/script/unary_operation.rb
sass-3.1.4 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.11 lib/sass/script/unary_operation.rb
sass-3.1.3 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.9 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.8 lib/sass/script/unary_operation.rb
haml-3.2.0.alpha.5 vendor/sass/lib/sass/script/unary_operation.rb
haml-3.2.0.alpha.4 vendor/sass/lib/sass/script/unary_operation.rb
haml-3.1.2 vendor/sass/lib/sass/script/unary_operation.rb
sass-3.1.2 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.7 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.6 lib/sass/script/unary_operation.rb
radiant-1.0.0.rc1 vendor/plugins/haml/lib/sass/script/unary_operation.rb
haml-3.2.0.alpha.3 vendor/sass/lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.4 lib/sass/script/unary_operation.rb
sass-3.2.0.alpha.3 lib/sass/script/unary_operation.rb
sass-3.1.1 lib/sass/script/unary_operation.rb