Skip to content

Commit

Permalink
Rename anonymous capture* functions and format
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe committed Sep 23, 2024
1 parent 2338b76 commit 8168ba7
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions spork/temple.janet
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,25 @@
[path &]
(with-dyns [:current-file path]
(let [tmpl (create (slurp path) path)]
@{'render @{:doc "Main template function."
:value (fn render [&keys args] (tmpl args))}
'render-dict @{:doc "Template function, but pass arguments as a dictionary."
:value tmpl}
'capture @{:doc "Template function that returns buffer of rendered template."
:value (fn render [&keys args]
(def b @"")
(with-dyns [:out b] (tmpl args)
b))}
'capture-dict @{:doc "Template function that returns buffer of rendered template,
@{'render
@{:doc "Main template function."
:value (fn render [&keys args] (tmpl args))}
'render-dict
@{:doc "Template function, but pass arguments as a dictionary."
:value tmpl}
'capture
@{:doc "Template function that returns buffer of rendered template."
:value (fn capture [&keys args]
(def b @"")
(with-dyns [:out b] (tmpl args))
b)}
'capture-dict
@{:doc "Template function that returns buffer of rendered template,
but pass arguments as a dictionary."
:value (fn render [args]
(def b @"")
(with-dyns [:out b] (tmpl args)
b))}})))
:value (fn capture-dict [args]
(def b @"")
(with-dyns [:out b] (tmpl args))
b)}})))

(defn add-loader
"Adds the custom template loader to Janet's module/loaders and
Expand Down

0 comments on commit 8168ba7

Please sign in to comment.