Blame Scripts/Bash/Cli/Functions/Identity/identity_renderBase.sh

d27df4
#!/bin/bash
d27df4
#
8af4d8
# identity_renderBase.sh -- This function performs base-rendition
8af4d8
# action for all files.
d27df4
#
d27df4
# Copyright (C) 2009-2011 Alain Reguera Delgado
d27df4
# 
d27df4
# This program is free software; you can redistribute it and/or
d27df4
# modify it under the terms of the GNU General Public License as
d27df4
# published by the Free Software Foundation; either version 2 of the
d27df4
# License, or (at your option) any later version.
d27df4
# 
d27df4
# This program is distributed in the hope that it will be useful, but
d27df4
# WITHOUT ANY WARRANTY; without even the implied warranty of
d27df4
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d27df4
# General Public License for more details.
d27df4
#
d27df4
# You should have received a copy of the GNU General Public License
d27df4
# along with this program; if not, write to the Free Software
d27df4
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
d27df4
# USA.
d27df4
# 
d27df4
# ----------------------------------------------------------------------
d27df4
# $Id$
d27df4
# ----------------------------------------------------------------------
d27df4
ad3ecd
function identity_renderBase {
d27df4
8af4d8
    local -a FILES
b76187
    local FILE=''
b76187
    local OUTPUT=''
ddde89
    local TEMPLATE=''
b76187
    local PARENTDIR=''
8af4d8
    local EXTENSION=''
b76187
    local TRANSLATION=''
b76187
    local EXTERNALFILE=''
b76187
    local EXTERNALFILES=''
8af4d8
    local THIS_FILE_DIR=''
8af4d8
    local NEXT_FILE_DIR=''
8af4d8
    local COUNT=0
8af4d8
8af4d8
    # Define the extension pattern for template files. This is the
8af4d8
    # file extensions that centos-art will look for in order to build
8af4d8
    # the list of files to process. The list of files to process
8af4d8
    # contains the files that match this extension pattern.
8af4d8
    EXTENSION='\.(svgz|svg|docbook)'
d27df4
d27df4
    # Redefine parent directory for current workplace.
c979f9
    PARENTDIR=$(basename "${ACTIONVAL}")
d27df4
ddde89
    # Define base location of template files.
130f90
    identity_getDirTemplate
ddde89
    
8af4d8
    # Define list of files to process as array variable. This make
8af4d8
    # posible to realize verifications like: is the current base
8af4d8
    # directory equal to the next one in the list of files to process?
8af4d8
    # This is used to know when centos-art.sh is leaving a directory
8af4d8
    # structure and entering into another. This information is
8af4d8
    # required in order for centos-art.sh to know when to apply
8af4d8
    # last-rendition actions.
8af4d8
    for FILE in $(cli_getFilesList "${TEMPLATE}" "${FLAG_FILTER}.*${EXTENSION}");do
8af4d8
        FILES[$COUNT]=$FILE
8af4d8
        COUNT=$(($COUNT + 1))
8af4d8
    done
ddde89
ddde89
    # Set action preamble.
8af4d8
    cli_printActionPreamble "${FILES[@]}"
d27df4
c979f9
    # Reset common directory counter.
8af4d8
    COUNT=0
b76187
b76187
    # Start processing the base rendition list of FILES. Fun part
b76187
    # approching :-).
8af4d8
    while [[ $COUNT -lt ${#FILES[*]} ]];do
8af4d8
8af4d8
        # Define base file.
8af4d8
        FILE=${FILES[$COUNT]}
8af4d8
8af4d8
        # Define the base directory path for the current file being
8af4d8
        # process.
8af4d8
        THIS_FILE_DIR=$(dirname ${FILES[$COUNT]})
8af4d8
8af4d8
        # Define the base directory path for the next file that will
8af4d8
        # be process.
8af4d8
        if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then
8af4d8
            NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]})
8af4d8
        else
8af4d8
            NEXT_FILE_DIR=''
8af4d8
        fi
b76187
5a6a0f
        # Print separator line.
5a6a0f
        cli_printMessage '-' 'AsSeparatorLine'
5a6a0f
b76187
        # Define final location of translation file.
b76187
        TRANSLATION=$(dirname $FILE \
b76187
           | sed -r 's!/trunk/(Identity/)!/trunk/Locales/\1!')/$(cli_getCurrentLocale).po
b76187
b76187
        # Print final location of translation file.
b76187
        if [[ ! -f "$TRANSLATION" ]];then
b76187
            cli_printMessage "`gettext "None"`" "AsTranslationLine"
b76187
        else
b76187
            cli_printMessage "$TRANSLATION" 'AsTranslationLine'
b76187
        fi
b76187
b76187
        # Define final location of template file.
b76187
        TEMPLATE=${FILE}
b76187
b76187
        # Print final location of template file.
b76187
        if [[ ! -f "$TEMPLATE" ]];then
b76187
            cli_printMessage "`gettext "None"`" "AsDesignLine"
b76187
        else
b76187
            cli_printMessage "$TEMPLATE" 'AsDesignLine'
b76187
        fi
b76187
 
b76187
        # Define final location of output directory.
130f90
        identity_getDirOutput
b76187
b76187
        # Get relative path to file. The path string (stored in FILE)
b76187
        # has two parts: 1. the variable path and 2. the common path.
b76187
        # The variable path is before the common point in the path
b76187
        # string. The common path is after the common point in the
b76187
        # path string. The common point is the name of the parent
b76187
        # directory (stored in PARENTDIR).
b76187
        #
b76187
        # trunk/Locales/Identity/.../Firstboot/3/splash-small.svg
b76187
        # -------------------------^| the     |^------------^
b76187
        # variable path             | common  |    common path
b76187
        # -------------------------v| point   |    v------------v
b76187
        # trunk/Identity/Themes/M.../Firstboot/Img/3/splash-small.png
b76187
        #
b76187
        # What we do here is remove the varibale path, the common
b76187
        # point, and the file extension parts in the string holding
b76187
        # the path retrived from design models directory structure.
b76187
        # Then we use the common path as relative path to store the
b76187
        # the final image file.
b76187
        #
b76187
        # The file extension is removed from the common path because
b76187
        # it is set when we create the final image file. This
b76187
        # configuration let us use different extensions for the same
b76187
        # file name.
b76187
        #
b76187
        # When we render using renderImage function, the structure of
b76187
        # files under the output directory will be the same used after
b76187
        # the common point in the related design model directory
b76187
        # structure.
b76187
        FILE=$(echo ${FILE} \
b76187
            | sed -r "s!.*${PARENTDIR}/!!" \
8af4d8
            | sed -r "s/${EXTENSION}$//")
b76187
b76187
        # Define absolute path to final file (without extension).
b76187
        FILE=${OUTPUT}/$(basename "${FILE}")
b76187
b76187
        # Define instance name from design model.
b76187
        INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
b76187
8af4d8
        # Verify translation file existence and create template
8af4d8
        # instance accordingly.
b76187
        if [[ -f ${TRANSLATION} ]];then
b76187
b76187
            # Create translated instance from design model.
b76187
            /usr/bin/xml2po -p ${TRANSLATION} ${TEMPLATE} > ${INSTANCE}
b76187
b76187
            # Remove .xml2po.mo temporal file.
b76187
            if [[ -f ${PWD}/.xml2po.mo ]];then
b76187
                rm ${PWD}/.xml2po.mo
b76187
            fi
b76187
b76187
        else
b76187
            # Create non-translated instance form design model.
fd7f9d
            /bin/cp ${TEMPLATE} ${INSTANCE}    
b76187
        fi
b76187
8af4d8
        # Apply translation markers replacements to template instance.
b76187
        cli_replaceTMarkers ${INSTANCE}
b76187
8af4d8
        # Verify the extension of template instance and render content
8af4d8
        # accordingly.
8af4d8
        if [[ $INSTANCE =~ '\.(svgz|svg)$' ]];then
8af4d8
8af4d8
            # Perform base-rendition action for svg files.
8af4d8
            identity_renderSvg
8af4d8
8af4d8
            # Perform post-rendition action for svg files.
8af4d8
            identity_renderSvgPostActions
8af4d8
8af4d8
            # Perform last-rendition action for svg files.
8af4d8
            identity_renderSvgLastActions
8af4d8
            
fd7f9d
        elif [[ $INSTANCE =~ '\.docbook$' ]];then
8af4d8
8af4d8
            # Perform base-rendition action for docbook files.
fd7f9d
            identity_renderDocbook
8af4d8
8af4d8
            # Perform post-rendition action for docbook files.
8af4d8
            #identity_renderDocbookPostActions
b76187
8af4d8
            # Perform base-rendition action for docbook files.
8af4d8
            #identity_renderDocbookLastActions
8af4d8
8af4d8
        else
8af4d8
            cli_printMessage "`gettext "The template extension you try to render is not supported yet."`" 'AsErrorLine'
8af4d8
            cli_printMessage "$(caller)" 'AsToKnowMoreLine' 
8af4d8
        fi
b76187
b76187
        # Remove template instance. 
8af4d8
        if [[ -f $INSTANCE ]];then
b76187
            rm $INSTANCE
b76187
        fi
ddde89
8af4d8
        # Perform post-rendition actions for all files.
c979f9
        identity_renderPostActions
b76187
8af4d8
        # Perform last-rendition actions for all files.
8af4d8
        identity_renderLastActions
b76187
8af4d8
        # Increment file counter.
8af4d8
        COUNT=$(($COUNT + 1))
b76187
b76187
    done
c979f9
d27df4
}