Class: Sass::Tree::AttrNode
- Defined in:
- lib/sass/css.rb,
lib/sass/tree/attr_node.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Node
#children, #filename, #line, #options
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, value, attr_syntax) ⇒ AttrNode
constructor
A new instance of AttrNode.
- #to_s(tabs, parent_name = nil) ⇒ Object
- #to_sass(tabs, opts = {}) ⇒ Object
Methods inherited from Node
#<<, #invisible?, #last, #perform, #render, #style
Constructor Details
#initialize(name, value, attr_syntax) ⇒ AttrNode
Returns a new instance of AttrNode.
5 6 7 8 9 10 |
# File 'lib/sass/tree/attr_node.rb', line 5 def initialize(name, value, attr_syntax) @name = name @value = value @attr_syntax = attr_syntax super() end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sass/tree/attr_node.rb', line 3 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/sass/tree/attr_node.rb', line 3 def value @value end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 |
# File 'lib/sass/tree/attr_node.rb', line 12 def ==(other) self.class == other.class && name == other.name && value == other.value && super end |
#to_s(tabs, parent_name = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sass/tree/attr_node.rb', line 16 def to_s(tabs, parent_name = nil) if @options[:attribute_syntax] == :normal && @attr_syntax == :new raise Sass::SyntaxError.new("Illegal attribute syntax: can't use alternate syntax when :attribute_syntax => :normal is set.") elsif @options[:attribute_syntax] == :alternate && @attr_syntax == :old raise Sass::SyntaxError.new("Illegal attribute syntax: can't use normal syntax when :attribute_syntax => :alternate is set.") end if value[-1] == ?; raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (no \";\" required at end-of-line).", @line) end real_name = name real_name = "#{parent_name}-#{real_name}" if parent_name if value.empty? && children.empty? raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (no value).", @line) end join_string = case style when :compact; ' ' when :compressed; '' else "\n" end spaces = ' ' * (tabs - 1) to_return = '' if !value.empty? to_return << "#{spaces}#{real_name}:#{style == :compressed ? '' : ' '}#{value};#{join_string}" end children.each do |kid| next if kid.invisible? to_return << kid.to_s(tabs, real_name) << join_string end (style == :compressed && parent_name) ? to_return : to_return[0...-1] end |
#to_sass(tabs, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/sass/css.rb', line 33 def to_sass(tabs, opts = {}) "#{' ' * tabs}#{opts[:alternate] ? '' : ':'}#{name}#{opts[:alternate] ? ':' : ''} #{value}\n" end |