Implement reading template file

This commit is contained in:
2024-04-12 10:21:07 +02:00
parent 5b853a9752
commit 44256e5ed9
7 changed files with 18 additions and 52 deletions

View File

@@ -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;
} }

View File

@@ -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!!!"))))

View File

@@ -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))]))

View File

@@ -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])))

View File

@@ -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))))

View File

@@ -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])

View File

@@ -1,5 +0,0 @@
(ns packer.script
(:use packer.main)
(:gen-class))
(-main)