add recipe lookup by title

This commit is contained in:
Christoffer Müller Madsen 2017-04-06 00:22:37 +02:00
parent 989e8747e4
commit 41344fe84c
2 changed files with 16 additions and 2 deletions

View File

@ -65,3 +65,13 @@
(lambda (recipes search-ingredients) (lambda (recipes search-ingredients)
(filter (lambda (x) (contains-ingredients? x search-ingredients)) (filter (lambda (x) (contains-ingredients? x search-ingredients))
recipes))) recipes)))
(define recipe-by-name
(lambda (recipes name)
(if (null? recipes)
#f
(let ((recipe (car recipes)))
(if (equal? (title recipe)
name)
recipe
(recipe-by-name (cdr recipes) name))))))

View File

@ -6,8 +6,12 @@ get '/' do
`cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"` `cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"`
end end
get '/:ingredient' do get '/ingredient/:ingredient' do
ingredient = HTMLEntities.new.decode params['ingredient'] ingredient = HTMLEntities.new.decode params['ingredient']
puts ingredient
`cd ..; echo "(display (html-wrap (cookbook-as-html (recipes-by-ingredients cookbook '(\\"#{ingredient}\\")))))" | petite -q "batch.scm"` `cd ..; echo "(display (html-wrap (cookbook-as-html (recipes-by-ingredients cookbook '(\\"#{ingredient}\\")))))" | petite -q "batch.scm"`
end end
get '/recipe/:title' do
title = HTMLEntities.new.decode params['title']
`cd ..; echo "(display (html-wrap (recipe-as-html (recipe-by-name cookbook \\"#{title}\\"))))" | petite -q "batch.scm"`
end