Class: JavascriptDOMNode

Inherits:
JavascriptObject show all
Defined in:
lib/vapir-firefox/javascript_object.rb

Overview

represents a node on the DOM. not substantially from JavascriptObject, but #inspect is more informative, and #dump is defined for extensive debug info.

This class is mostly useful for debug, not used anywhere in production at the moment.

Instance Attribute Summary

Attributes inherited from JavascriptObject

#debug_name, #firefox_socket, #function_result, #ref

Instance Method Summary collapse

Methods inherited from JavascriptObject

#%, #*, #+, #-, #/, #<, #<=, #==, #>, #>=, #[], #[]=, always_define_methods, always_define_methods=, #assign, #assign_expr, #assign_or_call_or_val_or_object_by_suffix, #attr, #binary_operator, #call, #define_methods!, #implemented_interfaces, #initialize, #instanceof, #invoke, #invoke?, #method_missing, #new, #object_respond_to?, #object_type, #pass, #respond_to?, #store, #store_rand_object_key, #store_rand_temp, #sub, #to_array, #to_dom, #to_function, #to_hash, #to_js_array, #to_js_hash, #to_js_hash_safe, #to_ruby_array, #to_ruby_hash, #to_simple_enumerator, #triple_equals, #type, #val, #val_or_object, #val_str

Constructor Details

This class inherits a constructor from JavascriptObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JavascriptObject

Instance Method Details

#dump(options = {}) ⇒ Object

returns a string (most useful when written to STDOUT or to a file) consisting of this dom node and its child nodes, recursively. each node is one line and depth is indicated by spacing.

call #dump(:recurse => n) to recurse down only n levels. default is to recurse all the way down the dom tree.



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/vapir-firefox/javascript_object.rb', line 655

def dump(options={})
  options={:recurse => nil, :level => 0}.merge(options)
  options[:document] ||= self.ownerDocument
  next_options=options.merge(:recurse => options[:recurse] && (options[:recurse]-1), :level => options[:level]+1)
  result=(" "*options[:level]*2)+self.inspect+"\n"
  if options[:recurse]==0
    result+=(" "*next_options[:level]*2)+"...\n"
  else 
    self.childNodes.to_array.each do |child|
      result+=child.to_dom.dump(next_options)
    end
    anons = self.nodeType == 1 && options[:document].getAnonymousNodes(self)
    if anons
      result+=(" "*next_options[:level]*2)+"ANONYMOUS:\n"
      anons.to_array.each do |child|
        result+=child.to_dom.dump(next_options)
      end
    end
  end
  result
end

#inspectObject

returns a string with a bunch of information about this dom node



635
636
637
# File 'lib/vapir-firefox/javascript_object.rb', line 635

def inspect
  "\#<#{self.class.name} #{inspect_stuff.map{|(k,v)| "#{k}=#{v.inspect}"}.join(', ')}>"
end

#inspect_stuffObject

:nodoc:



624
625
626
627
628
629
630
631
632
633
# File 'lib/vapir-firefox/javascript_object.rb', line 624

def inspect_stuff # :nodoc:
  [:nodeName, :nodeType, :nodeValue, :tagName, :textContent, :id, :name, :value, :type, :className, :hidden].map do |attrn|
    attr=attr(attrn)
    if ['undefined','null'].include?(attr.type)
      nil
    else
      [attrn, attr.val_or_object(:error_on_undefined => false)]
    end
  end.compact
end

#pretty_print(pp) ⇒ Object

:nodoc:



638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/vapir-firefox/javascript_object.rb', line 638

def pretty_print(pp) # :nodoc:
  pp.object_address_group(self) do
    pp.seplist(inspect_stuff, lambda { pp.text ',' }) do |attr_val|
      pp.breakable ' '
      pp.group(0) do
        pp.text attr_val.first.to_s
        pp.text ': '
        #pp.breakable
        pp.text attr_val.last.inspect
      end
    end
  end
end