From 4591de21e3f8c98d9250728d7392c6744d4d8d49 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jun 11 2011 17:58:49 +0000 Subject: Update `render' functionality: - Follow `tuneup' design committed at revision 3409. See description there. --- diff --git a/Scripts/Functions/Render/render.sh b/Scripts/Functions/Render/render.sh index 02562ae..e53579f 100644 --- a/Scripts/Functions/Render/render.sh +++ b/Scripts/Functions/Render/render.sh @@ -74,14 +74,12 @@ function render { # where backend-specific directories are stored in. local RENDER_BACKEND_DIR="${FUNCDIR}/${FUNCDIRNAM}/Backends" - # Initialize extension pattern used to retrive template files as - # an empty value. The value of this variable specifies the file - # extensions that `centos-art.sh' will look for building the list - # of files to process. The list of files to process contains the - # files that satisfy this file extension pattern. The value of - # this variable is redefine later, at the moment of evaluating the - # repository renderable paths. - local RENDER_EXTENSION='' + # Initialize list of supported file extensions. These file + # extensions are used by design model files, the files used as + # base-rendition input. In order for design model files to be + # correclty rendered, they must end with one of the file + # extensions listed here. + local RENDER_EXTENSIONS='svg docbook' # Interpret arguments and options passed through command-line. render_getOptions @@ -109,21 +107,13 @@ function render { # Define renderable directories and the way they are produced. # To describe the way renderable directories are produced, we # take the action value (ACTIONVAL) as reference and describe - # the production through the action name (ACTIONNAM), the - # rendition backend (RENDER_BACKEND) and the rendition - # extension (RENDER_EXTENSION) related to it. + # the production through an action name (ACTIONNAM). if [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/Identity/Images/Themes" ]];then ACTIONNAM="${FUNCNAME}_doThemeActions" - RENDER_BACKEND='svg' - RENDER_EXTENSION='(svgz|svg)' elif [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/Identity/Images" ]];then ACTIONNAM="${FUNCNAME}_doBaseActions" - RENDER_BACKEND='svg' - RENDER_EXTENSION='(svgz|svg)' elif [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/Manuals" ]];then ACTIONNAM="${FUNCNAME}_doBaseActions" - RENDER_BACKEND='docbook' - RENDER_EXTENSION='docbook' else cli_printMessage "`gettext "The path provided does not support rendition."`" --as-error-line fi diff --git a/Scripts/Functions/Render/render_doBaseActions.sh b/Scripts/Functions/Render/render_doBaseActions.sh index e665600..2b1f08f 100755 --- a/Scripts/Functions/Render/render_doBaseActions.sh +++ b/Scripts/Functions/Render/render_doBaseActions.sh @@ -35,6 +35,7 @@ function render_doBaseActions { local EXTERNALFILES='' local THIS_FILE_DIR='' local NEXT_FILE_DIR='' + local RENDER_EXTENSION='' local COUNT=0 # Verify default directory where design models are stored in. @@ -46,165 +47,186 @@ function render_doBaseActions { # Define base location of template files. render_getDirTemplate - # Define the list of files to process. Use an array variable to - # store the list of files to process. This make posible to realize - # verifications like: is the current base directory equal to the - # next one in the list of files to process? Questions like this - # is let us to know when centos-art.sh is leaving a directory - # structure and entering another. This information is required in - # order for centos-art.sh to know when to apply last-rendition - # actions. - # - # Another issue is that some directories might be named as if they - # were files (e.g., using a renderable extension like .docbook). - # In these situations we need to avoid such directories from being - # interpreted as a renderable file. For this, pass the - # `--type="f"' option when building the list of files to process - # in order to retrive regular files only. - # - # Another issue to consider here, is that in some cases both - # templates and outputs might be in the same location. In these - # cases localized content are stored in the same location where - # template files are retrived from and we need to avoid using - # localized content from being interpreted as design models. In - # that sake, supress language-specific files from the list of - # files to process. - # - # Another issue to consider here, is the way of filtering. We - # cannot expand the pattern specified by FLAG_FILTER with a `.*' - # here (e.g., "${FLAG_FILTER}.*\.${RENDER_EXTENSION}") because - # that would suppress any possibility from the user to specifiy - # just one file name in locations where more than one file with - # the same name as prefix exists (e.g., `repository.docbook', - # `repository-preamble.docbook' and `repository-parts.docbook'). - # Instead, pass filtering control to the user whom can use regular - # expression markup in the `--filter' option to decide whether to - # match `repository.docbook' only (e.g., through - # `--filter="repository"') or `repository-preamble.docbook' and - # `repository-parts.docbook' but not `repository.docbook' (e.g., - # through `--filter="repository-.*"'). - for FILE in $(cli_getFilesList ${TEMPLATE} \ - --pattern="${FLAG_FILTER}\.${RENDER_EXTENSION}" --type="f" \ - | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/');do - FILES[((++${#FILES[*]}))]=$FILE - done - - # Initialize backend-specific functionalities. - cli_exportFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \ - ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}" - - # Start processing the base rendition list of FILES. Fun part - # approching :-). - while [[ $COUNT -lt ${#FILES[*]} ]];do - - # Define base file. - FILE=${FILES[$COUNT]} - - # Define the base directory path for the current file being - # process. - THIS_FILE_DIR=$(dirname ${FILES[$COUNT]}) - - # Define the base directory path for the next file that will - # be process. - if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then - NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]}) - else - NEXT_FILE_DIR='' - fi - - # Print separator line. - cli_printMessage '-' --as-separator-line - - # Define final location of translation file. - TRANSLATION=$(dirname $FILE \ - | sed -r 's!trunk/(Manuals|Identity)!trunk/Locales/\1!')/$(cli_getCurrentLocale)/messages.po - - # Print final location of translation file. - if [[ ! -f "$TRANSLATION" ]];then - cli_printMessage "`gettext "None"`" --as-translation-line + # Loop through list of supported file extensions. + for RENDER_EXTENSION in ${RENDER_EXTENSIONS};do + + # Redefine name of rendition backend based on supported file + # extension. + if [[ $RENDER_EXTENSION == 'svg' ]];then + RENDER_BACKEND='svg' + elif [[ $RENDER_EXTENSION == 'docbook' ]];then + RENDER_BACKEND='docbook' else - cli_printMessage "$TRANSLATION" --as-translation-line + cli_printMessage "`eval_gettext "The \\\"\\\$RENDER_EXTENSION\\\" file extension is not supported yet."`" --as-error-line fi - # Define final location of template file. - TEMPLATE=${FILE} - - # Print final location of template file. - if [[ ! -f "$TEMPLATE" ]];then - cli_printMessage "`gettext "None"`" --as-design-line - else - cli_printMessage "$TEMPLATE" --as-design-line - fi - - # Define final location of output directory. - render_getDirOutput - - # Get relative path to file. The path string (stored in FILE) - # has two parts: 1. the variable path and 2. the common path. - # The variable path is before the common point in the path - # string. The common path is after the common point in the - # path string. The common point is the name of the parent - # directory (stored in PARENTDIR). - # - # Identity/Models/Themes/.../Firstboot/3/splash-small.svg - # -------------------------^| the |^------------^ - # variable path | common | common path - # -------------------------v| point | v------------v - # Identity/Images/Themes/.../Firstboot/Img/3/splash-small.png + # Define the list of files to process. Use an array variable + # to store the list of files to process. This make posible to + # realize verifications like: is the current base directory + # equal to the next one in the list of files to process? + # Questions like this is let us to know when centos-art.sh is + # leaving a directory structure and entering another. This + # information is required in order for centos-art.sh to know + # when to apply last-rendition actions. # - # What we do here is remove the varibale path, the common - # point, and the file extension parts in the string holding - # the path retrived from design models directory structure. - # Then we use the common path as relative path to store the - # the final image file. + # Another issue is that some directories might be named as if + # they were files (e.g., using a renderable extension like + # .docbook). In these situations we need to avoid such + # directories from being interpreted as a renderable file. For + # this, pass the `--type="f"' option when building the list of + # files to process in order to retrive regular files only. # - # The file extension is removed from the common path because - # it is set when we create the final image file. This - # configuration let us use different extensions for the same - # file name. + # Another issue to consider here, is that in some cases both + # templates and outputs might be in the same location. In + # these cases localized content are stored in the same + # location where template files are retrived from and we need + # to avoid using localized content from being interpreted as + # design models. In that sake, supress language-specific files + # from the list of files to process. # - # When we render using base-rendition action, the structure of - # files under the output directory will be the same used after - # the common point in the related design model directory - # structure. - FILE=$(echo ${FILE} \ - | sed -r "s!.*${PARENTDIR}/!!" \ - | sed -r "s/\.${RENDER_EXTENSION}$//") - - # Define absolute path to final file (without extension). - FILE=${OUTPUT}/$(basename "${FILE}") - - # Define instance name from design model. - INSTANCE=$(cli_getTemporalFile ${TEMPLATE}) - - # Apply translation file to design model to produce the design - # model translated instance. - render_doTranslation - - # Expand translation markers inside design model instance. - cli_replaceTMarkers ${INSTANCE} - - # Perform backend base-rendition. - ${RENDER_BACKEND} - - # Perform backend post-rendition. - ${RENDER_BACKEND}_doPostActions - - # Perform backend last-rendition. - ${RENDER_BACKEND}_doLastActions - - # Remove template instance. - if [[ -f $INSTANCE ]];then - rm $INSTANCE + # Another issue to consider here, is the way of filtering. We + # cannot expand the pattern specified by FLAG_FILTER with a + # `.*' here (e.g., "${FLAG_FILTER}.*\.${RENDER_EXTENSION}") + # because that would suppress any possibility from the user to + # specifiy just one file name in locations where more than one + # file with the same name as prefix exists (e.g., + # `repository.docbook', `repository-preamble.docbook' and + # `repository-parts.docbook'). Instead, pass filtering + # control to the user whom can use regular expression markup + # in the `--filter' option to decide whether to match + # `repository.docbook' only (e.g., through + # `--filter="repository"') or `repository-preamble.docbook' + # and `repository-parts.docbook' but not `repository.docbook' + # (e.g., through `--filter="repository-.*"'). + for FILE in $(cli_getFilesList ${TEMPLATE} \ + --pattern="${FLAG_FILTER}\.${RENDER_EXTENSION}" --type="f" \ + | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/');do + FILES[((++${#FILES[*]}))]=$FILE + done + + # Verify list of files to process. Assuming no file is found, + # evaluate the next supported file extension. + if [[ ${#FILES[*]} -eq 0 ]];then + continue fi - # Increment file counter. - COUNT=$(($COUNT + 1)) + # Initialize backend-specific functionalities. + cli_exportFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \ + ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}" + + # Start processing the base rendition list of FILES. Fun part + # approching :-). + while [[ $COUNT -lt ${#FILES[*]} ]];do + + # Define base file. + FILE=${FILES[$COUNT]} + + # Define the base directory path for the current file being + # process. + THIS_FILE_DIR=$(dirname ${FILES[$COUNT]}) + + # Define the base directory path for the next file that will + # be process. + if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then + NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]}) + else + NEXT_FILE_DIR='' + fi + + # Print separator line. + cli_printMessage '-' --as-separator-line + + # Define final location of translation file. + TRANSLATION=$(dirname $FILE \ + | sed -r 's!trunk/(Manuals|Identity)!trunk/Locales/\1!')/$(cli_getCurrentLocale)/messages.po + + # Print final location of translation file. + if [[ ! -f "$TRANSLATION" ]];then + cli_printMessage "`gettext "None"`" --as-translation-line + else + cli_printMessage "$TRANSLATION" --as-translation-line + fi + + # Define final location of template file. + TEMPLATE=${FILE} + + # Print final location of template file. + if [[ ! -f "$TEMPLATE" ]];then + cli_printMessage "`gettext "None"`" --as-design-line + else + cli_printMessage "$TEMPLATE" --as-design-line + fi + + # Define final location of output directory. + render_getDirOutput + + # Get relative path to file. The path string (stored in + # FILE) has two parts: 1. the variable path and 2. the + # common path. The variable path is before the common + # point in the path string. The common path is after the + # common point in the path string. The common point is the + # name of the parent directory (stored in PARENTDIR). + # + # Identity/Models/Themes/.../Firstboot/3/splash-small.svg + # -------------------------^| the |^------------^ + # variable path | common | common path + # -------------------------v| point | v------------v + # Identity/Images/Themes/.../Firstboot/Img/3/splash-small.png + # + # What we do here is remove the varibale path, the common + # point, and the file extension parts in the string + # holding the path retrived from design models directory + # structure. Then we use the common path as relative path + # to store the the final image file. + # + # The file extension is removed from the common path + # because it is set when we create the final image file. + # This configuration let us use different extensions for + # the same file name. + # + # When we render using base-rendition action, the + # structure of files under the output directory will be + # the same used after the common point in the related + # design model directory structure. + FILE=$(echo ${FILE} \ + | sed -r "s!.*${PARENTDIR}/!!" \ + | sed -r "s/\.${RENDER_EXTENSION}$//") + + # Define absolute path to final file (without extension). + FILE=${OUTPUT}/$(basename "${FILE}") + + # Define instance name from design model. + INSTANCE=$(cli_getTemporalFile ${TEMPLATE}) + + # Apply translation file to design model to produce the design + # model translated instance. + render_doTranslation + + # Expand translation markers inside design model instance. + cli_replaceTMarkers ${INSTANCE} + + # Perform backend base-rendition. + ${RENDER_BACKEND} + + # Perform backend post-rendition. + ${RENDER_BACKEND}_doPostActions + + # Perform backend last-rendition. + ${RENDER_BACKEND}_doLastActions + + # Remove template instance. + if [[ -f $INSTANCE ]];then + rm $INSTANCE + fi + + # Increment file counter. + COUNT=$(($COUNT + 1)) + + done + + # Unset backend-specific functionalities. + cli_unsetFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \ + ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}" done - - # Unset backend-specific functionalities. - cli_unsetFunctions "${RENDER_BACKEND_DIR}/$(cli_getRepoName \ - ${RENDER_BACKEND} -d)" "${RENDER_BACKEND}" - }