Bug 1092351 - RFE: code switchery for brand
Summary: RFE: code switchery for brand
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Publican
Classification: Community
Component: publican
Version: future
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: 4.2
Assignee: Jeff Fearn 🐞
QA Contact: Deepti Navale
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-04-29 07:05 UTC by Joshua Wulf
Modified: 2014-10-19 23:02 UTC (History)
4 users (show)

Fixed In Version: 4.2.0
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-09-01 03:40:24 UTC


Attachments (Terms of Use)

Description Joshua Wulf 2014-04-29 07:05:54 UTC
Here's the brand where it is working: https://github.com/jwulf/publican-redhat-video/


A breakdown of how it works:

Javascript files are found here: https://github.com/jwulf/publican-redhat-video/tree/master/en-US/scripts

Inject the javascript into the book html through xsl (there's some schema.org metadata thrown in there as a bonus)
[from https://github.com/jwulf/publican-redhat-video/blob/master/xsl/html-single.xsl]:

<!-- set the onload of the page -->
<!-- http://www.sagehill.net/docbookxsl/BodyAtts.html -->
<xsl:template name="body.attributes">
    <xsl:attribute name="onLoad">skynetBookLoad()</xsl:attribute>
    <xsl:attribute name="itemscope"/>
    <xsl:attribute name="itemtype">http://schema.org/TechArticle</xsl:attribute>
</xsl:template>

<xsl:template name="user.header.content">
    <meta itemprop="aboutProduct">
        <xsl:attribute name="content">
        <xsl:value-of select="concat(//productname[1], ' ', //productnumber[1])"/>
        </xsl:attribute>
    </meta>
</xsl:template>

<!-- inject our javascript into the footer -->
<!-- http://www.sagehill.net/docbookxsl/InsertExtHtml.html -->
<!-- Inject a div.skynetBookID with Product_Name/Book_Name
  This is used for cookies for the book -->
<xsl:template name="user.footer.content">
    <div class="skynetBookID"><xsl:value-of select="//productname[1]"/>/<xsl:value-of select="//title[1]"/>/<xsl:value-of select="//productnumber[1]"/></div>
    <xsl:choose>
        <xsl:when test="$embedtoc != 0">
        <!-- web path -->

        <script type="text/javascript">
            <xsl:attribute name="src">
                <xsl:value-of select="concat($tocpath, '/../', $brand, '/', $langpath, '/scripts/jquery-1.4.2.min.js')"/>
            </xsl:attribute>
        </script>

        <script type="text/javascript">
            <xsl:attribute name="src">
                <xsl:value-of select="concat($tocpath, '/../', $brand, '/', $langpath, '/scripts/utils.js')"/>
            </xsl:attribute>
        </script>

        <script type="text/javascript">
            <xsl:attribute name="src">
                <xsl:value-of select="concat($tocpath, '/../', $brand, '/', $langpath, '/scripts/code-lang-switcher.js')"/>
            </xsl:attribute>
        </script>

        <script type="text/javascript">
            <xsl:attribute name="src">
                <xsl:value-of select="concat($tocpath, '/../', $brand, '/', $langpath, '/scripts/changelogs.js')"/>
            </xsl:attribute>
        </script>
      
        <script type="text/javascript">
            <xsl:attribute name="src">
                <xsl:value-of select="concat($tocpath, '/../', $brand, '/', $langpath, '/scripts/skynet-book.js')"/>
            </xsl:attribute>
        </script>
    </xsl:when>
    <xsl:otherwise>
        <!-- desktop path -->
        <script type="text/javascript">
            <xsl:attribute name="src">Common_Content/scripts/jquery-1.4.2.min.js</xsl:attribute>
        </script>
        <script type="text/javascript">
            <xsl:attribute name="src">Common_Content/scripts/utils.js</xsl:attribute>
        </script>
        <script type="text/javascript">
            <xsl:attribute name="src">Common_Content/scripts/code-lang-switcher.js</xsl:attribute>
        </script>
        <script type="text/javascript">
            <xsl:attribute name="src">Common_Content/scripts/changelogs.js</xsl:attribute>
        </script>
        <script type="text/javascript">
            <xsl:attribute name="src">Common_Content/scripts/skynet-book.js</xsl:attribute>
        </script>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Comment 1 Jeff Fearn 🐞 2014-05-23 00:14:46 UTC
Do we have an example of a book with multi language examples like this?

Comment 3 Jeff Fearn 🐞 2014-05-23 06:03:18 UTC
I'd like to go for a simpler structure in the XML.

e.g.

<informalexample role="switchery">
<programlisting langauge="Perl">
... some perl code
</programlisting>
<programlisting langauge="C++">
... some C++ code
</programlisting>
<programlisting langauge="Java">
... some Java code
</programlisting>
</informalexample>

Comment 4 Jeff Fearn 🐞 2014-05-26 04:19:25 UTC
Added code language switch, including cookie to set default language.

Example at: http://jfearn.fedorapeople.org/HTML5_Test/html/pref-Publican-Users_Guide-Introduction.html

To ssh://git.fedorahosted.org/git/publican.git
   1e53c5e..6652bcf  devel -> devel

Comment 5 Don Domingo 2014-08-26 00:31:49 UTC
Tested https://bugzilla.redhat.com/show_bug.cgi?id=1092351#c3 sample on common-db5 brand. The generated example shows a tabbed code box where users can switch between the languages:

http://file.bne.redhat.com/~ddomingo/tests/bz1092351/

Setting as VERIFIED.

Comment 6 Jeff Fearn 🐞 2014-09-01 03:40:24 UTC
A fix for this shipped in Publican 4.2.0.


Note You need to log in before you can comment on or make changes to this bug.