mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add #to_sass methods for the Sass::Script nodes, and use in RuleNode.
This commit is contained in:
parent
b92903f61c
commit
c439efe0a9
10 changed files with 41 additions and 2 deletions
|
@ -380,7 +380,6 @@ END
|
|||
return HTML4_COLORS_REVERSE[rgb] if HTML4_COLORS_REVERSE[rgb]
|
||||
hex_str
|
||||
end
|
||||
alias_method :inspect, :to_s
|
||||
|
||||
# Returns a string representation of the color.
|
||||
#
|
||||
|
|
|
@ -29,6 +29,11 @@ module Sass
|
|||
"#{name}(#{args.map {|a| a.inspect}.join(', ')})"
|
||||
end
|
||||
|
||||
# @see Node#to_sass
|
||||
def to_sass
|
||||
"#{name}(#{args.map {|a| a.to_sass}.join(', ')})"
|
||||
end
|
||||
|
||||
# Evaluates the function call.
|
||||
#
|
||||
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
||||
|
|
|
@ -61,6 +61,9 @@ module Sass
|
|||
'{' => :lcurly,
|
||||
}
|
||||
|
||||
# @private
|
||||
OPERATORS_REVERSE = Haml::Util.map_hash(OPERATORS) {|k, v| [v, k]}
|
||||
|
||||
# A list of operator strings ordered with longer names first
|
||||
# so that `>` and `<` don't clobber `>=` and `<=`.
|
||||
# @private
|
||||
|
|
|
@ -206,5 +206,6 @@ MSG
|
|||
def to_s
|
||||
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
|
||||
end
|
||||
alias_method :to_sass, :to_s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,5 +32,12 @@ module Sass::Script
|
|||
def children
|
||||
raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #children.")
|
||||
end
|
||||
|
||||
# Returns the text of this SassScript expression.
|
||||
#
|
||||
# @return [String]
|
||||
def to_sass
|
||||
raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #to_sass.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,6 +26,12 @@ module Sass::Script
|
|||
"(#{@operator.inspect} #{@operand1.inspect} #{@operand2.inspect})"
|
||||
end
|
||||
|
||||
# @see Node#to_sass
|
||||
def to_sass
|
||||
o1 = @operand1.is_a?(Operation) ? "(#{@operand1.to_sass})" : @operand1.to_sass
|
||||
"#{o1} #{Lexer::OPERATORS_REVERSE[@operator]} #{@operand2.to_sass}"
|
||||
end
|
||||
|
||||
# Evaluates the operation.
|
||||
#
|
||||
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
||||
|
|
|
@ -8,5 +8,10 @@ module Sass::Script
|
|||
# @return [String]
|
||||
attr_reader :value
|
||||
alias_method :to_s, :value
|
||||
|
||||
# @see Node#to_sass
|
||||
def to_sass
|
||||
"\"#{value}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,12 @@ module Sass::Script
|
|||
"(#{@operator.inspect} #{@operand.inspect})"
|
||||
end
|
||||
|
||||
# @see Node#to_sass
|
||||
def to_sass
|
||||
op = @operand.is_a?(Operation) ? "(#{@operand.to_sass})" : @operand.to_sass
|
||||
Lexer::OPERATORS_REVERSE[@operator] + op
|
||||
end
|
||||
|
||||
# Evaluates the operation.
|
||||
#
|
||||
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
||||
|
|
|
@ -16,6 +16,7 @@ module Sass
|
|||
def inspect
|
||||
"!#{name}"
|
||||
end
|
||||
alias_method :to_sass, :inspect
|
||||
|
||||
# Evaluates the variable.
|
||||
#
|
||||
|
|
|
@ -108,7 +108,13 @@ module Sass::Tree
|
|||
|
||||
# @see Node#to_sass
|
||||
def to_sass(tabs, opts = {})
|
||||
name = rule.first
|
||||
name = rule.map do |r|
|
||||
if r.is_a?(String)
|
||||
r.gsub(/(,[ \t]*)?\n\s*/) {$1 ? $1 + "\n" : " "}
|
||||
else
|
||||
"\#{#{r.to_sass}}"
|
||||
end
|
||||
end.join
|
||||
name = "\\" + name if name[0] == ?:
|
||||
str = "\n#{' ' * tabs}#{name}#{children.any? { |c| c.is_a? PropNode } ? "\n" : ''}"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue