Skip to content

Instantly share code, notes, and snippets.

@rubiety
Created January 15, 2012 22:51
Show Gist options
  • Save rubiety/1617848 to your computer and use it in GitHub Desktop.
Save rubiety/1617848 to your computer and use it in GitHub Desktop.
Jazzity PngRenderer using Capybara Webkit
require "capybara/rails"
class PngRenderer
include Capybara::DSL
DEFAULT_PATH = Rails.root.join("public/images/rendered")
def initialize(url)
@url = url
end
def render(file_path = nil)
Capybara.current_driver = :webkit
visit @url
page.driver.render file_path || "#{DEFAULT_PATH}#{@url}.png"
end
end
# Usage:
PngRenderer.new("/chords/major-7/staff").render # => public/images/rendered/chords/major-7/staff.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment