2017-09-29

(sph filesystem asset-compiler)

configuration format and helpers to process and concatenate files from multiple sources.

part of sph-lib

library description

for example to compile from many files in different preprocessor formats into one target format file.

data structures

  config: hashtable:{symbol:output-format -> (config-output config-input ...)}

  config-output: #(symbol:id string:suffix false/procedure:processor-output)

  config-input: #(symbol:name source-match? false/procedure:processor-input)

  config-format: (config-output config-input ...)

  source-match? :: boolean/procedure:{any:source -> boolean}

  processor-input :: source-element port:output any:processor-options ->

  processor-output :: procedure:input->port port:output-port any:processor-options ->

  sources: (any:processor-dependent ...)

syntax

  ac-config :: (out-id suffix out-proc) (in-id matcher in-proc) ... -> hashtable

  ac-config-input :: id matcher processor -> vector

  ac-config-output :: id suffix processor -> vector

example config

  (define my-ac-config

    (ac-config

      ( (html ".htm" (l (process-input out-port options) (process-input out-port)))

        (html #t (l (source out-port options) (file->port source out-port)))

        (sxml #t s-template-sxml->html))

      ( (js #t js-output-processor)

        (js #t ac-input-copy)

        (sjs #t s-template-sescript->js))))

import name

(sph filesystem asset-compiler)

exports

ac-compile

procedure

signature

config output-format sources port [processor-options] ->

hashtable symbol list port [any] -> false/unspecified

description

"processor-options" is an optional value passed to input and output processors as the last argument

ac-compile->file

procedure

signature

config output-format sources dest-directory #:processor-options #:when #:dest-name ->

hashtable symbol list string _ ... -> string:path-destination

description

#:processor-options: any/alist

#:when takes a symbol:

new: update only if destination does not exist

newer: update if destination does not exist or any source file is newer

always: always compile, overwriting any existing destination file

#:dest-name sets the destination file name to use instead of an automatically generated one

ac-config

syntax

signature

((out-id suffix out-proc) (in-id matcher in-proc) ...) ...

ac-config-input

syntax

signature

id matcher processor

ac-config-input-p

procedure

signature

id matcher processor ->

description

symbol procedure/boolean procedure/false

create a config-input object.

if processor is false, a default processor that interprets source elements as

filesystem paths and reads them is used.

matcher

procedure: match a source element

#t: match the id as a filename extension separated with a dot

for source elements which are strings

else: never match

ac-config-output

syntax

signature

id suffix processor

ac-config-output-p

procedure

signature

id suffix processor ->

symbol string/procedure/boolean procedure -> vector

description

create a config-output object.

if processor is false, a default processor that just copies is used.

suffix

#t: use the id as a filename extension separated with a dot

else: no filename extension

ac-config-p

procedure

signature

config-source ->

list:((id config-output config-input ...) ...) -> hashtable

description

create an ac-config from a list with the following format

ac-destination

procedure

signature

path-directory format sources [name suffix] ->

string symbol string list -> string

description

create a string for an output path relative to "path-directory".

format:

* "{path-directory}/{format}/{name}"

* "{path-directory}/{format}/_{basename-without-suffix-first-of-sources}-{base32-hash-of-sources}"

ac-input-id

procedure

signature

record ->

ac-input-matcher

procedure

signature

record ->

ac-input-processor

procedure

signature

record ->

ac-input-record

variable

ac-output-id

procedure

signature

record ->

ac-output-processor

procedure

signature

record ->

ac-output-record

variable

ac-output-suffix

procedure

signature

record ->

ac-source-files-updated?

procedure

signature

dest sources ->

string (string ...) -> boolean

description

true if any source is newer than destination

sph-filesystem-asset-compiler-description

variable

tags: programming guile documentation library scheme sph-lib q1 filesystem asset-compiler highlight sph-filesystem-asset-compiler