mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Use an attribute to access @style in Sass::Tree.
This commit is contained in:
parent
de038486ab
commit
a76e1654da
5 changed files with 22 additions and 21 deletions
|
@ -30,7 +30,7 @@ module Sass::Tree
|
|||
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump}.", @line)
|
||||
end
|
||||
|
||||
join_string = case @style
|
||||
join_string = case style
|
||||
when :compact; ' '
|
||||
when :compressed; ''
|
||||
else "\n"
|
||||
|
@ -38,14 +38,14 @@ module Sass::Tree
|
|||
spaces = ' ' * (tabs - 1)
|
||||
to_return = ''
|
||||
if !value.empty?
|
||||
to_return << "#{spaces}#{real_name}:#{@style == :compressed ? '' : ' '}#{value};#{join_string}"
|
||||
to_return << "#{spaces}#{real_name}:#{style == :compressed ? '' : ' '}#{value};#{join_string}"
|
||||
end
|
||||
|
||||
children.each do |kid|
|
||||
to_return << kid.to_s(tabs, real_name) << join_string
|
||||
end
|
||||
|
||||
(@style == :compressed && parent_name) ? to_return : to_return[0...-1]
|
||||
(style == :compressed && parent_name) ? to_return : to_return[0...-1]
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -18,11 +18,11 @@ module Sass::Tree
|
|||
end
|
||||
|
||||
def to_s(tabs = 0, parent_name = nil)
|
||||
return if (@style == :compressed || silent?)
|
||||
return if (style == :compressed || silent?)
|
||||
|
||||
spaces = ' ' * (tabs - 1)
|
||||
spaces + "/* " + ([value] + children.map {|c| c.text}).
|
||||
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(@style == :compact ? ' ' : "\n#{spaces} * ") + " */"
|
||||
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(style == :compact ? ' ' : "\n#{spaces} * ") + " */"
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -11,15 +11,15 @@ module Sass::Tree
|
|||
if children.empty?
|
||||
value + ";"
|
||||
else
|
||||
result = if @style == :compressed
|
||||
result = if style == :compressed
|
||||
"#{value}{"
|
||||
else
|
||||
"#{' ' * (tabs - 1)}#{value} {" + (@style == :compact ? ' ' : "\n")
|
||||
"#{' ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
|
||||
end
|
||||
was_attr = false
|
||||
first = true
|
||||
children.each do |child|
|
||||
if @style == :compact
|
||||
if style == :compact
|
||||
if child.is_a?(AttrNode)
|
||||
result << "#{child.to_s(first || was_attr ? 1 : tabs + 1)} "
|
||||
else
|
||||
|
@ -32,17 +32,17 @@ module Sass::Tree
|
|||
end
|
||||
was_attr = child.is_a?(AttrNode)
|
||||
first = false
|
||||
elsif @style == :compressed
|
||||
elsif style == :compressed
|
||||
result << (was_attr ? ";#{child.to_s(1)}" : child.to_s(1))
|
||||
was_attr = child.is_a?(AttrNode)
|
||||
else
|
||||
result << child.to_s(tabs + 1) + "\n"
|
||||
end
|
||||
end
|
||||
result.rstrip + if @style == :compressed
|
||||
result.rstrip + if style == :compressed
|
||||
"}"
|
||||
else
|
||||
(@style == :expanded ? "\n" : " ") + "}\n"
|
||||
(style == :expanded ? "\n" : " ") + "}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ module Sass
|
|||
attr_accessor :children
|
||||
attr_accessor :line
|
||||
attr_accessor :filename
|
||||
attr_reader :style
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
|
@ -35,10 +36,10 @@ module Sass
|
|||
else
|
||||
child_str = child.to_s(1)
|
||||
next unless child_str && child_str.length > 0
|
||||
result << child_str + (@style == :compressed ? '' : "\n")
|
||||
result << child_str + (style == :compressed ? '' : "\n")
|
||||
end
|
||||
end
|
||||
@style == :compressed ? result+"\n" : result[0...-1]
|
||||
style == :compressed ? result+"\n" : result[0...-1]
|
||||
end
|
||||
|
||||
def perform(environment)
|
||||
|
|
|
@ -38,10 +38,10 @@ module Sass::Tree
|
|||
attributes = []
|
||||
sub_rules = []
|
||||
|
||||
rule_separator = @style == :compressed ? ',' : ', '
|
||||
line_separator = [:nested, :expanded].include?(@style) ? ",\n" : rule_separator
|
||||
rule_separator = style == :compressed ? ',' : ', '
|
||||
line_separator = [:nested, :expanded].include?(style) ? ",\n" : rule_separator
|
||||
rule_indent = ' ' * (tabs - 1)
|
||||
per_rule_indent, total_indent = [:nested, :expanded].include?(@style) ? [rule_indent, ''] : ['', rule_indent]
|
||||
per_rule_indent, total_indent = [:nested, :expanded].include?(style) ? [rule_indent, ''] : ['', rule_indent]
|
||||
|
||||
total_rule = total_indent + @rules.map do |line|
|
||||
per_rule_indent + line.join(rule_separator)
|
||||
|
@ -59,7 +59,7 @@ module Sass::Tree
|
|||
if !attributes.empty?
|
||||
old_spaces = ' ' * (tabs - 1)
|
||||
spaces = ' ' * tabs
|
||||
if @options[:line_comments] && @style != :compressed
|
||||
if @options[:line_comments] && style != :compressed
|
||||
to_return << "#{old_spaces}/* line #{line}"
|
||||
|
||||
if filename
|
||||
|
@ -78,20 +78,20 @@ module Sass::Tree
|
|||
to_return << " */\n"
|
||||
end
|
||||
|
||||
if @style == :compact
|
||||
if style == :compact
|
||||
attributes = attributes.map { |a| a.to_s(1) }.select{|a| a && a.length > 0}.join(' ')
|
||||
to_return << "#{total_rule} { #{attributes} }\n"
|
||||
elsif @style == :compressed
|
||||
elsif style == :compressed
|
||||
attributes = attributes.map { |a| a.to_s(1) }.select{|a| a && a.length > 0}.join(';')
|
||||
to_return << "#{total_rule}{#{attributes}}"
|
||||
else
|
||||
attributes = attributes.map { |a| a.to_s(tabs + 1) }.select{|a| a && a.length > 0}.join("\n")
|
||||
end_attrs = (@style == :expanded ? "\n" + old_spaces : ' ')
|
||||
end_attrs = (style == :expanded ? "\n" + old_spaces : ' ')
|
||||
to_return << "#{total_rule} {\n#{attributes}#{end_attrs}}\n"
|
||||
end
|
||||
end
|
||||
|
||||
tabs += 1 unless attributes.empty? || @style != :nested
|
||||
tabs += 1 unless attributes.empty? || style != :nested
|
||||
sub_rules.each do |sub|
|
||||
to_return << sub.to_s(tabs, @rules)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue