From 41344fe84c0d572bdb1f1578552df1c9bbd52ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Thu, 6 Apr 2017 00:22:37 +0200 Subject: [PATCH] add recipe lookup by title --- parse.scm | 10 ++++++++++ web/server.rb | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/parse.scm b/parse.scm index 54cea99..b238ce7 100644 --- a/parse.scm +++ b/parse.scm @@ -65,3 +65,13 @@ (lambda (recipes search-ingredients) (filter (lambda (x) (contains-ingredients? x search-ingredients)) 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)))))) diff --git a/web/server.rb b/web/server.rb index 747652b..032592a 100644 --- a/web/server.rb +++ b/web/server.rb @@ -6,8 +6,12 @@ get '/' do `cd ..; echo "(display (html-wrap (cookbook-as-html cookbook)))" | petite -q "batch.scm"` end -get '/:ingredient' do +get '/ingredient/:ingredient' do 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"` 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