# server.rb require 'sinatra' require 'htmlentities' get '/' do servings = params['servings'] scaling_factor = params['scale'] `cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"` end get '/ingredient/:ingredient' do ingredient = HTMLEntities.new.decode params['ingredient'] `cd ..; echo "(display (html-wrap (cookbook-as-html (recipes-by-ingredients '(\\"#{ingredient}\\" cookbook)))))" | petite -q "batch.scm"` end get '/recipe/:title' do title = HTMLEntities.new.decode params['title'] servings = params['servings'] scaling_factor = params['scale'] if servings puts "servings" `cd ..; echo "(display (html-wrap (recipe-as-html (scale-recipe-by-servings #{servings} (recipe-by-name \\"#{title}\\" cookbook)))))" | petite -q "batch.scm"` elsif scaling_factor `cd ..; echo "(display (html-wrap (recipe-as-html (scale-recipe-by-factor #{scaling_factor} (recipe-by-name \\"#{title}\\" cookbook)))))" | petite -q "batch.scm"` else `cd ..; echo "(display (html-wrap (recipe-as-html (recipe-by-name \\"#{title}\\" cookbook))))" | petite -q "batch.scm"` end end