Skip to content

Commit c366508

Browse files
oscarlevinrbeezer
authored andcommitted
Assembly: short-circuit passes once @assembly-id present (PR #2868)
1 parent 4276a7d commit c366508

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

pretext/lib/pretext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5011,6 +5011,8 @@ def assembly(xml, pub_file, stringparams, out_file, dest_dir, method):
50115011
stringparams["debug.assembly.exercise"] = method
50125012
elif method == "version":
50135013
stringparams["assembly.version-only"] = "yes"
5014+
elif method == "assembly-id":
5015+
stringparams["assembly.assembly-id-only"] = "yes"
50145016
else:
50155017
log.error("assembly method {} not recognized".format(method))
50165018
# "extra_xsl" would be silly in this context (?)
@@ -5044,6 +5046,8 @@ def assembly_internal(xml, pub_file, stringparams, method):
50445046
stringparams["debug.assembly.exercise"] = method
50455047
elif method == "version":
50465048
stringparams["assembly.version-only"] = "yes"
5049+
elif method == "assembly-id":
5050+
stringparams["assembly.assembly-id-only"] = "yes"
50475051
else:
50485052
log.error("assembly method {} not recognized".format(method))
50495053
# use the right xsl template

xsl/pretext-assembly.xsl

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
149149
<xsl:variable name="exercise-style" select="'static'"/>
150150

151151
<!-- Short-Circuit -->
152-
<!-- Sometimes we only want to convert to a "version" (valid PreTeXt) via -->
153-
<!-- the resolution of version support and customizations. Examples are -->
154-
<!-- determining publisher variables (for generating something like LaTeX -->
155-
<!-- images, when we do not process the whole source) or performiong -->
156-
<!-- validation. We control this with an internal variable, which is not -->
157-
<!-- documented as an author or publisher feature. When we select only -->
158-
<!-- the production of the "version" tree, the choice of "exercise-style" -->
159-
<!-- is irrelevant. -->
152+
<!-- Sometimes we only want to stop at an intermediate tree. For example, -->
153+
<!-- we may convert only to a "version" (valid PreTeXt) via resolution of -->
154+
<!-- version support and customizations, or stop at the tree that has -->
155+
<!-- @assembly-id attributes but has not yet loaded exercise components. -->
156+
<!-- We control this with internal variables, not documented as author or -->
157+
<!-- publisher features. When we stop this early, "exercise-style" is -->
158+
<!-- irrelevant. -->
160159

161160
<!-- default is empty, so we ccan detect non-use -->
162161
<xsl:param name="assembly.version-only" select="''"/>
162+
<xsl:param name="assembly.assembly-id-only" select="''"/>
163163

164164
<!-- Set to 'yes' to enable diagnostic checks, such as -->
165165
<!-- verifying coherence of @assembly-id and @unique-id. -->
@@ -186,6 +186,25 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
186186
</xsl:variable>
187187
<xsl:variable name="b-version-only" select="$version-only = 'yes'"/>
188188

189+
<!-- convert to a boolean, with error-checking -->
190+
<xsl:variable name="assembly-id-only">
191+
<xsl:choose>
192+
<xsl:when test="$assembly.assembly-id-only = ''">
193+
<xsl:text>no</xsl:text>
194+
</xsl:when>
195+
<xsl:when test="$assembly.assembly-id-only = 'yes'">
196+
<xsl:text>yes</xsl:text>
197+
</xsl:when>
198+
<xsl:when test="$assembly.assembly-id-only = 'no'">
199+
<xsl:text>no</xsl:text>
200+
</xsl:when>
201+
<xsl:otherwise>
202+
<xsl:message>PTX:BUG: the internal parameter assembly.assembly-id-only received an unrecognized value of "<xsl:value-of select="$assembly.assembly-id-only"/>" (possible values are "yes" and "no")</xsl:message>
203+
</xsl:otherwise>
204+
</xsl:choose>
205+
</xsl:variable>
206+
<xsl:variable name="b-assembly-id-only" select="$assembly-id-only = 'yes'"/>
207+
189208
<!-- ################################################ -->
190209
<!-- Controlling Two-Pass Extraction and Substitution -->
191210
<!-- ################################################ -->
@@ -506,7 +525,13 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
506525
<xsl:variable name="assembly-label" select="exsl:node-set($assembly-label-rtf)"/>
507526

508527
<xsl:variable name="representations-rtf">
509-
<xsl:apply-templates select="$assembly-label" mode="representations"/>
528+
<xsl:choose>
529+
<!-- short-circuit to stop after adding @assembly-id -->
530+
<xsl:when test="$b-assembly-id-only"/>
531+
<xsl:otherwise>
532+
<xsl:apply-templates select="$assembly-label" mode="representations"/>
533+
</xsl:otherwise>
534+
</xsl:choose>
510535
</xsl:variable>
511536
<xsl:variable name="representations" select="exsl:node-set($representations-rtf)"/>
512537

xsl/utilities/pretext-enhanced-source.xsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
9494
<xsl:when test="$b-version-only">
9595
<xsl:apply-templates select="$version" mode="showme"/>
9696
</xsl:when>
97+
<xsl:when test="$b-assembly-id-only">
98+
<xsl:apply-templates select="$assembly-label" mode="showme"/>
99+
</xsl:when>
97100
<xsl:otherwise>
98101
<xsl:apply-templates select="$root" mode="showme"/>
99102
</xsl:otherwise>

0 commit comments

Comments
 (0)