summaryrefslogtreecommitdiff
path: root/cook
diff options
context:
space:
mode:
Diffstat (limited to 'cook')
-rw-r--r--cook/cli.scm9
-rw-r--r--cook/html.scm35
-rw-r--r--cook/html.sld8
3 files changed, 51 insertions, 1 deletions
diff --git a/cook/cli.scm b/cook/cli.scm
index 1b5db87..f912a89 100644
--- a/cook/cli.scm
+++ b/cook/cli.scm
@@ -1,5 +1,6 @@
(import (cook parse-internals)
(cook debug)
+ (cook html)
(chibi)
(chibi app)
(chibi config)
@@ -15,6 +16,11 @@
(let ((recipe (parse-cook (file->string recipe-file))))
(display (cook->list recipe))))
+(define (html-cook cfg spec recipe-file)
+ (let ((recipe (parse-cook (file->string recipe-file))))
+ (display (recipe->html recipe))
+ (newline)))
+
(run-application
`(cook
"Cooklang recipe tool"
@@ -22,6 +28,7 @@
(help boolean (#\h ) "show this help"))
(or
(help "Show this help" () (,app-help-command))
- (read "Read recipe in the terminal" () (,read-cook recipe)))
+ (read "Read recipe in the terminal" () (,read-cook recipe))
+ (html "Display recipe in HTML format" () (,html-cook recipe)))
(,cook files ...))
(command-line))
diff --git a/cook/html.scm b/cook/html.scm
new file mode 100644
index 0000000..0f8a501
--- /dev/null
+++ b/cook/html.scm
@@ -0,0 +1,35 @@
+;; TODO
+(define (expand x)
+ (match x
+ (($ <note> text)
+ `(p ,text))
+ (($ <section> name)
+ `(h1 ,name))
+ (($ <step> elements)
+ `(li ,@(map expand elements)))
+ (($ <amount> quantity unit)
+ (list "(" (number->string quantity) unit ")"))
+ (($ (or <ingredient> <cookware> <timer>) name amount)
+ `(span ,@(if name (list name) '())
+ ,@(if amount (expand amount) '())))
+ (($ <recipe> metadata body)
+ `((@raw "<!DOCTYPE html>")
+ (html (body (ol ,@(expand body))))))
+ ((? list? x)
+ (map expand x))
+ ((? string? x)
+ x)
+ (else "")))
+
+(define (recipe->html recipe)
+ (let ((ingredients (recipe-ingredients recipe))
+ (cookware (recipe-cookware recipe))
+ (timers (recipe-timers recipe)))
+ #;(for-each (lambda (x)
+ (display (ingredient-name x))
+ (display ": ")
+ (when (ingredient-amount x)
+ (display (amount-quantity (ingredient-amount x)))
+ (display (amount-unit (ingredient-amount x))))
+ (newline)) ingredients)
+ (sxml->xml (expand recipe))))
diff --git a/cook/html.sld b/cook/html.sld
new file mode 100644
index 0000000..c40752f
--- /dev/null
+++ b/cook/html.sld
@@ -0,0 +1,8 @@
+(define-library (cook html)
+ (import (scheme small)
+ (chibi match)
+ (chibi sxml)
+ (chibi string)
+ (cook parse-internals))
+ (export recipe->html)
+ (include "html.scm"))