2017-04-05 22:13:59 +00:00
|
|
|
# server.rb
|
|
|
|
require 'sinatra'
|
|
|
|
require 'htmlentities'
|
|
|
|
|
|
|
|
get '/' do
|
2017-04-08 19:12:14 +00:00
|
|
|
servings = params['servings']
|
|
|
|
scaling_factor = params['scale']
|
2017-04-05 22:13:59 +00:00
|
|
|
`cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"`
|
|
|
|
end
|
|
|
|
|
2017-04-05 22:22:37 +00:00
|
|
|
get '/ingredient/:ingredient' do
|
2017-04-05 22:13:59 +00:00
|
|
|
ingredient = HTMLEntities.new.decode params['ingredient']
|
2017-04-08 19:12:14 +00:00
|
|
|
`cd ..; echo "(display (html-wrap (cookbook-as-html (recipes-by-ingredients '(\\"#{ingredient}\\" cookbook)))))" | petite -q "batch.scm"`
|
2017-04-05 22:13:59 +00:00
|
|
|
end
|
2017-04-05 22:22:37 +00:00
|
|
|
|
|
|
|
get '/recipe/:title' do
|
|
|
|
title = HTMLEntities.new.decode params['title']
|
2017-04-08 19:12:14 +00:00
|
|
|
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
|
2017-04-05 22:22:37 +00:00
|
|
|
end
|