Class: HTMLRender::Renderers::HTTPRenderer
- 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
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ HTTPRenderer
constructor
A new instance of HTTPRenderer.
- #render(html) ⇒ Object
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
#url ⇒ Object
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 |