Class: Roda::Component::DOM
- Inherits:
-
Object
- Object
- Roda::Component::DOM
- Defined in:
- lib/roda/component/dom.rb
Instance Attribute Summary collapse
-
#dom ⇒ Object
Returns the value of attribute dom.
-
#raw_html ⇒ Object
Returns the value of attribute raw_html.
Instance Method Summary collapse
- #find(string, &block) ⇒ Object
- #html(content = false) ⇒ Object
- #html=(content) ⇒ Object
-
#initialize(html) ⇒ DOM
constructor
A new instance of DOM.
-
#method_missing(method, *args, &block) ⇒ Object
This allows you to use all the nokogiri or opal jquery methods if a global one isn’t set.
- #node ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
This allows you to use all the nokogiri or opal jquery methods if a global one isn’t set
72 73 74 75 76 77 78 79 |
# File 'lib/roda/component/dom.rb', line 72 def method_missing method, *args, &block # respond_to?(symbol, include_all=false) if dom.respond_to? method, true dom.send method, *args, &block else super end end |
Instance Attribute Details
#dom ⇒ Object
Returns the value of attribute dom.
4 5 6 |
# File 'lib/roda/component/dom.rb', line 4 def dom @dom end |
#raw_html ⇒ Object
Returns the value of attribute raw_html.
4 5 6 |
# File 'lib/roda/component/dom.rb', line 4 def raw_html @raw_html end |
Instance Method Details
#find(string, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/roda/component/dom.rb', line 16 def find string, &block if server? @node = dom.css string else @node = dom.find string end if block if server? node.each do |n| block.call n end else block.call node end else if server? @node = node.first end end if server? self else node end end |
#html(content = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/roda/component/dom.rb', line 54 def html content = false if !content if server? node.inner_html else node ? node.html : dom.html end else self.html = content end end |
#html=(content) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/roda/component/dom.rb', line 44 def html= content if server? node.inner_html = content else node.html content end node end |
#node ⇒ Object
66 67 68 |
# File 'lib/roda/component/dom.rb', line 66 def node @node || dom end |