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

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