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
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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 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
    # Redefine parent directory for current workplace.
294842
    PARENTDIR=$(basename "${ACTIONVAL}")
294842
294842
    # Define base location of template files.
ab1d67
    render_getDirTemplate
294842
    
4d1322
    # Define the list of files to process. Use an array variable to
4d1322
    # store the list of files to process. This make posible to realize
9e0b92
    # verifications like: is the current base directory equal to the
74ff53
    # next one in the list of files to process?  Questions like this
74ff53
    # is let us to know when centos-art.sh is leaving a directory
74ff53
    # structure and entering another. This information is required in
74ff53
    # order for centos-art.sh to know when to apply last-rendition
74ff53
    # actions.
4d1322
    #
74ff53
    # Another issue is that some directories might be named as if they
74ff53
    # were files (e.g., using a renderable extension like .docbook).
74ff53
    # In these situations we need to avoid such directories from being
74ff53
    # interpreted as a renderable file. For this, pass the
74ff53
    # `--type="f"' option when building the list of files to process
74ff53
    # in order to retrive regular files only.
4d1322
    #
74ff53
    # Another issue to consider here, is that in some cases both
74ff53
    # templates and outputs might be in the same location. In these
74ff53
    # cases localized content are stored in the same location where
4d1322
    # template files are retrived from and we need to avoid using
4d1322
    # localized content from being interpreted as design models. In
4d1322
    # that sake, supress language-specific files from the list of
4d1322
    # files to process.
03f2b5
    #
03f2b5
    # Another issue to consider here, is the way of filtering. We
03f2b5
    # cannot expand the pattern specified by FLAG_FILTER with a `.*'
69a31c
    # here (e.g., "${FLAG_FILTER}.*\.${RENDER_EXTENSION}") because
69a31c
    # that would suppress any possibility from the user to specifiy
69a31c
    # just one file name in locations where more than one file with
69a31c
    # the same name as prefix exists (e.g., `repository.docbook',
03f2b5
    # `repository-preamble.docbook' and `repository-parts.docbook').
febca5
    # Instead, pass filtering control to the user whom can use regular
03f2b5
    # expression markup in the `--filter' option to decide whether to
febca5
    # match `repository.docbook' only (e.g., through
febca5
    # `--filter="repository"') or `repository-preamble.docbook' and
febca5
    # `repository-parts.docbook' but not `repository.docbook' (e.g.,
febca5
    # through `--filter="repository-.*"').
74ff53
    for FILE in $(cli_getFilesList ${TEMPLATE} \
69a31c
        --pattern="${FLAG_FILTER}\.${RENDER_EXTENSION}" --type="f" \
4d1322
        | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/');do
5f7579
        FILES[((++${#FILES[*]}))]=$FILE
294842
    done
294842
69a31c
    # Initialize backend-specific functionalities.
69a31c
    cli_exportFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \
69a31c
        ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}"
69a31c
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 \
000216
           | sed -r 's!trunk/(Manuals|Identity)!trunk/Locales/\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}/!!" \
69a31c
            | sed -r "s/\.${RENDER_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
74ff53
        # Perform backend base-rendition.
74ff53
        ${RENDER_BACKEND}
9e0b92
74ff53
        # Perform backend post-rendition.
74ff53
        ${RENDER_BACKEND}_doPostActions
1b9973
74ff53
        # Perform backend last-rendition.
74ff53
        ${RENDER_BACKEND}_doLastActions
1b9973
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
69a31c
    # Unset backend-specific functionalities.
69a31c
    cli_unsetFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \
69a31c
        ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}"
69a31c
4c79b5
}