Class: Sass::Script::UnaryOperation

Inherits:
Node show all
Defined in:
/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb

Overview

A SassScript parse node representing a unary operation, such as -$b or not true.

Currently only -, /, and not are unary operators.

Instance Method Summary

Methods inherited from Node

#dasherize, #perform

Constructor Details

- (UnaryOperation) initialize(operand, operator)

A new instance of UnaryOperation

Parameters:

  • (Script::Node) operand — The parse-tree node for the object of the operator
  • (Symbol) operator — The operator to perform


10
11
12
13
14
# File '/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb', line 10

def initialize(operand, operator)
  @operand = operand
  @operator = operator
  super()
end

Instance Method Details

- (Literal) _perform(environment) (protected)

Evaluates the operation.

Parameters:

  • (Sass::Environment) environment — The environment in which to evaluate the SassScript

Returns:

  • (Literal) — The SassScript object that is the value of the operation

Raises:



48
49
50
51
52
53
54
55
# File '/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb', line 48

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

- (Array<Node>) children

Returns the operand of the operation.

Returns:

See Also:



37
38
39
# File '/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb', line 37

def children
  [@operand]
end

- (String) inspect

A human-readable s-expression representation of the operation

Returns:

  • (String) — A human-readable s-expression representation of the operation


17
18
19
# File '/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb', line 17

def inspect
  "(#{@operator.inspect} #{@operand.inspect})"
end

- to_sass(opts = {})

See Also:



22
23
24
25
26
27
28
29
30
31
# File '/var/www/sass-pages/.haml/lib/sass/script/unary_operation.rb', line 22

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