Bug 1092351 - RFE: code switchery for brand
Summary: RFE: code switchery for brand
Alias: None
Product: Publican
Classification: Community
Component: publican
Version: future
Hardware: Unspecified
OS: Unspecified
Target Milestone: 4.2
Assignee: Jeff Fearn 🐞
QA Contact: Deepti Navale
Depends On:
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:
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 name="user.header.content">
    <meta itemprop="aboutProduct">
        <xsl:attribute name="content">
        <xsl:value-of select="concat(//productname[1], ' ', //productnumber[1])"/>

<!-- 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: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')"/>

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

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

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

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.


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

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:


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.