Add sample template
This commit is contained in:
57
sample-template.clj
Normal file
57
sample-template.clj
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user