Class: Celerity::ViewerConnection
- Inherits:
-
Object
- Object
- Celerity::ViewerConnection
- Defined in:
- lib/celerity/viewer_connection.rb
Class Method Summary collapse
-
.create(host, port) ⇒ Object
Create a new connection to the given host/port.
Instance Method Summary collapse
-
#close ⇒ Object
Close the connection.
-
#image_data ⇒ Object
Get the currently rendered page as a Base64-encoded PNG image.
-
#initialize(socket) ⇒ ViewerConnection
constructor
A new instance of ViewerConnection.
-
#render_html(html, url) ⇒ Object
Tells the viewer to render the given HTML, with the given URL as base url.
-
#save(path) ⇒ Object
Tells the viewer to save a screenshot of the current page to the given path.
-
#save_render_tree(path) ⇒ Object
Tells the viewer to dump the render tree to the given path.
Constructor Details
#initialize(socket) ⇒ ViewerConnection
Returns a new instance of ViewerConnection.
15 16 17 |
# File 'lib/celerity/viewer_connection.rb', line 15 def initialize(socket) @socket = socket end |
Class Method Details
.create(host, port) ⇒ Object
Create a new connection to the given host/port
8 9 10 11 12 13 |
# File 'lib/celerity/viewer_connection.rb', line 8 def self.create(host, port) # if the connection fails, we won't spend time loading json socket = TCPSocket.new(host, port) require "json" new(socket) end |
Instance Method Details
#close ⇒ Object
Close the connection.
61 62 63 |
# File 'lib/celerity/viewer_connection.rb', line 61 def close @socket.close rescue nil end |
#image_data ⇒ Object
Get the currently rendered page as a Base64-encoded PNG image. Only available in the Qt viewer.
51 52 53 54 55 |
# File 'lib/celerity/viewer_connection.rb', line 51 def image_data send_data('method' => 'image_data') data = read_data data['image'] || data['error'] end |
#render_html(html, url) ⇒ Object
Tells the viewer to render the given HTML, with the given URL as base url.
23 24 25 |
# File 'lib/celerity/viewer_connection.rb', line 23 def render_html(html, url) send_data('method' => 'page_changed', 'html' => html, 'url' => url) end |
#save(path) ⇒ Object
Tells the viewer to save a screenshot of the current page to the given path. May not be available on all viewers.
32 33 34 |
# File 'lib/celerity/viewer_connection.rb', line 32 def save(path) send_data('method' => 'save', 'path' => path) end |
#save_render_tree(path) ⇒ Object
Tells the viewer to dump the render tree to the given path. Only available in the Qt viewer.
42 43 44 |
# File 'lib/celerity/viewer_connection.rb', line 42 def save_render_tree(path) send_data('method' => 'save_render_tree', 'path' => path) end |