Class: Harmony::Page
- Inherits:
-
Object
- Object
- Harmony::Page
- Defined in:
- lib/harmony/page.rb
Defined Under Namespace
Classes: Window
Instance Attribute Summary collapse
-
#window ⇒ Object
readonly
DOM document’s ‘window` object.
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.
Constructor Details
#initialize(document = nil) ⇒ Page
Create new page containing given document.
44 45 46 |
# File 'lib/harmony/page.rb', line 44 def initialize(document=nil) @window = document ? Window.from_document(document) : Window.blank end |
Instance Attribute Details
#window ⇒ Object (readonly)
DOM document’s ‘window` object. Equivalent to the return value of `page.execute_js(’window’)‘
16 17 18 |
# File 'lib/harmony/page.rb', line 16 def window @window end |
Class Method Details
.fetch(uri) ⇒ Page
Create page from remote document.
32 33 34 35 36 |
# File 'lib/harmony/page.rb', line 32 def self.fetch(uri) page = new page.window.open(uri) page end |
Instance Method Details
#document ⇒ Object
Convenience method, equivalent to the return value of ‘page.execute_js(’window.document’)‘
82 83 84 |
# File 'lib/harmony/page.rb', line 82 def document window.document end |
#execute_js(code) ⇒ Object Also known as: x
Evaluate Javascript code within this page’s context.
71 72 73 |
# File 'lib/harmony/page.rb', line 71 def execute_js(code) window.evaluate(code) end |
#load(*paths) ⇒ Page
Load one or more javascript files in page’s context
54 55 56 57 58 59 60 61 |
# File 'lib/harmony/page.rb', line 54 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
90 91 92 |
# File 'lib/harmony/page.rb', line 90 def to_html document.innerHTML end |