Blame Scripts/Bash/Functions/Render/render_doBaseActions.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# render_doBaseActions.sh -- This function performs base-rendition
878a2b
# action for all files.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function render_doBaseActions {
878a2b
878a2b
    local -a FILES
878a2b
    local FILE=''
878a2b
    local OUTPUT=''
878a2b
    local TEMPLATE=''
b4a50f
    local TEMPLATES=''
878a2b
    local PARENTDIR=''
878a2b
    local TRANSLATION=''
878a2b
    local EXTERNALFILE=''
878a2b
    local EXTERNALFILES=''
878a2b
    local THIS_FILE_DIR=''
878a2b
    local NEXT_FILE_DIR=''
878a2b
    local RENDER_EXTENSION=''
878a2b
    local COUNT=0
878a2b
878a2b
    # Verify default directory where design models are stored in.
765717
    cli_checkFiles -e "${TCAR_WORKDIR}/trunk/Identity/Models/Themes/${FLAG_THEME_MODEL}"
878a2b
878a2b
    # Redefine parent directory for current workplace.
878a2b
    PARENTDIR=$(basename "${ACTIONVAL}")
878a2b
878a2b
    # Define base location of template files.
878a2b
    render_getDirTemplate
878a2b
    
878a2b
    # Loop through list of supported file extensions. 
878a2b
    for RENDER_EXTENSION in ${RENDER_EXTENSIONS};do
878a2b
24ece8
        # Redefine name of rendition format based on supported file
878a2b
        # extension.
f55962
        if [[ $RENDER_EXTENSION =~ '^(svgz|svg)$' ]];then
56cf52
            RENDER_FORMAT='svg'
56cf52
        elif [[ $RENDER_EXTENSION =~ '^(docbook)$' ]];then
56cf52
            RENDER_FORMAT='docbook'
878a2b
        else
878a2b
           cli_printMessage "`eval_gettext "The \\\"\\\$RENDER_EXTENSION\\\" file extension is not supported yet."`" --as-error-line 
878a2b
        fi
878a2b
878a2b
        # Define the list of files to process. Use an array variable
b4a50f
        # to store the list of files to process. This make possible to
878a2b
        # realize verifications like: is the current base directory
878a2b
        # equal to the next one in the list of files to process?
b4a50f
        # Questions like this let us to know when centos-art.sh is
878a2b
        # leaving a directory structure and entering another. This
878a2b
        # information is required in order for centos-art.sh to know
878a2b
        # when to apply last-rendition actions.
878a2b
        #
878a2b
        # Another issue is that some directories might be named as if
878a2b
        # they were files (e.g., using a renderable extension like
878a2b
        # .docbook).  In these situations we need to avoid such
b4a50f
        # directories from being interpreted as a render able file.
b4a50f
        # For this, pass the `--type="f"' option when building the
b4a50f
        # list of files to process in order to retrieve regular files
b4a50f
        # only.
878a2b
        #
878a2b
        # Another issue to consider here, is that in some cases both
878a2b
        # templates and outputs might be in the same location. In
878a2b
        # these cases localized content are stored in the same
b4a50f
        # location where template files are retrieved from and we need
878a2b
        # to avoid using localized content from being interpreted as
b4a50f
        # design models. In that sake, build the list of files to
b4a50f
        # process using the files directely stored in the directory
b4a50f
        # passed as argument to centos-art.sh command-line. Don't go
b4a50f
        # recursive here.
878a2b
        #
878a2b
        # Another issue to consider here, is the way of filtering. We
878a2b
        # cannot expand the pattern specified by FLAG_FILTER with a
878a2b
        # `.*' here (e.g., "${FLAG_FILTER}.*\.${RENDER_EXTENSION}")
878a2b
        # because that would suppress any possibility from the user to
b4a50f
        # specify just one file name in locations where more than one
878a2b
        # file with the same name as prefix exists (e.g.,
878a2b
        # `repository.docbook', `repository-preamble.docbook' and
878a2b
        # `repository-parts.docbook').  Instead, pass filtering
878a2b
        # control to the user whom can use regular expression markup
878a2b
        # in the `--filter' option to decide whether to match
878a2b
        # `repository.docbook' only (e.g., through
878a2b
        # `--filter="repository"') or `repository-preamble.docbook'
878a2b
        # and `repository-parts.docbook' but not `repository.docbook'
878a2b
        # (e.g., through `--filter="repository-.*"').
b4a50f
        if [[ ${TEMPLATE} =~ "${TCAR_WORKDIR}/trunk/Documentation/(Models|Manuals)/Docbook/.+$" ]];then
b4a50f
            TEMPLATES=$(cli_getFilesList ${TEMPLATE} \
b4a50f
                --maxdepth="1" --mindepth="1" \
bc8245
                --pattern="$(cli_getRepoName ${TEMPLATE} -f)\.${RENDER_EXTENSION}" \
b4a50f
                --type="f")
b4a50f
        else
b4a50f
            TEMPLATES=$(cli_getFilesList ${TEMPLATE} \
bc8245
                --pattern="${FLAG_FILTER}\.${RENDER_EXTENSION}" \
b4a50f
                --type="f")
b4a50f
        fi
b4a50f
        for FILE in $TEMPLATES;do
878a2b
            FILES[((++${#FILES[*]}))]=$FILE
878a2b
        done
878a2b
878a2b
        # Verify list of files to process. Assuming no file is found,
878a2b
        # evaluate the next supported file extension.
878a2b
        if [[ ${#FILES[*]} -eq 0 ]];then
878a2b
            continue
878a2b
        fi
878a2b
24ece8
        # Initialize format-specific functionalities.
0a16be
        cli_exportFunctions "${CLI_FUNCDIRNAM}/$(cli_getRepoName ${RENDER_FORMAT} -d)/$(cli_getRepoName ${RENDER_FORMAT} -f)"
878a2b
878a2b
        # Start processing the base rendition list of FILES. Fun part
b4a50f
        # approaching :-).
878a2b
        while [[ $COUNT -lt ${#FILES[*]} ]];do
878a2b
878a2b
            # Define base file.
878a2b
            FILE=${FILES[$COUNT]}
878a2b
878a2b
            # Define the base directory path for the current file being
878a2b
            # process.
878a2b
            THIS_FILE_DIR=$(dirname ${FILES[$COUNT]})
878a2b
878a2b
            # Define the base directory path for the next file that will
878a2b
            # be process.
878a2b
            if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then
878a2b
                NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]})
878a2b
            else
878a2b
                NEXT_FILE_DIR=''
878a2b
            fi
878a2b
878a2b
            # Print separator line.
878a2b
            cli_printMessage '-' --as-separator-line
878a2b
878a2b
            # Define final location of translation file.
878a2b
            TRANSLATION=$(dirname $FILE \
765717
               | sed -r 's!trunk/(Documentation|Identity)!trunk/Locales/\1!')/${CLI_LANG_LC}/messages.po
878a2b
878a2b
            # Define final location of template file.
878a2b
            TEMPLATE=${FILE}
878a2b
878a2b
            # Verify design models file existence. We cannot continue
878a2b
            # with out it.
878a2b
            if [[ ! -f $TEMPLATE ]];then
878a2b
                cli_printMessage "`gettext "The template file doesn't exist."`" --as-error-line
878a2b
            fi
878a2b
b4a50f
            # Print action message.
b4a50f
            cli_printMessage "$TEMPLATE" --as-template-line
878a2b
 
878a2b
            # Define final location of output directory.
878a2b
            render_getDirOutput
878a2b
878a2b
            # Get relative path to file. The path string (stored in
878a2b
            # FILE) has two parts: 1. the variable path and 2. the
878a2b
            # common path.  The variable path is before the common
878a2b
            # point in the path string. The common path is after the
878a2b
            # common point in the path string. The common point is the
878a2b
            # name of the parent directory (stored in PARENTDIR).
878a2b
            #
878a2b
            # Identity/Models/Themes/.../Firstboot/3/splash-small.svg
878a2b
            # -------------------------^| the     |^------------^
878a2b
            # variable path             | common  |    common path
878a2b
            # -------------------------v| point   |    v------------v
878a2b
            # Identity/Images/Themes/.../Firstboot/Img/3/splash-small.png
878a2b
            #
878a2b
            # What we do here is remove the varibale path, the common
878a2b
            # point, and the file extension parts in the string
878a2b
            # holding the path retrived from design models directory
878a2b
            # structure.  Then we use the common path as relative path
878a2b
            # to store the the final image file.
878a2b
            #
878a2b
            # The file extension is removed from the common path
878a2b
            # because it is set when we create the final image file.
878a2b
            # This configuration let us use different extensions for
878a2b
            # the same file name.
878a2b
            #
878a2b
            # When we render using base-rendition action, the
878a2b
            # structure of files under the output directory will be
878a2b
            # the same used after the common point in the related
878a2b
            # design model directory structure.
878a2b
            FILE=$(echo ${FILE} \
878a2b
                | sed -r "s!.*${PARENTDIR}/!!" \
878a2b
                | sed -r "s/\.${RENDER_EXTENSION}$//")
878a2b
878a2b
            # Define absolute path to final file (without extension).
878a2b
            FILE=${OUTPUT}/$(basename "${FILE}")
878a2b
878a2b
            # Define instance name from design model.
878a2b
            INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
878a2b
878a2b
            # Apply translation file to design model to produce the design
878a2b
            # model translated instance. 
878a2b
            render_doTranslation
878a2b
878a2b
            # Expand translation markers inside design model instance.
878a2b
            cli_expandTMarkers ${INSTANCE}
878a2b
24ece8
            # Perform format base-rendition.
24ece8
            ${RENDER_FORMAT}
878a2b
878a2b
            # Remove template instance. 
878a2b
            if [[ -f $INSTANCE ]];then
878a2b
                rm $INSTANCE
878a2b
            fi
878a2b
878a2b
            # Increment file counter.
878a2b
            COUNT=$(($COUNT + 1))
878a2b
878a2b
        done
878a2b
24ece8
        # Unset format-specific functionalities.
24ece8
        cli_unsetFunctions "${RENDER_FORMAT_DIR}/$(cli_getRepoName \
24ece8
            ${RENDER_FORMAT} -d)" "${RENDER_FORMAT}"
878a2b
878a2b
    done
878a2b
}