Skip to content

Commit

Permalink
simplify and fix: loader/script-name-from-component-name (#1648)
Browse files Browse the repository at this point in the history
* simplify and fix: `script-name-from-component-name`

* fix test model paths
  • Loading branch information
muazzam0x48 authored Jan 9, 2025
1 parent 62081fa commit 81ce027
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/agentlang/lang/tools/loader.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@
(load-components component-scripts model-root false)))

(defn- script-name-from-component-name [component-name]
(loop [s (subs (str component-name) 1), sep "", result []]
(if-let [c (first s)]
(cond
(Character/isUpperCase c) (recur (rest s) "_" (conj result sep (Character/toLowerCase c)))
(or (= \/ c) (= \. c)) (recur (rest s) "" (conj result java.io.File/separator))
:else (recur (rest s) sep (conj result c)))
(str (s/join result) (u/get-script-extn)))))
(-> component-name
name
(s/replace #"\." "/")
(s/replace #"([a-zA-Z])([0-9])" "$1_$2")
(s/replace #"([a-z])([A-Z])" "$1_$2")
(s/replace #"([A-Z][A-Z])([a-z])" "$1_$2")
s/lower-case
(str (u/get-script-extn))))

(defn load-components-from-model
([model model-root load-from-resource]
Expand Down

0 comments on commit 81ce027

Please sign in to comment.