lib/sass/script/literal.rb in haml-edge-2.3.179 vs lib/sass/script/literal.rb in haml-edge-2.3.180
- old
+ new
@@ -19,20 +19,13 @@
# Creates a new literal.
#
# @param value [Object] The object for \{#value}
def initialize(value = nil)
@value = value
+ super()
end
- # Evaluates the literal.
- #
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
- # @return [Literal] This literal
- def perform(environment)
- self
- end
-
# Returns an empty array.
#
# @return [Array<Node>] empty
# @see Node#children
def children
@@ -107,20 +100,20 @@
# false otherwise
def unary_not
Sass::Script::Bool.new(!to_bool)
end
- # The SassScript default operation (e.g. `!a !b`, `"foo" "bar"`).
+ # The SassScript default operation (e.g. `$a $b`, `"foo" "bar"`).
#
# @param other [Literal] The right-hand side of the operator
# @return [Script::String] A string containing both literals
# separated by a space
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
- # The SassScript `,` operation (e.g. `!a, !b`, `"foo", "bar"`).
+ # The SassScript `,` operation (e.g. `$a, $b`, `"foo", "bar"`).
#
# @param other [Literal] The right-hand side of the operator
# @return [Script::String] A string containing both literals
# separated by `", "`
def comma(other)
@@ -131,10 +124,13 @@
#
# @param other [Literal] The right-hand side of the operator
# @return [Script::String] A string containing both literals
# without any separation
def plus(other)
+ if other.is_a?(Sass::Script::String)
+ return Sass::Script::String.new(self.to_s + other.value, other.type)
+ end
Sass::Script::String.new(self.to_s + other.to_s)
end
# The SassScript `-` operation.
#
@@ -152,20 +148,29 @@
# separated by `"/"`
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
- # The SassScript unary `-` operation (e.g. `-!a`).
+ # The SassScript unary `+` operation (e.g. `+$a`).
#
# @param other [Literal] The right-hand side of the operator
# @return [Script::String] A string containing the literal
+ # preceded by `"+"`
+ def unary_plus
+ Sass::Script::String.new("+#{self.to_s}")
+ end
+
+ # The SassScript unary `-` operation (e.g. `-$a`).
+ #
+ # @param other [Literal] The right-hand side of the operator
+ # @return [Script::String] A string containing the literal
# preceded by `"-"`
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
- # The SassScript unary `/` operation (e.g. `/!a`).
+ # The SassScript unary `/` operation (e.g. `/$a`).
#
# @param other [Literal] The right-hand side of the operator
# @return [Script::String] A string containing the literal
# preceded by `"/"`
def unary_div
@@ -203,8 +208,19 @@
# as it would be output to the CSS document.
#
# @return [String]
def to_s
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
+ end
+ alias_method :to_sass, :to_s
+
+ protected
+
+ # Evaluates the literal.
+ #
+ # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
+ # @return [Literal] This literal
+ def _perform(environment)
+ self
end
end
end