Blame Scripts/Functions/Render/render_doBaseActions.sh

4c79b5
#!/bin/bash
4c79b5
#
ab1d67
# render_do.sh -- This function performs base-rendition action
294842
# for all files.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
7b46a4
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
033f8d
function render_doBaseActions {
4c79b5
294842
    local -a FILES
107351
    local FILE=''
294842
    local OUTPUT=''
294842
    local TEMPLATE=''
294842
    local PARENTDIR=''
294842
    local EXTENSION=''
294842
    local TRANSLATION=''
294842
    local EXTERNALFILE=''
294842
    local EXTERNALFILES=''
294842
    local THIS_FILE_DIR=''
294842
    local NEXT_FILE_DIR=''
294842
    local COUNT=0
294842
4e3fd4
    # Initialize post-rendition list of actions,  the specification of
4e3fd4
    # what actions does centos-art execute immediatly after producing
4e3fd4
    # the base file in the same directory structure. 
4e3fd4
    local -a POSTACTIONS
4e3fd4
    
4e3fd4
    # Initialize last-rendition list of actions, the specification of
4e3fd4
    # what actions does centos-art execute once all base files in the
4e3fd4
    # same directory structure have been produced, this is just
4e3fd4
    # immediatly before passing to produce the next directory
4e3fd4
    # structure.
4e3fd4
    local -a LASTACTIONS
05d9ae
4e3fd4
    # Check theme model directory structure.
05d9ae
    cli_checkFiles "$(cli_getRepoTLDir)/Identity/Themes/Models/${FLAG_THEME_MODEL}" 'd'
ae711e
4e3fd4
    # Verify post-rendition actions passed from command-line and add
4e3fd4
    # them, if any, to post-rendition list of actions.
4e3fd4
    if [[ $FLAG_GROUPED_BY != '' ]];then
ddd73c
        POSTACTIONS[((++${#POSTACTIONS[*]}))]="groupSimilarFiles:${FLAG_GROUPED_BY}"
4e3fd4
    fi
4e3fd4
294842
    # Define the extension pattern for template files. This is the
294842
    # file extensions that centos-art will look for in order to build
294842
    # the list of files to process. The list of files to process
294842
    # contains the files that match this extension pattern.
294842
    EXTENSION='\.(svgz|svg|docbook)'
294842
294842
    # Redefine parent directory for current workplace.
294842
    PARENTDIR=$(basename "${ACTIONVAL}")
294842
294842
    # Define base location of template files.
ab1d67
    render_getDirTemplate
294842
    
294842
    # Define list of files to process as array variable. This make
294842
    # posible to realize verifications like: is the current base
294842
    # directory equal to the next one in the list of files to process?
294842
    # This is used to know when centos-art.sh is leaving a directory
294842
    # structure and entering into another. This information is
294842
    # required in order for centos-art.sh to know when to apply
294842
    # last-rendition actions.
294842
    for FILE in $(cli_getFilesList "${TEMPLATE}" "${FLAG_FILTER}.*${EXTENSION}");do
5f7579
        FILES[((++${#FILES[*]}))]=$FILE
294842
    done
294842
294842
    # Set action preamble.
294842
    cli_printActionPreamble "${FILES[*]}" '' ''
107351
294842
    # Start processing the base rendition list of FILES. Fun part
294842
    # approching :-).
294842
    while [[ $COUNT -lt ${#FILES[*]} ]];do
d27df4
294842
        # Define base file.
294842
        FILE=${FILES[$COUNT]}
107351
294842
        # Define the base directory path for the current file being
294842
        # process.
294842
        THIS_FILE_DIR=$(dirname ${FILES[$COUNT]})
107351
294842
        # Define the base directory path for the next file that will
294842
        # be process.
294842
        if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then
294842
            NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]})
294842
        else
294842
            NEXT_FILE_DIR=''
294842
        fi
d27df4
795d12
        # Print separator line.
795d12
        cli_printMessage '-' 'AsSeparatorLine'
795d12
294842
        # Define final location of translation file.
294842
        TRANSLATION=$(dirname $FILE \
294842
           | sed -r 's!/trunk/(Identity/)!/trunk/Locales/\1!')/$(cli_getCurrentLocale).po
294842
294842
        # Print final location of translation file.
294842
        if [[ ! -f "$TRANSLATION" ]];then
294842
            cli_printMessage "`gettext "None"`" "AsTranslationLine"
294842
        else
294842
            cli_printMessage "$TRANSLATION" 'AsTranslationLine'
294842
        fi
294842
294842
        # Define final location of template file.
294842
        TEMPLATE=${FILE}
294842
294842
        # Print final location of template file.
294842
        if [[ ! -f "$TEMPLATE" ]];then
294842
            cli_printMessage "`gettext "None"`" "AsDesignLine"
294842
        else
294842
            cli_printMessage "$TEMPLATE" 'AsDesignLine'
294842
        fi
294842
 
294842
        # Define final location of output directory.
ab1d67
        render_getDirOutput
294842
294842
        # Get relative path to file. The path string (stored in FILE)
294842
        # has two parts: 1. the variable path and 2. the common path.
294842
        # The variable path is before the common point in the path
294842
        # string. The common path is after the common point in the
294842
        # path string. The common point is the name of the parent
294842
        # directory (stored in PARENTDIR).
294842
        #
294842
        # trunk/Locales/Identity/.../Firstboot/3/splash-small.svg
294842
        # -------------------------^| the     |^------------^
294842
        # variable path             | common  |    common path
294842
        # -------------------------v| point   |    v------------v
294842
        # trunk/Identity/Themes/M.../Firstboot/Img/3/splash-small.png
294842
        #
294842
        # What we do here is remove the varibale path, the common
294842
        # point, and the file extension parts in the string holding
294842
        # the path retrived from design models directory structure.
294842
        # Then we use the common path as relative path to store the
294842
        # the final image file.
294842
        #
294842
        # The file extension is removed from the common path because
294842
        # it is set when we create the final image file. This
294842
        # configuration let us use different extensions for the same
294842
        # file name.
294842
        #
294842
        # When we render using renderImage function, the structure of
294842
        # files under the output directory will be the same used after
294842
        # the common point in the related design model directory
294842
        # structure.
294842
        FILE=$(echo ${FILE} \
294842
            | sed -r "s!.*${PARENTDIR}/!!" \
294842
            | sed -r "s/${EXTENSION}$//")
294842
294842
        # Define absolute path to final file (without extension).
294842
        FILE=${OUTPUT}/$(basename "${FILE}")
294842
294842
        # Define instance name from design model.
294842
        INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
294842
294842
        # Verify translation file existence and create template
294842
        # instance accordingly.
294842
        if [[ -f ${TRANSLATION} ]];then
294842
294842
            # Create translated instance from design model.
294842
            /usr/bin/xml2po -p ${TRANSLATION} ${TEMPLATE} > ${INSTANCE}
294842
294842
            # Remove .xml2po.mo temporal file.
294842
            if [[ -f ${PWD}/.xml2po.mo ]];then
294842
                rm ${PWD}/.xml2po.mo
294842
            fi
294842
294842
        else
294842
            # Create non-translated instance form design model.
294842
            /bin/cp ${TEMPLATE} ${INSTANCE}    
294842
        fi
294842
294842
        # Apply translation markers replacements to template instance.
294842
        cli_replaceTMarkers ${INSTANCE}
294842
294842
        # Verify the extension of template instance and render content
294842
        # accordingly.
294842
        if [[ $INSTANCE =~ '\.(svgz|svg)$' ]];then
294842
294842
            # Perform base-rendition action for svg files.
ab1d67
            render_doSvg
294842
294842
            # Perform post-rendition action for svg files.
ab1d67
            render_doSvgPostActions
294842
294842
            # Perform last-rendition action for svg files.
ab1d67
            render_doSvgLastActions
294842
            
294842
        elif [[ $INSTANCE =~ '\.docbook$' ]];then
294842
294842
            # Perform base-rendition action for docbook files.
ab1d67
            render_doDocbook
294842
294842
            # Perform post-rendition action for docbook files.
ab1d67
            #render_doDocbookPostActions
294842
294842
            # Perform base-rendition action for docbook files.
ab1d67
            #render_doDocbookLastActions
294842
294842
        else
ae711e
            cli_printMessage "`gettext "The template file you try to render is not supported yet."`" 'AsErrorLine'
294842
            cli_printMessage "$(caller)" 'AsToKnowMoreLine' 
294842
        fi
294842
294842
        # Remove template instance. 
294842
        if [[ -f $INSTANCE ]];then
294842
            rm $INSTANCE
294842
        fi
294842
294842
        # Perform post-rendition actions for all files.
ab1d67
        render_doPostActions
294842
294842
        # Perform last-rendition actions for all files.
ab1d67
        render_doLastActions
294842
294842
        # Increment file counter.
294842
        COUNT=$(($COUNT + 1))
f3bce7
07c2fe
    done
4c79b5
4c79b5
}