From 98648ee16357206a4a48d9ae6788151709d9e71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Wed, 5 Apr 2017 15:02:47 +0200 Subject: [PATCH] add html parser --- html.scm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 html.scm diff --git a/html.scm b/html.scm new file mode 100644 index 0000000..eecbde1 --- /dev/null +++ b/html.scm @@ -0,0 +1,71 @@ +(define html-wrap + (lambda (body) + (string-append "" + body + "" + ))) + +(define html-wrap-list + (lambda (list-html) + (string-append "" + ))) + +(define cookbook-as-html + (lambda (cookbook) + (cookbook-as-html-rec cookbook ""))) + +(define cookbook-as-html-rec + (lambda (cookbook html) + (if (null? cookbook) + html + (let ((recipe (car cookbook))) + (cookbook-as-html-rec (cdr cookbook) + (string-append html + (recipe-as-html recipe) + "
"))) + ))) + +(define recipe-as-html + (lambda (recipe) + (string-append "

" + (title recipe) + "

" + "Ingredients
" + (ingredients-as-html (ingredients recipe)) + "
Steps
" + (steps-as-html (steps recipe)) + "
"))) + +(define pretty-ingredient + (lambda (ingredient) + (let* ((name (ingredient-name ingredient)) + (amount (number->string (ingredient-amount ingredient))) + (unit (ingredient-unit ingredient))) + (string-append amount + " " + unit + " " + name)))) + +(define ingredients-as-html + (lambda (ingredients) + (list-as-html (map (lambda (x) (pretty-ingredient x)) ingredients)))) + +(define steps-as-html + (lambda (steps) + (list-as-html steps))) + +(define list-as-html + (lambda (list) + (html-wrap-list (list-as-html-rec list "")))) + +(define list-as-html-rec + (lambda (list html) + (if (null? list) + html + (list-as-html-rec (cdr list) (string-append html + "
  • " + (car list) + "
  • \n")))))