Created
January 15, 2012 22:51
-
-
Save rubiety/1617848 to your computer and use it in GitHub Desktop.
Jazzity PngRenderer using Capybara Webkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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