Class: Harmony::Page
- Inherits:
-
Object
- Object
- Harmony::Page
- Defined in:
- lib/harmony/page.rb
Defined Under Namespace
Modules: Window
Class Method Summary collapse
-
.fetch(uri) ⇒ Page
Create page from remote document.
Instance Method Summary collapse
-
#document ⇒ Object
Convenience method, equivalent to the return value of ‘page.execute_js(’window.document’)‘.
-
#execute_js(code) ⇒ Object
(also: #x)
Evaluate Javascript code within this page’s context.
-
#initialize(document = nil) ⇒ Page
constructor
Create new page containing given document.
-
#load(*paths) ⇒ Page
Load one or more javascript files in page’s context.
-
#to_html ⇒ String
Page as html document.
-
#window ⇒ Object
DOM document’s ‘window` object.
Constructor Details
#initialize(document = nil) ⇒ Page
Create new page containing given document.
64 65 66 |
# File 'lib/harmony/page.rb', line 64 def initialize(document=nil) @window = Window.from_document(document) if document end |
Class Method Details
Instance Method Details
#document ⇒ Object
Convenience method, equivalent to the return value of ‘page.execute_js(’window.document’)‘
112 113 114 |
# File 'lib/harmony/page.rb', line 112 def document window.document end |
#execute_js(code) ⇒ Object Also known as: x
Evaluate Javascript code within this page’s context.
91 92 93 |
# File 'lib/harmony/page.rb', line 91 def execute_js(code) window.evaluate(code) end |
#load(*paths) ⇒ Page
Load one or more javascript files in page’s context
74 75 76 77 78 79 80 81 |
# File 'lib/harmony/page.rb', line 74 def load(*paths) paths.flatten.each do |path| path.to_s.map {|f| window.evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1) }.last end self end |
#to_html ⇒ String
Page as html document
120 121 122 |
# File 'lib/harmony/page.rb', line 120 def to_html document.innerHTML end |