Class: CSSPool::CSS::Document

Inherits:
Node
  • Object
show all
Defined in:
lib/csspool/css/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Visitable

#==, #accept, #children, #each, #hash, #to_css

Constructor Details

#initializeDocument

Returns a new instance of Document.



20
21
22
23
24
25
26
# File 'lib/csspool/css/document.rb', line 20

def initialize
  @rule_sets    = []
  @charsets     = []
  @import_rules = []
  @parent       = nil
  @parent_import_rule = nil
end

Instance Attribute Details

#charsetsObject

Returns the value of attribute charsets.



15
16
17
# File 'lib/csspool/css/document.rb', line 15

def charsets
  @charsets
end

#import_rulesObject

Returns the value of attribute import_rules.



16
17
18
# File 'lib/csspool/css/document.rb', line 16

def import_rules
  @import_rules
end

#parentObject

Returns the value of attribute parent.



17
18
19
# File 'lib/csspool/css/document.rb', line 17

def parent
  @parent
end

#parent_import_ruleObject

Returns the value of attribute parent_import_rule.



18
19
20
# File 'lib/csspool/css/document.rb', line 18

def parent_import_rule
  @parent_import_rule
end

#rule_setsObject

Returns the value of attribute rule_sets.



14
15
16
# File 'lib/csspool/css/document.rb', line 14

def rule_sets
  @rule_sets
end

Class Method Details

.parse(string) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/csspool/css/document.rb', line 4

def self.parse string
  unless string && string.length > 0
    return CSSPool::CSS::Document.new
  end
  handler = CSSPool::CSS::DocumentHandler.new
  parser = CSSPool::SAC::Parser.new(handler)
  parser.parse(string)
  handler.document
end

Instance Method Details

#[](selector) ⇒ Object



28
29
30
31
# File 'lib/csspool/css/document.rb', line 28

def [] selector
  selectors = CSSPool.CSS("#{selector} {}").rule_sets.first.selectors
  rule_sets.find_all { |rs| rs.selectors == selectors}
end