Class: CSSPool::CSS::Document

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

Instance Attribute Summary collapse

Attributes inherited from Node

#inner_end_pos, #inner_start_pos, #outer_end_pos, #outer_start_pos

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initializeDocument

Returns a new instance of Document.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/csspool/css/document.rb', line 32

def initialize
  @rule_sets    = []
  @charsets     = []
  @import_rules = []
  @document_queries = []
  @supports_rules = []
  @namespaces   = []
  @parent       = nil
  @parent_import_rule = nil
  @keyframes_rules = []
  @fontface_rules = []
end

Instance Attribute Details

#charsetsObject

Returns the value of attribute charsets.



22
23
24
# File 'lib/csspool/css/document.rb', line 22

def charsets
  @charsets
end

#document_queriesObject

Returns the value of attribute document_queries.



24
25
26
# File 'lib/csspool/css/document.rb', line 24

def document_queries
  @document_queries
end

#fontface_rulesObject

Returns the value of attribute fontface_rules.



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

def fontface_rules
  @fontface_rules
end

#import_rulesObject

Returns the value of attribute import_rules.



23
24
25
# File 'lib/csspool/css/document.rb', line 23

def import_rules
  @import_rules
end

#keyframes_rulesObject

Returns the value of attribute keyframes_rules.



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

def keyframes_rules
  @keyframes_rules
end

#namespacesObject

Returns the value of attribute namespaces.



26
27
28
# File 'lib/csspool/css/document.rb', line 26

def namespaces
  @namespaces
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#parent_import_ruleObject

Returns the value of attribute parent_import_rule.



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

def parent_import_rule
  @parent_import_rule
end

#rule_setsObject

Returns the value of attribute rule_sets.



21
22
23
# File 'lib/csspool/css/document.rb', line 21

def rule_sets
  @rule_sets
end

#supports_rulesObject

Returns the value of attribute supports_rules.



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

def supports_rules
  @supports_rules
end

Class Method Details

.parse(string) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/csspool/css/document.rb', line 4

def self.parse string
  # If a File object gets passed in, via functions like File.open
  # or Kernel::open
  if string.respond_to? :read
    string = string.read
  end

  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



45
46
47
48
# File 'lib/csspool/css/document.rb', line 45

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