Class: Celerity::ViewerConnection
- Inherits:
- Object
- Defined in:
- lib/celerity/viewer_connection.rb
Method Summary
- + (Object) create(host, port) Create a new connection to the given host/port.
- - (Object) close Close the connection.
- - (Object) image_data Get the currently rendered page as a Base64-encoded PNG image.
- - (ViewerConnection) initialize(socket) A new instance of ViewerConnection.
- - (Object) render_html(html, url) Tells the viewer to render the given HTML, with the given URL as base url.
- - (Object) save(path) Tells the viewer to save a screenshot of the current page to the given path.
- - (Object) save_render_tree(path) Tells the viewer to dump the render tree to the given path.
Constructor Details
- (ViewerConnection) initialize(socket)
A new instance of ViewerConnection
15 16 17 |
# File 'lib/celerity/viewer_connection.rb', line 15 def initialize(socket) @socket = socket end |
Method Details
+ (Object) create(host, port)
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 |
- (Object) close
Close the connection.
61 62 63 |
# File 'lib/celerity/viewer_connection.rb', line 61 def close @socket.close rescue nil end |
- (Object) image_data
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 |
- (Object) render_html(html, url)
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 |
- (Object) save(path)
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 |
- (Object) save_render_tree(path)
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 |