]> Lady’s Gitweb - Shushe/commitdiff
Allow ⛩️📰 书社 to produce plain text
authorLady <redacted>
Mon, 1 Apr 2024 21:05:41 +0000 (17:05 -0400)
committerLady <redacted>
Tue, 2 Apr 2024 02:10:24 +0000 (22:10 -0400)
This requires adding _another_ build stage; the result of the
transformation step is output to `build/results`, which is then
processed again to create the `build/public` final result. In most
cases, this additional processing just produces a symlink. However,
when the root element is a special value, a derived file will be
produced.

The only special elements supported right now are `<书社:raw-text>`,
which outputs the raw text contents of the text nodes in the result
tree, and `<书社:base64-binary>`, which produces a binary file from the
base64 text contents determined using the same method.

GNUmakefile
README.markdown
lib/catalog2transform.xslt

index 75045a96fb4db52b580849004c38e641b0809550..98a08cb4d67c8cd5c9eb4d0df44bb1a784f687e1 100644 (file)
@@ -39,6 +39,7 @@ override define makefileinfo
 ║│ • touch                                                    │║
 ║│ • tr (requires support for `-d´)                           │║
 ║│ • uuencode (requires support for `-m´ and `-r´)            │║
+║│ • uudecode (requires support for `-m´ and `-r´)            │║
 ║│ • xargs (requires support for `-0´)                        │║
 ║│ • xmlcatalog (provided by libxml2)                         │║
 ║│ • xmllint (provided by libxml2)                            │║
@@ -112,6 +113,7 @@ STAT := stat
 TEST := test
 TOUCH := touch
 TR := tr
+UUDECODE := uudecode
 UUENCODE := uuencode
 XARGS := xargs
 XMLCATALOG := xmlcatalog
@@ -366,7 +368,7 @@ override sourcedestinationpair := $(foreach destination,$(destinations),$(call s
 override destination = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcedestinationpair))))
 
 # Pair each source file with its compiled location.
-override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/public/$(call destination,$(file)))
+override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/results/$(call destination,$(file)))
 
 # (callable) Get the location of the transformed X·M·L files for the given source files.
 override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcecompiledpair))))
@@ -374,6 +376,9 @@ override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,
 # (callable) Get the source files for the given compiled file.
 override uncompiled = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcecompiledpair))))
 
+# (callable) Get the location of the final built file for the given source files.
+override built = $(foreach file,$1,$(patsubst $(BUILDDIR)/results/%,$(BUILDDIR)/public/%,$(call compiled,$(file))))
+
 # (callable) Get the installed locations for the given source files.
 override installed = $(foreach file,$1,$(DESTDIR)/$(call destination,$(file)))
 endif
@@ -396,10 +401,16 @@ override wrapplaintext = $(TR) '\000\013\014' '\032\011\012' < $(call quote,$1)
 # This isn’t a perfect substitution (it makes some assumptions about the format of the underlying X·M·L), but it should be workable for most sensible, welformed files.
 override serializexml = $(SED) "$$($(PRINTF) '%b' '/<?xml[ \t]\\{1,\\}version=[\0042\0047]1.1/,$${ s/<?xml[^>]*?>/<!--<?xml version=\00421.1\0042?>-->/\n s/&\0043x0*[1-8BCEFbcef];/\0302\0221/g\n s/&\0043x0*1[0-9A-Fa-f];/\0302\0221/g\n s/&\00430*[1-8];/\0302\0221/g\n s/&\00430*1[124-9];/\0302\0221/g\n s/&\00430*2[0-9];/\0302\0221/g\n s/&\00430*3[01];/\0302\0221/g\n}')" < $(call quote,$1) | $(SED) "$$(PRINTF '%b' ':a\n/^\\n*$$/{ $$d\n N\n ba\n}')"
 
+# (callable) Test if the provided xpath expression matches the provided document.
+override xpath = $(XMLLINT) --xpath $(call quote,$1) $(call quote,$2) > /dev/null 2> /dev/null
+
+# (callable) Extract the value of the text nodes in the provided X·M·L document and print them to `stdout´.
+override extracttext = $(PRINTF) '%s' '<transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"><output method="text" encoding="UTF-8"/></transform>' | $(XSLTPROC) - $(call quote,$1)
+
 # ─ ¶ Phony Targets ───────────────────────────────────────────────────
 
 # Compile all files, or error if any are recursive.
-all : $(call compiled,$(recursivefiles) $(compilablefiles)) ;
+all : $(call built,$(recursivefiles) $(compilablefiles)) ;
 
 # Destroy buildfiles.
 clean :
@@ -539,16 +550,26 @@ $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalo
        @$(ECHO) "Generating main transform…"
        $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<)
 
-# Generate the output files using the dependencies as necessary.
-$(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
-       $(silent)$(call ensuredirectory,$(dir $@))
+# Compile the result files using the dependencies as necessary.
+$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@)))
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
+       $(silent)$(call ensuredirectory,$(dir $@))
        $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@))) --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<)
-$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@)
+$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/results/% : $$(call uncompiled,$$@)
        @$(PRINTF) '%s\n' $(call quote,Compiling </$*>…)
        $(silent)$(call ensuredirectory,$(dir $@))
        $(silent)$(CP) $(call quote,$<) $(call quote,$@)
 
+# Create the final files from the compiled results (or error in the case of recursive ones).
+$(call built,$(compilablefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/%
+       @$(PRINTF) '%s\n' $(call quote,Building </$*>…)
+       $(silent)$(call ensuredirectory,$(dir $@))
+       $(silent)if $(call xpath,/*[local-name()="raw-text" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) > $(call quote,$@); elif $(call xpath,/*[local-name()="base64-binary" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) | $(TR) -d '\t\n\f\r ' | $(UUDECODE) -m -r > $(call quote,$@); else $(LN) -s -f $(call quote,$(subst $(space),,$(foreach component,$(subst /, ,$*),../))results/$*) $(call quote,$@); fi
+$(call built,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/%
+       @$(PRINTF) '%s\n' $(call quote,Building </$*>…)
+       $(silent)$(call ensuredirectory,$(dir $@))
+       $(silent)$(LN) -s -f $(call quote,../results/$*) $(call quote,$@)
+
 # Install compiled files (or error in the case of recursive ones).
 $(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)) : $(DESTDIR)/% : $(BUILDDIR)/public/%
        @$(PRINTF) '%s\n' $(call quote,Installing </$*>…)
index 1973e02d0e7d3315c93e734b64e0f5956db433d4..7c663be305086a76c6d33937a012c7eb339e4ce9 100644 (file)
@@ -73,9 +73,13 @@ Compilation involves the following steps :⁠—
 5. ⛩️📰 书社 uses the dependency tree to establish prerequisites for
     each output file.
 
-6. ⛩️📰 书社 compiles each output file to `build/public`.
+6. ⛩️📰 书社 compiles each output file to `build/result`.
 
-7. ⛩️📰 书社 copies the output files to `public`.
+7. ⛩️📰 书社 symlinks most output files from `build/result` to
+     `build/public`, but it does some additional processing instead on
+     those which indicate a non‐X·M·L desired final output form.
+
+8. ⛩️📰 书社 copies the final resulting files to `public`.
 
 You can use `make list` to list each identified source file or include
   alongside its computed type and dependencies.
@@ -126,6 +130,7 @@ In every case, you may supply your own implementation by overriding the
 - `touch`
 - `tr` (requires support for `-d`)
 - `uuencode` (requires support for `-m` and `-r`)
+- `uudecode` (requires support for `-m` and `-r`)
 - `xargs` (requires support for `-0`)
 - `xmlcatalog` (provided by `libxml2`)
 - `xmllint` (provided by `libxml2`)
@@ -522,8 +527,8 @@ This mechanism can be used to allow transforms to insert content
 Output wrapping can be entirely disabled by adding a
   `@书社:disable-output-wrapping` attribute to the top‐level element in
   the result tree.
-This attribute will also prevent wrapping non‐H·T·M·L embeds with an
-  `<html:div>`.
+It will not be performed on outputs whose root elements are
+  `<书社:raw-text>` or `<书社:base64-binary>` (described below).
 
 ## Applying Attributes
 
@@ -546,6 +551,22 @@ Both elements ignore attributes in the `xml:` namespace, except for
 On H·T·M·L and S·V·G elements, `@lang` has the same behaviour as
   `@xml:lang`.
 
+## Other Kinds of Output
+
+There are a few special elements in the `书社:` namespace which, if
+  they appear as the toplevel element in a transformation result, cause
+  ⛩️📰 书社 to produce something other than an X·M·L file.
+They are :⁠—
+
+- **`<书社:raw-text>`:**
+  A plaintext (U·T·F‐8) file will be produced from the text nodes in
+    the transformation result.
+
+- **`<书社:base64-binary>`:**
+  The text nodes in the transformation result will, after removing all
+    Ascii whitespace, be treated as a Base·64 string, which is then
+    decoded.
+
 ## License
 
 This repository conforms to [REUSE][].
index 35f9c2bcd5a940a01f4fac5b6cacee6d326e3b9a..85d043c7c359651f0a855e751ac9cc20efd49267 100644 (file)
@@ -232,7 +232,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <xslt:variable name="result-nodes" select="exsl:node-set($书社:result)/node()[not(self::书社:apply-attributes-to-root)]|exsl:node-set($书社:result)/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
                                <xslt:variable name="root-with-attributes">
                                        <xslt:choose>
-                                               <xslt:when test="$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
+                                               <xslt:when test="$result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary']|$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
                                                        <xslt:call-template name="书社:apply-attributes">
                                                                <xslt:with-param name="and-version" select="true()"/>
                                                                <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
This page took 0.031835 seconds and 4 git commands to generate.