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
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
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
9e0b92
    # Verify default directory where design models are stored in.
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.
12ba9c
    EXTENSION='(svgz|svg|xhtml|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
    
9e0b92
    # Define list of files to process. Use an array variable to store
9e0b92
    # the list of files to process. This make posible to realize
9e0b92
    # verifications like: is the current base directory equal to the
9e0b92
    # next one in the list of files to process?  This is used to know
9e0b92
    # when centos-art.sh is leaving a directory structure and entering
9e0b92
    # into another. This information is required in order for
9e0b92
    # centos-art.sh to know when to apply last-rendition actions.
9e0b92
    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 \
f3e5c0
           | sed -r 's!trunk/Identity/(Models|Themes/Models)!trunk/Locales/Identity/\1!')/$(cli_getCurrentLocale)/messages.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
        #
9e0b92
        # Identity/Themes/Models/.../Firstboot/3/splash-small.svg
294842
        # -------------------------^| the     |^------------^
294842
        # variable path             | common  |    common path
294842
        # -------------------------v| point   |    v------------v
9e0b92
        # Identity/Themes/Motifs/.../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
        #
9e0b92
        # When we render using base-rendition action, 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}/!!" \
9e0b92
            | 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.
bad45e
            /usr/bin/xml2po -a -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
9e0b92
            # Perform base-rendition action for Docbook files.
ab1d67
            render_doDocbook
294842
9e0b92
            # Perform post-rendition action for Docbook files.
ab1d67
            #render_doDocbookPostActions
294842
9e0b92
            # Perform base-rendition action for Docbook files.
ab1d67
            #render_doDocbookLastActions
294842
9e0b92
        elif [[ $INSTANCE =~ '\.xhtml$' ]];then
9e0b92
9e0b92
            # Perform base-rendition action for XHTML files.
9e0b92
            render_doXhtml
9e0b92
9e0b92
            # Perform post-rendition action for Docbook files.
9e0b92
            #render_doXhtmlPostActions
9e0b92
9e0b92
            # Perform base-rendition action for Xhtml files.
9e0b92
            #render_doXhtmlLastActions
9e0b92
294842
        else
ae711e
            cli_printMessage "`gettext "The template file you try to render is not supported yet."`" 'AsErrorLine'
eee226
            cli_printMessage "${FUNCDIRNAM}" '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
}