Created
November 21, 2008 23:39
-
-
Save farleyknight/27696 to your computer and use it in GitHub Desktop.
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 'mechanize' | |
module MathUrl | |
def mathurl_agent | |
@agent ||= WWW::Mechanize.new | |
end | |
def mathurl_img_for(latex) | |
page = math_url_agent.get("http://mathurl.com") | |
form = page.forms.first | |
# You'll probably want to cache this.. | |
form.set_field(:latex => latex || %q{ \sin \frac{\pi}{4} = \frac{\sqrt{2}}{2} }) | |
form.add_field!("make", "make mathURL") | |
result = form.submit | |
image_url = result.uri.to_s.gsub("/\?", "/\?img=") | |
image_tag(image_url) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment