Browse Source

Better text output

master
Stephen Starkey 2 years ago
parent
commit
9459f14310
  1. 10
      install-fortune
  2. 2
      project.clj
  3. 19
      src/lojong.clj

10
install-fortune

@ -0,0 +1,10 @@
#!/usr/bin/env bash
## An example script for taking the results of build-clj and installing it
## into your fortunes folder
pushd target/documents
strfile lojong
cp lojong lojong.dat /usr/share/games/fortunes
rm -f lojong.dat
popd

2
project.clj

@ -14,7 +14,7 @@
; along with lojong. If not, see <https://www.gnu.org/licenses/>.
;
(defproject lojong "0.1.4"
(defproject lojong "0.2.0"
:description "Display random lojong slogans"
:dependencies [[org.clojure/clojure "1.10.1"]
[clj-commons/clj-yaml "0.7.0"]

19
src/lojong.clj

@ -33,10 +33,12 @@
(def slogans
(-> "slogans.yaml" io/resource slurp (yaml/parse-string :keywords false)))
(defrecord Slogan [category slogan description])
(defrecord Slogan [idx category slogan description])
(defn build-category [result [category slogans-in-category]]
(letfn [(new-slogan [[slogan desc]] (Slogan. category slogan desc))]
(letfn [(new-slogan [[slogan-text desc]]
(let [[_ idx slogan] (re-matches #"(\d+)\. (.*)" slogan-text)]
(Slogan. idx category slogan desc)))]
(concat result (map new-slogan slogans-in-category))))
(def slogan-list (reduce build-category [] slogans))
@ -46,22 +48,17 @@
(defn format-description [description]
(if (string? description) description (str/join "\n " description)))
(defn slogan->text [{:keys [category slogan description]}]
(defn slogan->text [{:keys [idx category slogan description]}]
(str
slogan "\n"
(str " " (format-description description))
"\n\n"
"(" category ")"))
category " / " idx))
(def text-slogans (map slogan->text slogan-list))
;; LaTeX
(defn tex-format-slogan [{slogan-text :slogan :as slogan}]
(let [[_ idx content] (re-matches #"(\d+)\. (.*)" slogan-text)]
(assoc slogan :slogan content
:idx idx)))
(defn surround [begin end s] (str begin s end))
(defn tex-format-description [description]
@ -74,9 +71,7 @@
(reduce str)))))
(defn slogan->tex [slogan]
(-> slogan
tex-format-slogan
(update :description tex-format-description)))
(update slogan :description tex-format-description))
;; Program entry

Loading…
Cancel
Save