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
#
2fe9b7
# 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=''
034027
    local TEMPLATE_HAS_DOCTYPE=''
294842
    local PARENTDIR=''
294842
    local TRANSLATION=''
294842
    local EXTERNALFILE=''
294842
    local EXTERNALFILES=''
294842
    local THIS_FILE_DIR=''
294842
    local NEXT_FILE_DIR=''
4591de
    local RENDER_EXTENSION=''
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.
8c13b6
    render_getDirTemplate
294842
    
4591de
    # Loop through list of supported file extensions. 
4591de
    for RENDER_EXTENSION in ${RENDER_EXTENSIONS};do
4591de
4591de
        # Redefine name of rendition backend based on supported file
4591de
        # extension.
8c13b6
        if [[ $RENDER_EXTENSION == '^(svg|docbook)$' ]];then
8c13b6
            RENDER_BACKEND=${RENDER_EXTENSION}
294842
        else
4591de
           cli_printMessage "`eval_gettext "The \\\"\\\$RENDER_EXTENSION\\\" file extension is not supported yet."`" --as-error-line 
294842
        fi
294842
4591de
        # Define the list of files to process. Use an array variable
4591de
        # to store the list of files to process. This make posible to
4591de
        # realize verifications like: is the current base directory
4591de
        # equal to the next one in the list of files to process?
4591de
        # Questions like this is let us to know when centos-art.sh is
4591de
        # leaving a directory structure and entering another. This
4591de
        # information is required in order for centos-art.sh to know
4591de
        # when to apply last-rendition actions.
294842
        #
4591de
        # Another issue is that some directories might be named as if
4591de
        # they were files (e.g., using a renderable extension like
4591de
        # .docbook).  In these situations we need to avoid such
4591de
        # directories from being interpreted as a renderable file. For
4591de
        # this, pass the `--type="f"' option when building the list of
4591de
        # files to process in order to retrive regular files only.
294842
        #
4591de
        # Another issue to consider here, is that in some cases both
4591de
        # templates and outputs might be in the same location. In
4591de
        # these cases localized content are stored in the same
4591de
        # location where template files are retrived from and we need
4591de
        # to avoid using localized content from being interpreted as
4591de
        # design models. In that sake, supress language-specific files
4591de
        # from the list of files to process.
294842
        #
4591de
        # Another issue to consider here, is the way of filtering. We
4591de
        # cannot expand the pattern specified by FLAG_FILTER with a
4591de
        # `.*' here (e.g., "${FLAG_FILTER}.*\.${RENDER_EXTENSION}")
4591de
        # because that would suppress any possibility from the user to
4591de
        # specifiy just one file name in locations where more than one
4591de
        # file with the same name as prefix exists (e.g.,
4591de
        # `repository.docbook', `repository-preamble.docbook' and
4591de
        # `repository-parts.docbook').  Instead, pass filtering
4591de
        # control to the user whom can use regular expression markup
4591de
        # in the `--filter' option to decide whether to match
4591de
        # `repository.docbook' only (e.g., through
4591de
        # `--filter="repository"') or `repository-preamble.docbook'
4591de
        # and `repository-parts.docbook' but not `repository.docbook'
4591de
        # (e.g., through `--filter="repository-.*"').
4591de
        for FILE in $(cli_getFilesList ${TEMPLATE} \
4591de
            --pattern="${FLAG_FILTER}\.${RENDER_EXTENSION}" --type="f" \
4591de
            | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/');do
4591de
            FILES[((++${#FILES[*]}))]=$FILE
4591de
        done
4591de
4591de
        # Verify list of files to process. Assuming no file is found,
4591de
        # evaluate the next supported file extension.
4591de
        if [[ ${#FILES[*]} -eq 0 ]];then
4591de
            continue
294842
        fi
294842
4591de
        # Initialize backend-specific functionalities.
4591de
        cli_exportFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \
4591de
            ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}"
4591de
4591de
        # Start processing the base rendition list of FILES. Fun part
4591de
        # approching :-).
4591de
        while [[ $COUNT -lt ${#FILES[*]} ]];do
4591de
4591de
            # Define base file.
4591de
            FILE=${FILES[$COUNT]}
4591de
4591de
            # Define the base directory path for the current file being
4591de
            # process.
4591de
            THIS_FILE_DIR=$(dirname ${FILES[$COUNT]})
4591de
4591de
            # Define the base directory path for the next file that will
4591de
            # be process.
4591de
            if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then
4591de
                NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]})
4591de
            else
4591de
                NEXT_FILE_DIR=''
4591de
            fi
4591de
4591de
            # Print separator line.
4591de
            cli_printMessage '-' --as-separator-line
4591de
4591de
            # Define final location of translation file.
4591de
            TRANSLATION=$(dirname $FILE \
a5d502
               | sed -r 's!trunk/(Manuals|Identity)!trunk/L10n/\1!')/$(cli_getCurrentLocale)/messages.po
4591de
4591de
            # Define final location of template file.
4591de
            TEMPLATE=${FILE}
4591de
6c620e
            # Verify design models file existence. We cannot continue
6c620e
            # with out it.
6c620e
            if [[ ! -f $TEMPLATE ]];then
6c620e
                cli_printMessage "`gettext "The template file doesn't exist."`" --as-error-line
6c620e
            fi
6c620e
6c620e
            # Verify whether the design model uses DOCTYPE definition
034027
            # or not; and redefine related variable for further using.
6c620e
            egrep '^ /dev/null
034027
            TEMPLATE_HAS_DOCTYPE=$?
034027
034027
            # Validate design model before processing it. This step is
034027
            # very important in order to detect document's
034027
            # malformations and warn you about it, so you can correct
034027
            # them before processing the document as input.  Notice
034027
            # that, here, validation is possible only for documents
034027
            # which have a DOCTYPE definition inside.
6c620e
            if [[ $TEMPLATE_HAS_DOCTYPE -eq 0 ]];then
034027
034027
                # Print action message.
b62abf
                cli_printMessage "$TEMPLATE" --as-validating-line
034027
034027
                # Validate document before processing it.  
b62abf
                xmllint --valid --noent --noout $TEMPLATE
b62abf
                if [[ $? -ne 0 ]];then
b62abf
                    cli_printMessage "`gettext "Validation failed."`" --as-error-line
b62abf
                fi
034027
034027
            else
034027
                # Print action message.
034027
                cli_printMessage "$TEMPLATE" --as-template-line
4591de
            fi
4591de
 
4591de
            # Define final location of output directory.
8c13b6
            render_getDirOutput
4591de
4591de
            # Get relative path to file. The path string (stored in
4591de
            # FILE) has two parts: 1. the variable path and 2. the
4591de
            # common path.  The variable path is before the common
4591de
            # point in the path string. The common path is after the
4591de
            # common point in the path string. The common point is the
4591de
            # name of the parent directory (stored in PARENTDIR).
4591de
            #
4591de
            # Identity/Models/Themes/.../Firstboot/3/splash-small.svg
4591de
            # -------------------------^| the     |^------------^
4591de
            # variable path             | common  |    common path
4591de
            # -------------------------v| point   |    v------------v
4591de
            # Identity/Images/Themes/.../Firstboot/Img/3/splash-small.png
4591de
            #
4591de
            # What we do here is remove the varibale path, the common
4591de
            # point, and the file extension parts in the string
4591de
            # holding the path retrived from design models directory
4591de
            # structure.  Then we use the common path as relative path
4591de
            # to store the the final image file.
4591de
            #
4591de
            # The file extension is removed from the common path
4591de
            # because it is set when we create the final image file.
4591de
            # This configuration let us use different extensions for
4591de
            # the same file name.
4591de
            #
4591de
            # When we render using base-rendition action, the
4591de
            # structure of files under the output directory will be
4591de
            # the same used after the common point in the related
4591de
            # design model directory structure.
4591de
            FILE=$(echo ${FILE} \
4591de
                | sed -r "s!.*${PARENTDIR}/!!" \
4591de
                | sed -r "s/\.${RENDER_EXTENSION}$//")
4591de
4591de
            # Define absolute path to final file (without extension).
4591de
            FILE=${OUTPUT}/$(basename "${FILE}")
4591de
4591de
            # Define instance name from design model.
4591de
            INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
4591de
4591de
            # Apply translation file to design model to produce the design
4591de
            # model translated instance. 
8c13b6
            render_doTranslation
4591de
4591de
            # Expand translation markers inside design model instance.
54cb18
            cli_expandTMarkers ${INSTANCE}
4591de
4591de
            # Perform backend base-rendition.
4591de
            ${RENDER_BACKEND}
4591de
4591de
            # Remove template instance. 
4591de
            if [[ -f $INSTANCE ]];then
4591de
                rm $INSTANCE
4591de
            fi
4591de
4591de
            # Increment file counter.
4591de
            COUNT=$(($COUNT + 1))
4591de
4591de
        done
4591de
4591de
        # Unset backend-specific functionalities.
4591de
        cli_unsetFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \
4591de
            ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}"
f3bce7
07c2fe
    done
4c79b5
}