Class: HTMLRender::Renderers::HTTPRenderer

Inherits:
Base
  • Object
show all
Defined in:
lib/html_render/renderers.rb

Overview

Renders using an HTTP server built for the very purpose.

One should POST the HTML to the given URL, and the server should respond with a PNG image.

Defined Under Namespace

Classes: ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ HTTPRenderer

Returns a new instance of HTTPRenderer.



22
23
24
# File 'lib/html_render/renderers.rb', line 22

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



20
21
22
# File 'lib/html_render/renderers.rb', line 20

def url
  @url
end

Instance Method Details

#render(html) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/html_render/renderers.rb', line 26

def render(html)
  client = HTTPClient.new

  begin
    response = client.post(url, html)
  end

  if response.status != 200
    raise ServerError.new("Unexpected HTTP server response from #{url}: #{response.inspect}")
  end

  HTMLRender::Images::PNGImage.new(response.content)
end