Class: CSSPool::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/csspool/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inner_end_posObject

These give the position of this node in the source CSS. Not all node types are supported. “Outer” represents the start/end of this node, “inner” represents the start/end of this node’s children. Outer will not contain leading or trailing comments or whitespace, while inner will. For example, in this code:


1 /* test1 */ 2 @document domain(‘example.com’) { 3 /* test2 */ 4 * { color: blue; } 5 /* test3 */ 6 } /* test4 */


The index will represent the position: outer_start_pos: 2:0 inner_start_pos: 2:33 inner_end_pos: 6:0 outer_end_pos: 6:1



25
26
27
# File 'lib/csspool/node.rb', line 25

def inner_end_pos
  @inner_end_pos
end

#inner_start_posObject

These give the position of this node in the source CSS. Not all node types are supported. “Outer” represents the start/end of this node, “inner” represents the start/end of this node’s children. Outer will not contain leading or trailing comments or whitespace, while inner will. For example, in this code:


1 /* test1 */ 2 @document domain(‘example.com’) { 3 /* test2 */ 4 * { color: blue; } 5 /* test3 */ 6 } /* test4 */


The index will represent the position: outer_start_pos: 2:0 inner_start_pos: 2:33 inner_end_pos: 6:0 outer_end_pos: 6:1



25
26
27
# File 'lib/csspool/node.rb', line 25

def inner_start_pos
  @inner_start_pos
end

#outer_end_posObject

These give the position of this node in the source CSS. Not all node types are supported. “Outer” represents the start/end of this node, “inner” represents the start/end of this node’s children. Outer will not contain leading or trailing comments or whitespace, while inner will. For example, in this code:


1 /* test1 */ 2 @document domain(‘example.com’) { 3 /* test2 */ 4 * { color: blue; } 5 /* test3 */ 6 } /* test4 */


The index will represent the position: outer_start_pos: 2:0 inner_start_pos: 2:33 inner_end_pos: 6:0 outer_end_pos: 6:1



25
26
27
# File 'lib/csspool/node.rb', line 25

def outer_end_pos
  @outer_end_pos
end

#outer_start_posObject

These give the position of this node in the source CSS. Not all node types are supported. “Outer” represents the start/end of this node, “inner” represents the start/end of this node’s children. Outer will not contain leading or trailing comments or whitespace, while inner will. For example, in this code:


1 /* test1 */ 2 @document domain(‘example.com’) { 3 /* test2 */ 4 * { color: blue; } 5 /* test3 */ 6 } /* test4 */


The index will represent the position: outer_start_pos: 2:0 inner_start_pos: 2:33 inner_end_pos: 6:0 outer_end_pos: 6:1



25
26
27
# File 'lib/csspool/node.rb', line 25

def outer_start_pos
  @outer_start_pos
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



44
45
46
47
48
# File 'lib/csspool/node.rb', line 44

def == other
  return false unless self.class == other.class

  accept Visitors::Comparable.new other
end

#accept(target) ⇒ Object



27
28
29
# File 'lib/csspool/node.rb', line 27

def accept target
  target.accept self
end

#childrenObject



55
56
57
# File 'lib/csspool/node.rb', line 55

def children
  accept Visitors::Children.new
end

#each(&block) ⇒ Object



51
52
53
# File 'lib/csspool/node.rb', line 51

def each &block
  Visitors::Iterator.new(block).accept self
end

#hashObject



59
60
61
# File 'lib/csspool/node.rb', line 59

def hash
  @hash ||= children.map { |child| child.hash }.hash
end

#to_css(options = {}) ⇒ Object Also known as: to_s



31
32
33
34
35
36
37
# File 'lib/csspool/node.rb', line 31

def to_css options={}
  if options[:minify]
    to_minified_css
  else
    accept Visitors::ToCSS.new
  end
end

#to_minified_cssObject



40
41
42
# File 'lib/csspool/node.rb', line 40

def to_minified_css
  accept Visitors::ToMinifiedCSS.new
end