Blame Scripts/Functions/Render/Docbook/docbook_prepareStyles.sh

be62ec
#!/bin/bash
be62ec
#
c26ad2
# docbook_prepareStyles.sh -- This function prepares styles' final
c26ad2
# instances used in transformations based on XSL or DSL templates.
c26ad2
# There are translation markers inside the XSL and DSL templates that
c26ad2
# need to be expand before they be used for transformations. This
c26ad2
# function creates temporal instances of XSL and DSL templates with
c26ad2
# translation markers expanded inside so as for transformation
c26ad2
# commands (e.g., `xmltproc' or `openjade' through `docbook2pdf') to
c26ad2
# use as style defintion.
be62ec
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
be62ec
#
be62ec
# This program is free software; you can redistribute it and/or modify
be62ec
# it under the terms of the GNU General Public License as published by
2fe9b7
# the Free Software Foundation; either version 2 of the License, or (at
2fe9b7
# your option) any later version.
be62ec
#
be62ec
# This program is distributed in the hope that it will be useful, but
be62ec
# WITHOUT ANY WARRANTY; without even the implied warranty of
be62ec
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
be62ec
# General Public License for more details.
be62ec
#
be62ec
# You should have received a copy of the GNU General Public License
be62ec
# along with this program; if not, write to the Free Software
be62ec
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
be62ec
#
be62ec
# ----------------------------------------------------------------------
5ad52a
# $Id$
be62ec
# ----------------------------------------------------------------------
be62ec
2fa604
function docbook_prepareStyles {
be62ec
2fa604
    local STYLE_TEMPLATE_FILE=''
2fa604
    local STYLE_TEMPLATE_FILES=$@
2fa604
    local STYLE_INSTANCE_COMMON=''
be62ec
    local COUNT=0
be62ec
2fa604
    for STYLE_TEMPLATE_FILE in $STYLE_TEMPLATE_FILES;do
be62ec
2fa604
        STYLE_TEMPLATE[((++${#STYLE_TEMPLATE[*]}))]="${STYLE_TEMPLATE_FILE}"
2fa604
        STYLE_INSTANCE[((++${#STYLE_INSTANCE[*]}))]="$(cli_getTemporalFile ${STYLE_TEMPLATE_FILE})"
be62ec
be62ec
        # Keep track of array's real index value. Remember, it starts
be62ec
        # at zero but counting starts at 1 instead. So, substracting 1
be62ec
        # from counting we have the real index value we need to work
be62ec
        # with the information stored in the array.
2fa604
        COUNT=$(( ${#STYLE_INSTANCE[*]} - 1 ))
be62ec
c26ad2
        # Create style instance from style template.
2fa604
        cp ${STYLE_TEMPLATE[$COUNT]} ${STYLE_INSTANCE[$COUNT]}
be62ec
c26ad2
        # Define both final an common style instances based on style
c26ad2
        # templates.
2fa604
        if [[ $STYLE_TEMPLATE_FILE =~ 'docbook2fo\.xsl$' ]];then
2fa604
            STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[$COUNT]}
2fa604
        elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2pdf\.dsl$' ]];then
2fa604
            STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[${COUNT}]}
2fa604
        elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2xhtml-(chunks|single)\.xsl$' ]];then
2fa604
            STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[${COUNT}]}
2fa604
        elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2xhtml-common\.xsl$' ]];then
2fa604
            STYLE_INSTANCE_COMMON=${STYLE_INSTANCE[${COUNT}]}
be62ec
        fi
be62ec
be62ec
    done
be62ec
c26ad2
    # Verify style final instance. This is the file used by
c26ad2
    # transformation command (`xsltproc' or `openjade') to produce the
c26ad2
    # specified output. We cannot continue without it.
c26ad2
    cli_checkFiles $STYLE_INSTANCE_FINAL
be62ec
c26ad2
    # Expand common translation markers in the common style instance,
c26ad2
    # if it exists.
2fa604
    if [[ -f $STYLE_INSTANCE_COMMON ]];then
54cb18
        cli_expandTMarkers $STYLE_INSTANCE_COMMON
f8649c
    fi
f8649c
c26ad2
    # Expand specific translation markers in final style instance.
2fa604
    sed -r -i "s!=STYLE_XHTML_COMMON=!${STYLE_INSTANCE_COMMON}!" ${STYLE_INSTANCE_FINAL}
f8649c
be62ec
}