Class: Sass::Tree::RuleNode
- Defined in:
- lib/sass/css.rb,
lib/sass/tree/rule_node.rb
Constant Summary collapse
- PARENT =
The character used to include the parent selector
'&'
Instance Attribute Summary collapse
-
#parsed_rules ⇒ Object
Returns the value of attribute parsed_rules.
-
#rules ⇒ Object
Returns the value of attribute rules.
Attributes inherited from Node
#children, #filename, #line, #options
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_rules(node) ⇒ Object
- #continued? ⇒ Boolean
-
#initialize(rule) ⇒ RuleNode
constructor
A new instance of RuleNode.
- #to_s(tabs, super_rules = nil) ⇒ Object
- #to_sass(tabs, opts = {}) ⇒ Object
Methods inherited from Node
#<<, #invisible?, #last, #perform, #render, #style
Constructor Details
#initialize(rule) ⇒ RuleNode
Returns a new instance of RuleNode.
10 11 12 13 |
# File 'lib/sass/tree/rule_node.rb', line 10 def initialize(rule) @rules = [rule] super() end |
Instance Attribute Details
#parsed_rules ⇒ Object
Returns the value of attribute parsed_rules.
8 9 10 |
# File 'lib/sass/tree/rule_node.rb', line 8 def parsed_rules @parsed_rules end |
#rules ⇒ Object
Returns the value of attribute rules.
8 9 10 |
# File 'lib/sass/tree/rule_node.rb', line 8 def rules @rules end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 |
# File 'lib/sass/tree/rule_node.rb', line 15 def ==(other) self.class == other.class && rules == other.rules && super end |
#add_rules(node) ⇒ Object
19 20 21 |
# File 'lib/sass/tree/rule_node.rb', line 19 def add_rules(node) @rules += node.rules end |
#continued? ⇒ Boolean
23 24 25 |
# File 'lib/sass/tree/rule_node.rb', line 23 def continued? @rules.last[-1] == ?, end |
#to_s(tabs, super_rules = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sass/tree/rule_node.rb', line 27 def to_s(tabs, super_rules = nil) resolved_rules = resolve_parent_refs(super_rules) attributes = [] sub_rules = [] 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] total_rule = total_indent + resolved_rules.map do |line| per_rule_indent + line.join(rule_separator) end.join(line_separator) children.each do |child| next if child.invisible? if child.is_a? RuleNode sub_rules << child else attributes << child end end to_return = '' if !attributes.empty? old_spaces = ' ' * (tabs - 1) spaces = ' ' * tabs if @options[:line_comments] && style != :compressed to_return << "#{old_spaces}/* line #{line}" if filename relative_filename = if @options[:css_filename] begin Pathname.new(filename).relative_path_from( Pathname.new(File.dirname(@options[:css_filename]))).to_s rescue ArgumentError nil end end relative_filename ||= filename to_return << ", #{relative_filename}" end to_return << " */\n" end 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 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 : ' ') to_return << "#{total_rule} {\n#{attributes}#{end_attrs}}\n" end end tabs += 1 unless attributes.empty? || style != :nested sub_rules.each do |sub| to_return << sub.to_s(tabs, resolved_rules) end to_return end |