From 3554d1bd6fd9ac69dfe6598b520de734e9743de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Fri, 12 Apr 2024 10:33:58 +0200 Subject: [PATCH] Add sample template --- sample-template.clj | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sample-template.clj diff --git a/sample-template.clj b/sample-template.clj new file mode 100644 index 0000000..8bd4bac --- /dev/null +++ b/sample-template.clj @@ -0,0 +1,57 @@ +(use 'packer.model) +(require 'packer.util) + +; Define some useful function +; to provide a constant number of items. +(defn x [n] (fn [_] n)) + +; Define a store - the single source +; of truth of all items from which +; we are going to choose what we want to pack. +; The items are grouped by categories. +(def store { + :cloths [ + (->Item :t-shirt #(/ % 4)) + ] + + :electronics [ + (->Item :smartphone (x 1)) + (->Item :tablet (x 1)) + (->Item :laptop (x 1)) + ] +}) + +; Define the display names for each +; item, category and question. +(def i18n { + :nights? "How many nights?" + :tablet? "Do you need your tablet there?" + :laptop? "Do you need your laptop there?" + :electronics "Electronics" + :cloths "Cloths" + :t-shirt "T-shirt" + :smartphone "Smartphone" + :tablet "Tablet" + :laptop "Laptop" +}) + +; Define some utility function +; to generate preset basing on some question +(defn preset [question items seq] + (if (packer.util/ask-bool (get i18n question)) + (concat seq items) + seq)) + +; Define profile - a function which takes +; a number of provided nights and produces +; the sequence of all items which should +; be in the target list. If the sequence is empty +; no item will be produced on the target list. +(defn profile [nights] + (->> [:smartphone :t-shirt] + (preset :tablet? [:tablet]) + (preset :laptop? [:laptop]))) + +; Wrap it up together. It should be +; the last expression in the file. +(->Template store i18n profile) \ No newline at end of file