Make some working scaffolding
This commit is contained in:
229
flake.lock
generated
Normal file
229
flake.lock
generated
Normal file
@@ -0,0 +1,229 @@
|
||||
{
|
||||
"nodes": {
|
||||
"clj-nix": {
|
||||
"inputs": {
|
||||
"devshell": "devshell",
|
||||
"nix-fetcher-data": "nix-fetcher-data",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1711197542,
|
||||
"narHash": "sha256-RMM+G49X56W8gE2sg08TUsuR30KcU0LNLttsSRgxTCM=",
|
||||
"owner": "jlesquembre",
|
||||
"repo": "clj-nix",
|
||||
"rev": "20109727c6623b486d37fbd957d64c2a8232ccde",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "jlesquembre",
|
||||
"repo": "clj-nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"devshell": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"clj-nix",
|
||||
"nixpkgs"
|
||||
],
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1700815693,
|
||||
"narHash": "sha256-JtKZEQUzosrCwDsLgm+g6aqbP1aseUl1334OShEAS3s=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "7ad1c417c87e98e56dcef7ecd0e0a2f2e5669d51",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-part": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1685546676,
|
||||
"narHash": "sha256-XDbjJyAg6odX5Vj0Q22iI/gQuFvEkv9kamsSbQ+npaI=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "6ef2707776c6379bc727faf3f83c0dd60b06e0c6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1685546676,
|
||||
"narHash": "sha256-XDbjJyAg6odX5Vj0Q22iI/gQuFvEkv9kamsSbQ+npaI=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "6ef2707776c6379bc727faf3f83c0dd60b06e0c6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "flake-parts",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-fetcher-data": {
|
||||
"inputs": {
|
||||
"flake-part": "flake-part",
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": [
|
||||
"clj-nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1685572850,
|
||||
"narHash": "sha256-lYKEqFG9F84xu51H1rM1u+Ip88cINL0+W26sT+vFEZc=",
|
||||
"owner": "jlesquembre",
|
||||
"repo": "nix-fetcher-data",
|
||||
"rev": "f14967db6c92c79b77419f52c22a698518c91120",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "jlesquembre",
|
||||
"repo": "nix-fetcher-data",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1701253981,
|
||||
"narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"dir": "lib",
|
||||
"lastModified": 1682879489,
|
||||
"narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "lib",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib_2": {
|
||||
"locked": {
|
||||
"dir": "lib",
|
||||
"lastModified": 1682879489,
|
||||
"narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "lib",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1712608508,
|
||||
"narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"clj-nix": "clj-nix",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
15
flake.nix
15
flake.nix
@@ -7,12 +7,14 @@
|
||||
clj-nix.url = "github:jlesquembre/clj-nix";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, clj-nix }:
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
clj-nix,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: {
|
||||
|
||||
packages = {
|
||||
|
||||
default = clj-nix.lib.mkCljApp {
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
modules = [
|
||||
@@ -20,8 +22,8 @@
|
||||
# https://jlesquembre.github.io/clj-nix/options/
|
||||
{
|
||||
projectSrc = ./.;
|
||||
name = "me.lafuente/cljdemo";
|
||||
main-ns = "hello.core";
|
||||
name = "com.bartlomiejpluta.packer";
|
||||
main-ns = "packer.main";
|
||||
|
||||
nativeImage.enable = true;
|
||||
|
||||
@@ -29,7 +31,6 @@
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
33
src/packer/core.clj
Normal file
33
src/packer/core.clj
Normal file
@@ -0,0 +1,33 @@
|
||||
(ns packer.core (:gen-class))
|
||||
|
||||
|
||||
(def profile #{:t-shirt :tablet})
|
||||
|
||||
(defn produce-category-name [category i18n]
|
||||
(str "### " (get i18n category)))
|
||||
|
||||
(defn produce-item [item nights i18n]
|
||||
(let [qnt (int (Math/ceil ((:quantity item) nights)))]
|
||||
(str "- [ ] " (get i18n (:key item)) (if (> qnt 1) (str " x" qnt) ""))))
|
||||
|
||||
(defn produce-items [items nights i18n]
|
||||
(->> items
|
||||
(map #(produce-item % nights i18n))
|
||||
(clojure.string/join "\n")
|
||||
))
|
||||
|
||||
(defn produce-category [category items nights i18n]
|
||||
(if (empty? items)
|
||||
""
|
||||
(str
|
||||
(produce-category-name category i18n)
|
||||
"\n"
|
||||
(produce-items items nights i18n))))
|
||||
|
||||
(defn produce-all [store profile nights i18n]
|
||||
(->> store
|
||||
keys
|
||||
(map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))]))
|
||||
(filter #(not (empty? (second %))))
|
||||
(map #(produce-category (first %) (second %) nights i18n))
|
||||
(clojure.string/join "\n\n")))
|
||||
27
src/packer/database.clj
Normal file
27
src/packer/database.clj
Normal file
@@ -0,0 +1,27 @@
|
||||
(ns packer.database
|
||||
(:use packer.model)
|
||||
(:require packer.i18n.pl)
|
||||
(: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))
|
||||
]
|
||||
})
|
||||
|
||||
; Define profile getter
|
||||
(defn get-profile []
|
||||
(->> store
|
||||
vals
|
||||
flatten
|
||||
(map #(:key %))))
|
||||
9
src/packer/i18n/pl.clj
Normal file
9
src/packer/i18n/pl.clj
Normal file
@@ -0,0 +1,9 @@
|
||||
(ns packer.i18n.pl (:gen-class))
|
||||
|
||||
(def dict {
|
||||
:electronics "Elektronika"
|
||||
:cloths "Ubrania"
|
||||
:t-shirt "T-shirt"
|
||||
:smartphone "Telefon komórkowy"
|
||||
:tablet "Tablet"
|
||||
})
|
||||
8
src/packer/main.clj
Normal file
8
src/packer/main.clj
Normal file
@@ -0,0 +1,8 @@
|
||||
(ns packer.main
|
||||
(:use packer.model)
|
||||
(:require packer.core packer.database)
|
||||
(:gen-class))
|
||||
|
||||
(defn -main
|
||||
[& args]
|
||||
(println (packer.core/produce-all packer.database/store (packer.database/get-profile) 15 packer.database/i18n)))
|
||||
3
src/packer/model.clj
Normal file
3
src/packer/model.clj
Normal file
@@ -0,0 +1,3 @@
|
||||
(ns packer.model (:gen-class))
|
||||
|
||||
(defrecord Item [key quantity])
|
||||
5
src/packer/script.clj
Normal file
5
src/packer/script.clj
Normal file
@@ -0,0 +1,5 @@
|
||||
(ns packer.script
|
||||
(:use packer.main)
|
||||
(:gen-class))
|
||||
|
||||
(-main)
|
||||
Reference in New Issue
Block a user