Blame Scripts/Functions/Render/render_doBaseActions.sh

4c79b5
#!/bin/bash
4c79b5
#
9b8686
# render_doBaseActions.sh -- This function performs base-rendition
9b8686
# action 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
9e0b92
    # Verify default directory where design models are stored in.
2179d2
    cli_checkFiles "$(cli_getRepoTLDir)/Identity/Models/Themes/${FLAG_THEME_MODEL}" --directory
ae711e
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.
9d15a5
    for FILE in $(cli_getFilesList ${TEMPLATE} --pattern="${FLAG_FILTER}.*\.${EXTENSION}");do
5f7579
        FILES[((++${#FILES[*]}))]=$FILE
294842
    done
294842
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.
0ff158
        cli_printMessage '-' --as-separator-line
795d12
294842
        # Define final location of translation file.
294842
        TRANSLATION=$(dirname $FILE \
cff13a
           | sed -r 's!trunk/Identity/(.+)!trunk/Locales/Identity/\1!')/$(cli_getCurrentLocale)/messages.po
294842
294842
        # Print final location of translation file.
294842
        if [[ ! -f "$TRANSLATION" ]];then
0ff158
            cli_printMessage "`gettext "None"`" --as-translation-line
294842
        else
0ff158
            cli_printMessage "$TRANSLATION" --as-translation-line
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
0ff158
            cli_printMessage "`gettext "None"`" --as-design-line
294842
        else
0ff158
            cli_printMessage "$TEMPLATE" --as-design-line
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
        #
cff13a
        # Identity/Models/Themes/.../Firstboot/3/splash-small.svg
294842
        # -------------------------^| the     |^------------^
294842
        # variable path             | common  |    common path
294842
        # -------------------------v| point   |    v------------v
cff13a
        # Identity/Images/Themes/.../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
1b9973
        # Apply translation file to design model to produce the design
1b9973
        # model translated instance. 
1b9973
        render_doTranslation
294842
1b9973
        # Expand translation markers inside design model instance.
294842
        cli_replaceTMarkers ${INSTANCE}
294842
3a7b62
        # Define what action to perform based on the extension of
3a7b62
        # template instance.
294842
        if [[ $INSTANCE =~ '\.(svgz|svg)$' ]];then
294842
1b9973
            # Perform base-rendition actions for SVG files.
3a7b62
            render_svg
1b9973
1b9973
            # Perform post-rendition actions for SVG files.
1b9973
            render_svg_doPostActions
1b9973
1b9973
            # Perform last-rendition actions for SVG files.
1b9973
            render_svg_doLastActions
3a7b62
 
294842
        elif [[ $INSTANCE =~ '\.docbook$' ]];then
294842
1b9973
            # Perform base-rendition actions for Docbook files.
3a7b62
            render_docbook
294842
1b9973
            # Perform post-rendition actions for Docbook files.
1b9973
            #render_docbook_doPostActions
1b9973
1b9973
            # Perform last-rendition actions for Docbook files.
1b9973
            #render_docbook_doLastActions
1b9973
9e0b92
        elif [[ $INSTANCE =~ '\.xhtml$' ]];then
9e0b92
1b9973
            # Perform base-rendition actions for XHTML files.
3a7b62
            render_xhtml
9e0b92
1b9973
            # Perform post-rendition actions for XHTML files.
1b9973
            #render_xhtml_doPostActions
1b9973
1b9973
            # Perform last-rendition actions for XHTML files.
1b9973
            #render_xhtml_doLastActions
1b9973
294842
        else
0ff158
            cli_printMessage "`gettext "The template file you try to render is not supported yet."`" --as-error-line
294842
        fi
294842
294842
        # Remove template instance. 
294842
        if [[ -f $INSTANCE ]];then
294842
            rm $INSTANCE
294842
        fi
294842
294842
        # Increment file counter.
294842
        COUNT=$(($COUNT + 1))
f3bce7
07c2fe
    done
4c79b5
4c79b5
}