Skip to content

Commit 1443cf4

Browse files
Assembly: add qrcodes for static representations of interactive programs
1 parent 5298d1a commit 1443cf4

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

xsl/pretext-assembly.xsl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
19111911
<xsl:value-of select="@assembly-id"/>
19121912
</xsl:template>
19131913

1914+
<xsl:template match="program[@interactive]" mode="assembly-id">
1915+
<xsl:value-of select="@assembly-id"/>
1916+
</xsl:template>
1917+
19141918
<xsl:template match="datafile" mode="assembly-id">
19151919
<xsl:value-of select="@assembly-id"/>
19161920
</xsl:template>
@@ -3535,6 +3539,12 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
35353539
<xsl:apply-templates select="@source" />
35363540
</xsl:template>
35373541

3542+
<!-- interactive programs need to point to page in book -->
3543+
<xsl:template match="program[@interactive = 'codelens' or @interactive = 'activecode']" mode="static-url">
3544+
<xsl:value-of select="$baseurl"/>
3545+
<xsl:apply-templates select="." mode="containing-filename" />
3546+
</xsl:template>
3547+
35383548
<!-- The contents of a datafile may be encoded as text in an XML -->
35393549
<!-- file within the generated/datafile directory. The filename -->
35403550
<!-- has this construction, even if we do not always consult it. -->
@@ -3586,4 +3596,50 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
35863596
<xsl:variable name="interactive-url-file" select="concat($generated-directory-source,'qrcode/', @assembly-id, '-url.xml')"/>
35873597
<xsl:value-of select="document($interactive-url-file, $original)/interactive-url/@url"/>
35883598
</xsl:template>
3599+
3600+
<xsl:template match="program[@interactive = 'codelens' or @interactive = 'activecode']" mode="representations">
3601+
<xsl:choose>
3602+
<xsl:when test="$exercise-style = 'static'">
3603+
<!-- first the static program -->
3604+
<xsl:copy>
3605+
<xsl:apply-templates select="node()|@*" mode="representations"/>
3606+
</xsl:copy>
3607+
<!-- then a qr assemblage if desired -->
3608+
<xsl:if test="$b-program-static-qrcodes">
3609+
<xsl:variable name="static-url">
3610+
<xsl:apply-templates select="." mode="get-interactive-url-from-file"/>
3611+
</xsl:variable>
3612+
<assemblage>
3613+
<title>
3614+
<xsl:element name="pi:localize">
3615+
<xsl:attribute name="string-id">program-interactive-available</xsl:attribute>
3616+
</xsl:element>
3617+
</title>
3618+
<sidebyside margins="0%" widths="70% 25%" valign="top" halign="center">
3619+
<p>
3620+
<!-- Kill the automatic footnote -->
3621+
<url href="{$static-url}" visual="">
3622+
<xsl:value-of select="$static-url"/>
3623+
</url>
3624+
</p>
3625+
<image>
3626+
<xsl:attribute name="pi:generated">
3627+
<xsl:text>qrcode/</xsl:text>
3628+
<xsl:apply-templates select="." mode="assembly-id"/>
3629+
<xsl:text>.png</xsl:text>
3630+
</xsl:attribute>
3631+
</image>
3632+
</sidebyside>
3633+
</assemblage>
3634+
</xsl:if>
3635+
</xsl:when>
3636+
<xsl:when test="($exercise-style = 'dynamic')">
3637+
<!-- duplicate authored content for the non-static conversions -->
3638+
<xsl:copy>
3639+
<xsl:apply-templates select="node()|@*" mode="representations"/>
3640+
</xsl:copy>
3641+
</xsl:when>
3642+
</xsl:choose>
3643+
</xsl:template>
3644+
35893645
</xsl:stylesheet>

xsl/pretext-runestone-static.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,8 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
13391339
<!-- duplicate the authored prompt/statement -->
13401340
<xsl:copy-of select="statement/node()"/>
13411341
<!-- bring up the program as part of the problem statement -->
1342-
<xsl:copy-of select="program"/>
1342+
<!-- copy via representations to get possible qrcode -->
1343+
<xsl:apply-templates select="program" mode="representations"/>
13431344
</statement>
13441345
<xsl:copy-of select="hint"/>
13451346
<xsl:copy-of select="answer"/>

0 commit comments

Comments
 (0)