~subsetpark/bagatto

bd6b7e0ea3a93c689d1bf2e66efc97e11e792104 — Zach Smith 11 months ago 3833568
Working threads with new markable SHA
M bagatto.janet => bagatto.janet +2 -3
@@ 1,6 1,6 @@
(import sh)
(import temple)
(import moondown)
(import markable)
(import path)
(import jdn)
(import json)


@@ 392,8 392,7 @@
  "Render a markdown string into HTML."
  [md &opt opts]
  (default opts [:footnotes :smart])
  # TODO: Use markable when this bug is fixed: https://github.com/pyrmont/markable/issues/2
  (moondown/render (string md)))
  (markable/markdown->html (string md) opts))

(defn mmarkdown->html
  ```

A demo/mmd/index.janet => demo/mmd/index.janet +7 -0
@@ 0,0 1,7 @@
(bagatto/set-output-dir! "site")

(def data {:pages {:src (bagatto/slurp-* "pages/*.md")
                   :attrs bagatto/parse-mmarkdown}})
(def site {:pages {:each :pages
                   :dest (bagatto/%p "pages" '%i "title" '% ".html")
                   :out (bagatto/renderer "templates/page") }})

A demo/mmd/pages/about.md => demo/mmd/pages/about.md +4 -0
@@ 0,0 1,4 @@
title: About Me
---

This is a really simple example of using multimarkdown metadata.

A demo/mmd/templates/page.temple => demo/mmd/templates/page.temple +1 -0
@@ 0,0 1,1 @@
{- (bagatto/mmarkdown->html (get-in args [:_item :contents])) -}

M lockfile.jdn => lockfile.jdn +1 -2
@@ 3,8 3,7 @@
  {:sha "70ae525ad8ab0bf08ccb42e9544ac2bd2103df35" :repo "https://github.com/andrewchambers/janet-posix-spawn.git"}
  {:sha "ed7e83e8779e2a54e23bbbcc75366ade2dd5372a" :repo "https://git.sr.ht/~bakpakin/temple"}
  {:sha "ca257dd40159cf25bc49869386208df630b88336" :repo "https://github.com/pyrmont/testament"}
  {:sha "80785d8467e950e8b8c44ea7d0da3f6e1684b952" :repo "https://github.com/joy-framework/tester"}
  {:sha "b6dd2f3dcfebd26b027234a84029ee099b83b1f0" :repo "https://github.com/janet-lang/path.git"}
  {:sha "61437d96b5df6eb7e524f88847e7d7521201662d" :repo "https://github.com/janet-lang/json.git"}
  {:sha "4226a4cae548fde38358aa1fdb6d6a90bf5fe175" :repo "https://github.com/andrewchambers/janet-sh.git"}
  {:sha "64db559d6be781a05adee4b42be6ad7a4d575380" :repo "https://github.com/pyrmont/markable"}]
  {:sha "8d55732726332c3ae86fb934b2e8c9c10327be72" :repo "https://github.com/pyrmont/markable"}]

M main.janet => main.janet +2 -1
@@ 8,7 8,7 @@
(defn- index-value
  [env sym index]
  (try ((env sym) :value)
       ([err fib] (error/eval-error sym index))))
       ([err fib] (propagate (error/eval-error sym index) fib))))

(defn- prepare-env [index]
  (-> index


@@ 30,6 30,7 @@
          env (prepare-env index)]

      (env/prepare-environment! env)
      (env/populate-exec-blacklist!)

      (if (args "repl")
        # REPL mode: Enter a REPL to experiment with the contents of the

M project.janet => project.janet +0 -1
@@ 4,7 4,6 @@
  :dependencies ["https://github.com/andrewchambers/janet-sh.git"
                 "https://git.sr.ht/~bakpakin/temple"
                 "https://github.com/pyrmont/markable"
                 "https://github.com/joy-framework/moondown.git"
                 "https://github.com/janet-lang/path.git"
                 "https://github.com/andrewchambers/janet-jdn.git"
                 "https://github.com/janet-lang/json.git"

M src/core.janet => src/core.janet +2 -0
@@ 7,6 7,7 @@
(import src/loaders)
(import src/generators)
(import src/writers)
(import src/env)

(def bagatto
  ```


@@ 20,6 21,7 @@
  (thread/new (fn [parent]
                (temple/add-loader)
                (merge-into root-env bagatto)
                (setdyn :executable-blacklist env/exec-blacklist)
                (f parent))
              1 :hc))


M src/env.janet => src/env.janet +6 -10
@@ 2,6 2,7 @@
(import sh)

(def required-checks @{})
(def exec-blacklist @{})

(defmacro defrequire
  ```


@@ 29,25 30,20 @@
    nil :ok
    janet-path (put root-env :syspath janet-path)))

(defn add-exec-blacklist
(defn populate-exec-blacklist!
  ```
  Iterate through all the executables declared with `defrequire` and
  check for their existence in the path. Add a blacklist of all
  executables that are absent from the path to the given environment.
  ```
  [env]
  (let [blacklist @{}]
    (loop [check :keys required-checks]
  []
  (loop [check :keys required-checks]
      (unless (on-path? check)
        (put blacklist check true)))
    (put env :executable-blacklist blacklist)))
        (put exec-blacklist check true))))

(defn prepare-environment!
  [env]
  (temple/add-loader)
  # Monkey-patch the temple environment with the functions defined
  # in the index module.
  (merge-into temple/base-env env)
  (setdyn :executable-blacklist (env :executable-blacklist)))

(defn thread-env [bagatto])
  (merge-into temple/base-env env))

M src/error.janet => src/error.janet +24 -27
@@ 18,13 18,12 @@ Current render context:

(defn eval-error
  [sym filename]
  (error
    (string "Expected symbol " sym "; couldn't be found after evaluating " filename)))
  (string "Expected symbol " sym "; couldn't be found after evaluating " filename))

(defn path-error
  [err f args-type]
  (let [err (string/format
              ```
  (string/format
   ```

Encountered error generating path for site spec %s:
             


@@ 33,16 32,15 @@ Encountered error generating path for site spec %s:
Expected path function signature:
(defn %s %s "foo/bar/...")
             ```
              (spec-name)
              err
              (f-name f)
              (case args-type :d "[data]" :di "[data item]"))]
    (error err)))
   (spec-name)
   err
   (f-name f)
   (case args-type :d "[data]" :di "[data item]")))

(defn renderer-error
  [err f args-type]
  (let [err (string/format
              ```
  (string/format
   ```

Encountered error rendering output for site spec %s:



@@ 51,17 49,16 @@ Encountered error rendering output for site spec %s:
Expected renderer function signature:
(defn %s %s "<html>...")
             ```
              (spec-name)
              err
              (format-renderer-context)
              (f-name f)
              (case args-type :d "[data]" :di "[data item]"))]
    (error err)))
   (spec-name)
   err
   (format-renderer-context)
   (f-name f)
   (case args-type :d "[data]" :di "[data item]")))

(defn attrs-error
  [err attrs-f]
  (error (string/format
           ```
  (string/format
   ```

Encountered error getting attrs for data spec %s:



@@ 70,9 67,9 @@ Encountered error getting attrs for data spec %s:
Expected parse function signature:
(defn %s [src attrs] attrs)
          ```
           (spec-name)
           err
           (or (disasm attrs-f :name) "f"))))
   (spec-name)
   err
   (or (disasm attrs-f :name) "f")))

(defn data-error
  [spec]


@@ 104,8 101,8 @@ Specification can be one of the following:

(defn loader-spec-error
  [spec-name f]
  (error (string/format
           ```
  (string/format
   ```

Received invalid loader for data spec : %q



@@ 116,6 113,6 @@ Loader should return either:
{:each file-spec-sequence}
{:some single-file-spec}
          ```
           spec-name
           (f-name f)
           ((disasm f) :arity))))
   spec-name
   (f-name f)
   ((disasm f) :arity)))

M src/generators.janet => src/generators.janet +5 -4
@@ 13,12 13,13 @@

(defn- apply-path [f args args-type]
  (try (maybe-apply f args)
    ([err fib] (error/path-error err f args-type))))
       ([err fib]
        (propagate (error/path-error err f args-type) fib))))

(defn- apply-renderer [f args args-type]
  (try (maybe-apply f args)
    ([err fib]
      (error/renderer-error err f args-type))))
       ([err fib]
        (propagate (error/renderer-error err f args-type) fib))))

(defn render-each-generator
  [data spec-name filter site-selector path-generator renderer]


@@ 29,7 30,7 @@
    (loop [item :in (data site-selector)]
      (when (filter data item)
        (let [path (apply-path path-generator [data item] :di)
              contents (apply-renderer renderer [data item] :di) ]
              contents (apply-renderer renderer [data item] :di)]
          (array/push res [:write path contents]))))
    (:send parent [:res spec-name res])))


M src/loaders.janet => src/loaders.janet +2 -2
@@ 9,7 9,7 @@
  (let [base-attrs @{:path filename :contents file-contents}]
    (if file-contents
      (try (parser file-contents base-attrs)
        ([err fib] (error/attrs-error err parser)))
           ([err fib] (propagate (error/attrs-error err parser) fib)))
      base-attrs)))

(defn from-file-spec-loader


@@ 23,7 23,7 @@
    (threads/print "Loading " spec-name "...")

    (let [loader-specs (try (loader)
                         ([err fib] (error/loader-spec-error spec-name loader)))
                            ([err fib] (propagate (error/loader-spec-error spec-name loader) fib)))
          res (match loader-specs
                {:each ind}
                (do

M src/multimarkdown.janet => src/multimarkdown.janet +5 -4
@@ 14,10 14,11 @@
       (string/trim)))

(env/defrequire
  "multimarkdown"
  metadata [md]
  (let [keys (metadata-keys md)]
    (table ;(mapcat |[$0 (metadata-value md $0)] keys))))
 "multimarkdown"
 metadata
 [md]
 (let [keys (metadata-keys md)]
   (table ;(mapcat |[$0 (metadata-value md $0)] keys))))


(env/defrequire