(import-macros {:compile-html HTML} :macros) (local templates (require :templates)) (local lib (require :lib)) (local shop (require :shop)) (fn text->html [text] (assert (= (type text) "string")) (var result "") (var from 1) (var to (text:find "\n%s*\n%s*" from)) (while to (set result (.. result "

" (text:sub from (- to 1)) "

\n")) (set from (+ to 2)) (set to (text:find "\n%s*\n%s*" from))) (.. result "

" (text:sub from) "

")) (fn find-product [db name] (. (_G.must (luna.db.query-assoc db "SELECT products.name, products.title, products.short_description AS \"short-description\", products.description, products.price_per AS \"price-per\", products.type, products.region, products.stock, products.volume, products.packaging, products.published, products.year, products.image1, products.image2, products.image3, products.image4, products.image5 FROM products WHERE products.name = ?" [name])) 1)) (fn content [product basket agreed-to-cookies? authenticated?] (local redirect-url (.. "/shop/" product.name)) (local images []) (for [i 1 5] (table.insert images (. product (.. "image" i)))) [(HTML [:aside {} (templates.header "/shop" authenticated?) (if (< 0 (# basket)) (templates.basket basket redirect-url) "") (templates.conditions-block) (templates.address-block) (templates.contact-block)]) (HTML [:div {:class "content"} (if (not agreed-to-cookies?) (templates.cookies-agreement) "") ;; this method of going back to the list requires JS and is bug prone but ;; at the same time it's the simplest one. doing the same thing without ;; JS would require storing "back URL" in query parameter (which will make ;; URLs ugly and also hurt SEO) or in a cookie (which is brittle) ;; TODO: also add