Skip to content

Commit 4fe2acb

Browse files
Assembly: add qrcodes for static representations of interactive programs
1 parent d8895e4 commit 4fe2acb

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

xsl/pretext-assembly.xsl

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

2326+
<xsl:template match="program[@interactive]" mode="assembly-id">
2327+
<xsl:value-of select="@assembly-id"/>
2328+
</xsl:template>
2329+
23262330
<xsl:template match="datafile" mode="assembly-id">
23272331
<xsl:value-of select="@assembly-id"/>
23282332
</xsl:template>
@@ -4089,6 +4093,12 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
40894093
<xsl:apply-templates select="@source" />
40904094
</xsl:template>
40914095

4096+
<!-- interactive programs need to point to page in book -->
4097+
<xsl:template match="program[@interactive = 'codelens' or @interactive = 'activecode']" mode="static-url">
4098+
<xsl:value-of select="$baseurl"/>
4099+
<xsl:apply-templates select="." mode="containing-filename" />
4100+
</xsl:template>
4101+
40924102
<!-- The contents of a datafile may be encoded as text in an XML -->
40934103
<!-- file within the generated/datafile directory. The filename -->
40944104
<!-- has this construction, even if we do not always consult it. -->
@@ -4140,4 +4150,50 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
41404150
<xsl:variable name="interactive-url-file" select="concat($generated-directory-source,'qrcode/', @assembly-id, '-url.xml')"/>
41414151
<xsl:value-of select="document($interactive-url-file, $original)/interactive-url/@url"/>
41424152
</xsl:template>
4153+
4154+
<xsl:template match="program[@interactive = 'codelens' or @interactive = 'activecode']" mode="representations">
4155+
<xsl:choose>
4156+
<xsl:when test="$exercise-style = 'static'">
4157+
<!-- first the static program -->
4158+
<xsl:copy>
4159+
<xsl:apply-templates select="node()|@*" mode="representations"/>
4160+
</xsl:copy>
4161+
<!-- then a qr assemblage if desired -->
4162+
<xsl:if test="$b-program-static-qrcodes">
4163+
<xsl:variable name="static-url">
4164+
<xsl:apply-templates select="." mode="get-interactive-url-from-file"/>
4165+
</xsl:variable>
4166+
<sidebyside margins="0%" widths="70% 25%" valign="middle" halign="center">
4167+
<paragraphs>
4168+
<p pi:indent="no">
4169+
<xsl:element name="pi:localize">
4170+
<xsl:attribute name="string-id">program-interactive-available</xsl:attribute>
4171+
</xsl:element>
4172+
</p>
4173+
<p pi:indent="no">
4174+
<!-- Kill the automatic footnote -->
4175+
<url href="{$static-url}" visual="">
4176+
<xsl:value-of select="$static-url"/>
4177+
</url>
4178+
</p>
4179+
</paragraphs>
4180+
<image>
4181+
<xsl:attribute name="pi:generated">
4182+
<xsl:text>qrcode/</xsl:text>
4183+
<xsl:apply-templates select="." mode="assembly-id"/>
4184+
<xsl:text>.png</xsl:text>
4185+
</xsl:attribute>
4186+
</image>
4187+
</sidebyside>
4188+
</xsl:if>
4189+
</xsl:when>
4190+
<xsl:when test="($exercise-style = 'dynamic')">
4191+
<!-- duplicate authored content for the non-static conversions -->
4192+
<xsl:copy>
4193+
<xsl:apply-templates select="node()|@*" mode="representations"/>
4194+
</xsl:copy>
4195+
</xsl:when>
4196+
</xsl:choose>
4197+
</xsl:template>
4198+
41434199
</xsl:stylesheet>

xsl/pretext-runestone-static.xsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
13501350
<xsl:copy-of select="program/node()"/>
13511351
</xsl:element>
13521352
</xsl:if>
1353+
<!-- bring up the program as part of the problem statement -->
1354+
<!-- copy via representations to get possible qrcode -->
1355+
<xsl:apply-templates select="program" mode="representations"/>
13531356
</statement>
13541357
<xsl:copy-of select="hint"/>
13551358
<xsl:copy-of select="answer"/>

0 commit comments

Comments
 (0)