Class: TkXML::Nokogiri_Listener

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/tkxml/nokogiri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tk) ⇒ Nokogiri_Listener

Returns a new instance of Nokogiri_Listener.



18
19
20
21
# File 'lib/tkxml/nokogiri.rb', line 18

def initialize(tk)
  super()
  @tk = tk
end

Instance Attribute Details

#tkObject (readonly)

Returns the value of attribute tk.



15
16
17
# File 'lib/tkxml/nokogiri.rb', line 15

def tk
  @tk
end

Instance Method Details

#end_element(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tkxml/nokogiri.rb', line 42

def end_element(name)
  ## pull off the tag name if prefixed with the Tk namespace
  name = name.sub(/^Tk:/, '')

  # if method then we're finish
  # else if widget then finish creation and pop off the widget stack
  if name[0..0] == "_"
    name = name[1..-1]
    tk.end_method(name)
  else
    tk.end_widget(name)
  end
end

#start_element(name, attrs = []) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tkxml/nokogiri.rb', line 24

def start_element(name, attrs=[])
  tk.start

  ## pull off the tag name if prefixed with the Tk namespace
  name  = name.sub(/^Tk:/, '')

  attrs = Hash[*attrs.flatten]

  ## is it a method call or a new widget?
  if name[0..0] == '_'
    name = name[1..-1]
    tk.start_method(name, attrs)
  else
    tk.start_widget(name, attrs)
  end
end