Implement reading template file
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
name = "com.bartlomiejpluta.packer";
|
name = "com.bartlomiejpluta.packer";
|
||||||
main-ns = "packer.main";
|
main-ns = "packer.main";
|
||||||
|
|
||||||
nativeImage.enable = true;
|
nativeImage.enable = false;
|
||||||
|
|
||||||
# customJdk.enable = true;
|
# customJdk.enable = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
(ns hello.core
|
|
||||||
(:require
|
|
||||||
[clojure.string :as string])
|
|
||||||
(:gen-class))
|
|
||||||
|
|
||||||
(defn -main
|
|
||||||
[& args]
|
|
||||||
(println (str "Hello from " (string/upper-case "clojure!!!"))))
|
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"\n"
|
"\n"
|
||||||
(produce-items items nights i18n))))
|
(produce-items items nights i18n))))
|
||||||
|
|
||||||
(defn produce-all [store profile nights i18n]
|
(defn produce [store profile nights i18n]
|
||||||
(->> store
|
(->> store
|
||||||
keys
|
keys
|
||||||
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
(ns packer.database
|
|
||||||
(:use packer.model)
|
|
||||||
(:require packer.i18n.pl)
|
|
||||||
(:require [packer.util :as util])
|
|
||||||
(:gen-class))
|
|
||||||
|
|
||||||
; Choose language to Polish
|
|
||||||
(def i18n packer.i18n.pl/dict)
|
|
||||||
|
|
||||||
; Define store
|
|
||||||
(defn x [x] (fn [_] x))
|
|
||||||
(def store {
|
|
||||||
:cloths [
|
|
||||||
(->Item :t-shirt #(/ % 4))
|
|
||||||
]
|
|
||||||
|
|
||||||
:electronics [
|
|
||||||
(->Item :smartphone (x 2))
|
|
||||||
(->Item :tablet (x 1))
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
(defn simple-preset [question items seq]
|
|
||||||
(if (util/ask-bool question)
|
|
||||||
(concat seq items)
|
|
||||||
seq))
|
|
||||||
|
|
||||||
; Define profile getter
|
|
||||||
(defn get-profile [nights]
|
|
||||||
(->> [:t-shirt]
|
|
||||||
(simple-preset "Bierzesz telefon?" [:smartphone])))
|
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
(ns packer.main
|
(ns packer.main
|
||||||
(:use packer.model)
|
(:use packer.model)
|
||||||
(:require packer.core packer.database packer.util)
|
(:require [packer.core :as core]
|
||||||
|
[packer.util :as util])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(defn -main
|
|
||||||
[& args]
|
(defn eval-file [file]
|
||||||
(let [nights (packer.util/ask-int (:nights? packer.database/i18n))]
|
(map eval (read-string (str \( (slurp file) \)))))
|
||||||
(println (packer.core/produce-all packer.database/store (packer.database/get-profile nights) nights packer.database/i18n))))
|
|
||||||
|
(defn -main [& args]
|
||||||
|
(let [script (last (eval-file (first args)))
|
||||||
|
i18n (:i18n script)
|
||||||
|
nights (util/ask-int (:nights? i18n))
|
||||||
|
store (:store script)
|
||||||
|
profile ((:profile script) nights)]
|
||||||
|
(println (core/produce store profile nights i18n))))
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
(ns packer.model (:gen-class))
|
(ns packer.model (:gen-class))
|
||||||
|
|
||||||
(defrecord Item [key quantity])
|
(defrecord Item [key quantity])
|
||||||
|
|
||||||
|
(defrecord Template [store i18n profile])
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
(ns packer.script
|
|
||||||
(:use packer.main)
|
|
||||||
(:gen-class))
|
|
||||||
|
|
||||||
(-main)
|
|
||||||
Reference in New Issue
Block a user