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.



7
8
9
10
11
12
# File 'lib/csspool/css/document_handler.rb', line 7

def initialize
  @document     = nil
  @conditional_stack  = []
  @active_keyframes_block = nil
  @active_fontface_rule = nil
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

#node_start_posObject

Returns the value of attribute node_start_pos.



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

def node_start_pos
  @node_start_pos
end

Instance Method Details

#charset(name, location) ⇒ Object



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

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

#end_document_query(inner_end_pos = nil, outer_end_pos = nil) ⇒ Object



78
79
80
81
82
# File 'lib/csspool/css/document_handler.rb', line 78

def end_document_query inner_end_pos = nil, outer_end_pos = nil
  last = @conditional_stack.pop
  last.inner_end_pos = inner_end_pos
  last.outer_end_pos = outer_end_pos
end

#end_fontface_ruleObject



112
113
114
# File 'lib/csspool/css/document_handler.rb', line 112

def end_fontface_rule
  @active_fontface_rule = nil
end

#end_keyframes_blockObject



103
104
105
# File 'lib/csspool/css/document_handler.rb', line 103

def end_keyframes_block
  @active_keyframes_block = nil
end

#end_media(media_query_list) ⇒ Object



65
66
67
# File 'lib/csspool/css/document_handler.rb', line 65

def end_media media_query_list
  @conditional_stack.pop
end

#end_supportsObject



90
91
92
# File 'lib/csspool/css/document_handler.rb', line 90

def end_supports
  @conditional_stack.pop
end

#import_style(media, uri, ns = nil, loc = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/csspool/css/document_handler.rb', line 22

def import_style media, uri, ns = nil, loc = {}
  @document.import_rules << CSS::ImportRule.new(
    uri,
    ns,
    media,
    @document,
    loc
  )
end

#namespace(prefix, uri) ⇒ Object



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

def namespace prefix, uri
  @document.namespaces << CSS::NamespaceRule.new(
    prefix,
    uri
  )
end

#property(declaration) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/csspool/css/document_handler.rb', line 49

def property declaration
  if !@active_fontface_rule.nil?
    rs = @active_fontface_rule
  elsif !@active_keyframes_block.nil?
    rs = @active_keyframes_block
  else
    rs = @document.rule_sets.last
  end
  declaration.rule_set = rs
  rs.declarations << declaration
end

#start_documentObject



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

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

#start_document_query(url_functions, inner_start_pos = nil) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/csspool/css/document_handler.rb', line 69

def start_document_query url_functions, inner_start_pos = nil
  dq = CSS::DocumentQuery.new(url_functions)
  dq.outer_start_pos = @node_start_pos
  @node_start_pos = nil
  dq.inner_start_pos = inner_start_pos
  @document.document_queries << dq
  @conditional_stack << dq
end

#start_fontface_ruleObject



107
108
109
110
# File 'lib/csspool/css/document_handler.rb', line 107

def start_fontface_rule
  @active_fontface_rule = CSS::FontfaceRule.new
  @document.fontface_rules << @active_fontface_rule
end

#start_keyframes_block(keyText) ⇒ Object



98
99
100
101
# File 'lib/csspool/css/document_handler.rb', line 98

def start_keyframes_block keyText
  @active_keyframes_block = CSS::KeyframesBlock.new(keyText)
  @document.keyframes_rules.last.rule_sets << @active_keyframes_block
end

#start_keyframes_rule(name) ⇒ Object



94
95
96
# File 'lib/csspool/css/document_handler.rb', line 94

def start_keyframes_rule name
  @document.keyframes_rules << CSS::KeyframesRule.new(name)
end

#start_media(media_query_list) ⇒ Object



61
62
63
# File 'lib/csspool/css/document_handler.rb', line 61

def start_media media_query_list
  @conditional_stack << media_query_list
end

#start_selector(selector_list) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/csspool/css/document_handler.rb', line 39

def start_selector selector_list
  rs = RuleSet.new(
    selector_list,
    [],
    @conditional_stack.last
  )
  @document.rule_sets << rs
  @conditional_stack.last.rule_sets << rs unless @conditional_stack.empty?
end

#start_supports(conditions) ⇒ Object



84
85
86
87
88
# File 'lib/csspool/css/document_handler.rb', line 84

def start_supports conditions
  sr = CSS::SupportsRule.new(conditions)
  @document.supports_rules << sr
  @conditional_stack << sr
end