Blame Automation/centos-art.sh-mods/Render/Docbook/docbook_setStyles.sh

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