Class: CSSPool::CSS::DocumentHandler

Inherits:
SAC::Document show all
Defined in:
lib/csspool/css/document_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SAC::Document

#comment, #end_document, #end_selector

Constructor Details

#initializeDocumentHandler

Returns a new instance of DocumentHandler.



6
7
8
9
# File 'lib/csspool/css/document_handler.rb', line 6

def initialize
  @document     = nil
  @media_stack  = []
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



4
5
6
# File 'lib/csspool/css/document_handler.rb', line 4

def document
  @document
end

Instance Method Details

#charset(name, location) ⇒ Object



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

def charset name, location
  @document.charsets << CSS::Charset.new(name, location)
end

#end_media(media_list, parse_location) ⇒ Object



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

def end_media media_list, parse_location
  @media_stack.pop
end

#import_style(media_list, uri, ns, loc) ⇒ Object



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

def import_style media_list, uri, ns, loc
  @document.import_rules << CSS::ImportRule.new(
    uri,
    ns,
    media_list.map { |x| CSS::Media.new(x, loc) },
    @document,
    loc
  )
end

#property(name, exp, important) ⇒ Object



37
38
39
40
# File 'lib/csspool/css/document_handler.rb', line 37

def property name, exp, important
  rs = @document.rule_sets.last
  rs.declarations << Declaration.new(name, exp, important, rs)
end

#start_documentObject



11
12
13
# File 'lib/csspool/css/document_handler.rb', line 11

def start_document
  @document = CSSPool::CSS::Document.new
end

#start_media(media_list, parse_location) ⇒ Object



42
43
44
# File 'lib/csspool/css/document_handler.rb', line 42

def start_media media_list, parse_location
  @media_stack << media_list.map { |x| CSS::Media.new(x, parse_location) }
end

#start_selector(selector_list) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/csspool/css/document_handler.rb', line 29

def start_selector selector_list
  @document.rule_sets << RuleSet.new(
    selector_list,
    [],
    @media_stack.last || []
  )
end