Sha256: d6686d971bb20c905201a5ee8d02be8002e0a6d11dc4fe1fb3b4c11a7ff0aa13

Contents?: true

Size: 1.9 KB

Versions: 484

Compression:

Stored size: 1.9 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

    # @see Node#deep_copy
    def deep_copy
      node = dup
      node.instance_variable_set('@operand', @operand.deep_copy)
      node
    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

484 entries across 199 versions & 9 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.17/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.15/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.18/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.19/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.15/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.19/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.18/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.17/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.17/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.18/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/unary_operation.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.15/lib/sass/script/unary_operation.rb