(.module: [lux (#- Module)] (lux (control monad ["ex" exception (#+ exception:)]) (data [error] [text] text/format) (world [file (#+ File System)] [blob (#+ Blob)])) [/////host] [// (#+ Module)]) (type: #export Document File) (exception: #export (cannot-prepare {archive File} {module Module}) (ex.report ["Archive" archive] ["Module" module])) (def: #export (archive System root) (All [m] (-> (System m) File File)) (<| (format root (:: System separator)) (`` (for {(~~ (static /////host.common-lisp)) /////host.common-lisp (~~ (static /////host.js)) /////host.js (~~ (static /////host.jvm)) /////host.jvm (~~ (static /////host.lua)) /////host.lua (~~ (static /////host.php)) /////host.php (~~ (static /////host.python)) /////host.python (~~ (static /////host.r)) /////host.r (~~ (static /////host.ruby)) /////host.ruby (~~ (static /////host.scheme)) /////host.scheme})))) (def: #export (document System root module) (All [m] (-> (System m) File Module Document)) (let [archive (..archive System root)] (|> module (//.sanitize System) (format archive (:: System separator))))) (def: #export (prepare System root module) (All [m] (-> (System m) File Module (m Any))) (do (:: System &monad) [#let [archive (..archive System root) document (..document System root module)] document-exists? (file.exists? System document)] (if document-exists? (wrap []) (do @ [outcome (:: System try (:: System make-directory document))] (case outcome (#error.Success output) (wrap output) (#error.Error _) (:: System throw cannot-prepare [archive module])))))) (def: #export (write System root content name) (All [m] (-> (System m) File Blob Text (m Any))) (:: System write content (..document System root name))) (def: #export (module System root document) (All [m] (-> (System m) File Document (Maybe Module))) (case (text.split-with (..archive System root) document) (#.Some ["" post]) (let [raw (text.replace-all (:: System separator) "/" post)] (if (text.starts-with? "/" raw) (text.clip' +1 raw) (#.Some raw))) _ #.None))