From 64aead5d1c1b6aa70b34d079ff094031b69e0292 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jun 30 2013 15:52:19 +0000 Subject: Update centos-art.sh script. - Add files to complete previous refactoring. --- diff --git a/Scripts/Bash/Functions/Prepare/prepare_updateDirectoryStructure.sh b/Scripts/Bash/Functions/Prepare/prepare_updateDirectoryStructure.sh new file mode 100755 index 0000000..b7c8f7f --- /dev/null +++ b/Scripts/Bash/Functions/Prepare/prepare_updateDirectoryStructure.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# +# prepare_updateDirectoryStructure.sh -- This function standardizes +# the relation between source directory structures and target +# directory structures inside the repository. This function takes +# source and target paths as arguments, analyses them and builds the +# target directory structure based on source directory structure. This +# function must be executed before executing production functions like +# render. +# +# In order for this verification to work, all source directory +# structures provided must be organized using one directory level more +# than its related target directory. The purpose of this directory is +# content categorization. For example, consider the following path: +# +# ---------------++++++++++++++++++++++++ +# ${SOURCE_PATH}/${CATEGORY}/${COMPONENT} +# ---------------++++++++++++++++++++++++ +# ++++++++++++++++++++++++++++++++++------------ +# ${TARGET_PATH}/${NAME}/${VERSION}/${COMPONENT} +# ++++++++++++++++++++++++++++++++++------------ +# +# So we end with the following path: +# +# ${TARGET_PATH}/${CATEGORY}/${COMPONENT} +# +# In this path, ${CATEGORY} makes reference to a categorization +# directory used to describe source components related to target +# components. However, in the target side, such ${CATEGORY} directory +# is not needed and should be removed from it in order to get the +# final target path, which is: +# +# ${TARGET_PATH}/${COMPONENT} +# +# ${CATEGORY} is always a one-level directory, but ${COMPONENT} might +# have several levels deep. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function prepare_updateDirectoryStructure { + + # Define absolute path to design models' directory structure. This + # directory contains the directory structure you want to verify + # inside target path. + local SOURCE_PATH=$(cli_checkRepoDirSource "${1}") + + # Verify existence source path, just to be sure it was passed and + # it is a valid directory. + cli_checkFiles ${SOURCE_PATH} -d + + # Define absolute path to directory inside the repository where + # you want to replicate the source path directory structure. + local TARGET_PATH=$(cli_checkRepoDirSource "${2}") + + # NOTE: It is possible that target path doesn't exist. So verify + # the relation between target and source path. If there is a + # source path for the target, create an empty directory as target, + # using the related source directory as reference. + + # Define list of directories inside source path. + local SOURCE_DIRS=$(cli_getFilesList ${SOURCE_PATH} \ + --pattern='.+/[[:alpha:]]+$' --type=d) + + # Iterate through directories inside source path and verify + # whether or not they exist in the target path. If they don't + # exist create them. + for SOURCE_DIR in ${SOURCE_DIRS};do + + local SOURCE_DIR_BASENAME=$(echo ${SOURCE_DIR} \ + | sed -r "s,${SOURCE_PATH}/,,") + + local TARGET_DIR=${TARGET_PATH}/${SOURCE_DIR_BASENAME} + + if [[ ${SOURCE_DIR} == ${SOURCE_DIR_BASENAME} ]];then + continue + fi + + # Keep this for debugging ;) + #echo '---' + #echo $SOURCE_DIR_BASENAME; + #echo $SOURCE_DIR; + #echo $TARGET_DIR; + #echo $TARGET_PATH; + #echo '---' + #continue + + if [[ ! -d ${TARGET_DIR} ]];then + mkdir -p ${TARGET_DIR} + fi + + done + +} diff --git a/Scripts/Bash/Functions/Render/Conf/conf_setBaseRendition.sh b/Scripts/Bash/Functions/Render/Conf/conf_setBaseRendition.sh new file mode 100755 index 0000000..4962373 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Conf/conf_setBaseRendition.sh @@ -0,0 +1,126 @@ +#!/bin/bash +# +# conf_setBaseRendition.sh -- This function standardizes base actions +# related to image production through configuration files. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function conf_setBaseRendition { + + local COUNTER=0 + local EXPORTID="CENTOSARTWORK" + local -a MODEL_INSTANCES + local -a IMAGE_INSTANCES + local -a IMAGE_COMMANDS + + # Define absolute path to output location. This is the location + # inside the working copy all images will be stored in. + local OUTPUT=${OUTPUT}/${FGCOLOR}/${BGCOLOR}/${HEIGHT}/${FILENAME} + + # Define which command will be used to output the template + # content. This is required because template files might be found + # as compressed files inside the repository. + local VIEWER="/bin/cat" + + while [[ $COUNTER -lt ${#MODELS[*]} ]];do + + # Verify existence and extension of design models. + cli_checkFiles ${MODELS[$COUNTER]} -f --match='\.(svgz|svg)$' + + # Define file name for design model instances. We need to use + # a random string in from of it to prevent duplication. + # Remember that different files can have the same name in + # different locations. Use the correct file information. + MODEL_INSTANCES[$COUNTER]=${TMPDIR}/${RANDOM}-$(basename ${MODELS[$COUNTER]}) + + # Define file name for image instances. We need to use a + # random string in from of it to prevent duplication. + # Remember that different files can have the same name in + # different locations. Use the correct file information. + IMAGE_INSTANCES[$COUNTER]=${TMPDIR}/${RANDOM}-$(basename ${MODELS[$COUNTER]} \ + | sed -r 's/\.(svgz|svg)$/.png/') + + # Redefine command used to read design models. + if [[ $(file -b -i ${MODELS[$COUNTER]}) =~ '^application/x-gzip$' ]];then + VIEWER="/bin/zcat" + fi + + # Create uncompressed design model instances in order to make + # color replacements without affecting original design models. + $VIEWER ${MODELS[$COUNTER]} > ${MODEL_INSTANCES[$COUNTER]} + + # Make your best to be sure the design model instance you are + # processing is a valid scalable vector graphic. + cli_checkFiles ${MODEL_INSTANCES[$COUNTER]} --mime="text/xml" + + # Make color replacements to each design model instance before + # render them using Inkscape. + if [[ ${FGCOLOR} != '000000' ]];then + sed -i -r "s/((fill|stroke):#)000000/\1${FGCOLOR}/g" ${MODEL_INSTANCES[$COUNTER]} + fi + + # Create list of Inkscape commands based for each design model + # set in the configuration file. + IMAGE_COMMANDS[${COUNTER}]="${MODEL_INSTANCES[$COUNTER]} \ + --export-id=${EXPORTID} \ + --export-png=${IMAGE_INSTANCES[$COUNTER]} \ + --export-background=$(echo ${BGCOLOR} | cut -d'-' -f1) \ + --export-background-opacity=$(echo ${BGCOLOR} | cut -d'-' -f2) \ + --export-height=${HEIGHT}" + + # Create PNG image based on design models. + inkscape ${IMAGE_COMMANDS[$COUNTER]} > /dev/null + + COUNTER=$(( $COUNTER + 1 )) + + done + + cli_printMessage "${OUTPUT}" --as-creating-line + + # Verify existence of output directory. + if [[ ! -d $(dirname ${OUTPUT}) ]];then + mkdir -p $(dirname ${OUTPUT}) + fi + + # Apply command to PNG images produced from design models to + # construct the final PNG image. + ${COMMAND} ${IMAGE_INSTANCES[*]} ${OUTPUT} + + # Remove instances to save disk space. There is no need to have + # unused files inside the temporal directory. They would be + # consuming space unnecessarily. Moreover, there is a remote + # chance of name collapsing (because the huge number of files that + # would be in place and the week random string we are putting in + # front of files) which may produce unexpected results. + rm ${IMAGE_INSTANCES[*]} ${MODEL_INSTANCES[*]} + + # Create path for different image formats creation using PNG image + # extension as reference. + local TARGET=$(echo ${OUTPUT} | sed -r "s/\.png$//") + + # Convert images from PNG to those formats specified in the + # configuration file. + for FORMAT in ${FORMATS};do + cli_printMessage "${TARGET}.${FORMAT}" --as-creating-line + convert ${OUTPUT} ${TARGET}.${FORMAT} + done + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionText.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionText.sh new file mode 100755 index 0000000..7c4673c --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionText.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# +# svg_convertToText.sh -- This function takes the XHTML file produced +# by docbook_setConversionXhtml and produces one plain-text file (i.e., +# without markup inside). +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setConversionText { + + # Verify existence of HTML file. If `.xhtml' file doesn't exist + # don't create text file. The `.xhtml' file is required in order + # to create the `.txt' file. + if [[ ! -f ${FILE}.xhtml ]];then + return + fi + + local COMMAND='' + local OPTIONS='' + + # Define the command path to text-based web browser and options + # used to produce plain-text files. Most of these programs have a + # dump option that print formatted plain-text versions of given + # HTML file to stdout. + if [[ -x '/usr/bin/lynx' ]];then + COMMAND='/usr/bin/lynx' + OPTIONS='-force_html -nolist -width 70 -dump' + elif [[ -x '/usr/bin/elinks' ]];then + COMMAND='/usr/bin/elinks' + OPTIONS='-force_html -no-numbering -no-references -width 70 -dump' + elif [[ -x '/usr/bin/w3m' ]];then + COMMAND='/usr/bin/w3m' + OPTIONS='-dump' + fi + + if [[ $COMMAND != '' ]];then + + # Print action message. + if [[ -f ${FILE}.txt ]];then + cli_printMessage "${FILE}.txt" --as-updating-line + else + cli_printMessage "${FILE}.txt" --as-creating-line + fi + + # Convert from HTML to plain-text without markup. + ${COMMAND} ${OPTIONS} ${FILE}.xhtml > ${FILE}.txt + + else + cli_printMessage "`gettext "No way to convert from XHTML to plain-text found."`" --as-error-line + fi + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtml.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtml.sh new file mode 100755 index 0000000..1c9f0a6 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtml.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# docbook_setConversionXhtml.sh -- This function uses DocBook XML as input +# and applies XSL stylesheets to produce a big XHTML files as output. +# The procedure was taken from the documentation of +# `docbook-style-xsl-1.69.1-5.1' package, which says: ---To publish +# HTML from your XML documents, you just need an XSL engine.---. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setConversionXhtml { + + local -a STYLE_TEMPLATE + local -a STYLE_INSTANCE + local STYLE_INSTANCE_FINAL='' + + # Define absolute path to DocBook source file. This is the + # repository documentation manual file where DOCTYPE and ENTITY + # definition lines are set. + local SOURCE_FILE=${1} + + # Define absolute path to xhtml target file. This is the final + # location the xhtml file produced as result of DocBook to xhtml + # transformation will be stored in. + local TARGET_FILE=${FILE}-xhtml/$(basename ${FILE}).xhtml + + # Define absolute path to xhtml target file directory. This is the + # location the xhtml target file will be sotred in. + local TARGET_FILE_DIR=$(dirname ${TARGET_FILE}) + + # Print action message. + if [[ -f ${FILE}.xhtml ]];then + cli_printMessage "${TARGET_FILE}" --as-updating-line + else + cli_printMessage "${TARGET_FILE}" --as-creating-line + fi + + # Prepare XSL final instances used in transformations. + docbook_setStyles $(cli_getFilesList \ + ${DOCBOOK_XSL} --pattern='^.*/docbook2xhtml-(single|common)\.xsl$') + + # Clean up output directory. This is required in order to prevent + # old files from remaining therein when they are no longer needed. + if [[ -d ${TARGET_FILE_DIR} ]];then + rm -r "${TARGET_FILE_DIR}" + fi + mkdir ${TARGET_FILE_DIR} + + # Transform DocBook XML to XHTML suppressing all stderr output. + xsltproc --output ${TARGET_FILE} ${STYLE_INSTANCE_FINAL} ${SOURCE_FILE} &> /dev/null + + # Create `css' and `images' directories. In order to save disk + # space, these directories are linked (symbolically) to their + # respective locations inside the working copy. + ln -fs ${TCAR_WORKDIR}/Identity/Webenv/Themes/Default/Docbook/1.69.1/Css ${TARGET_FILE_DIR}/Css + ln -fs ${TCAR_WORKDIR}/Identity/Images/Webenv ${TARGET_FILE_DIR}/Images + + # Remove XSL instance files. + rm ${STYLE_INSTANCE[*]} + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtmlChunks.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtmlChunks.sh new file mode 100755 index 0000000..4caf61f --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXhtmlChunks.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# docbook_setConversionXhtmlChunks.sh -- This function uses DocBook XML as +# input and applies XSL stylesheets to produce a directory with many +# XHTML files as output. The procedure was taken from the +# documentation of `docbook-style-xsl-1.69.1-5.1' package, which says: +# ---To publish HTML from your XML documents, you just need an XSLT +# engine.---. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setConversionXhtmlChunks { + + local -a STYLE_TEMPLATE + local -a STYLE_INSTANCE + local STYLE_INSTANCE_FINAL='' + + # Define absolute path to DocBook source file. This is the + # repository documentation manual file where DOCTYPE and ENTITY + # definition lines are set. + local SOURCE_FILE=${1} + + # Define absolute path to XHTML target file. This is the final + # location the XHTML file produced as result of DocBook to PDF + # transformation will be stored in. + local TARGET_FILE="${FILE}-xhtml-chunks/" + + # Clean up output directory. This is required in order to prevent + # old files from remaining therein when they are no longer needed. + if [[ -d ${TARGET_FILE} ]];then + rm -r "${TARGET_FILE}" + fi + mkdir ${TARGET_FILE} + + # Print action message. + cli_printMessage "${TARGET_FILE}" --as-creating-line + + # Prepare XSL final instances used in transformations. + docbook_setStyles $(cli_getFilesList \ + ${DOCBOOK_XSL} --pattern='^.*/docbook2xhtml-(chunks|common)\.xsl$') + + # Transform DocBook XML to XHTML suppressing all stderr output. + xsltproc --output ${TARGET_FILE} ${STYLE_INSTANCE_FINAL} ${SOURCE_FILE} &> /dev/null + + # Create `css' and `images' directories. In order to save disk + # space, these directories are linked (symbolically) to their + # respective locations inside the working copy. Be sure to remove + # previous links first to prevent a recursive creation of links. + ln -sf ${TCAR_WORKDIR}/Identity/Webenv/Themes/Default/Docbook/1.69.1/Css ${TARGET_FILE}/Css + ln -sf ${TCAR_WORKDIR}/Identity/Images/Webenv ${TARGET_FILE}/Images + + # Remove XSL instance files. + rm ${STYLE_INSTANCE[*]} + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXml2Pdf.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXml2Pdf.sh new file mode 100755 index 0000000..f639e93 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setConversionXml2Pdf.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# +# docbook_setConversionXml2Pdf.sh -- This function transforms DocBook +# files which have set the XML DTD in them. To produce PDF from +# DocBook XML DTD, we need an XSLT engine (e.g., through `xsltproc' +# command) to produce formatting objects (FO), which then must be +# processed with an FO engine (e.g., through `pdfxmltex' command, +# which uses PassiveTex) to produce the PDF output. +# +# In this configuration and using default configuration settings, I've +# presented the following problems: +# +# 1. Something is wrong with headings. They are not expanded along the +# whole page-body. They seem to be rendered in a reduced width (1 inch +# approximately). This provokes the heading to be broken in a +# two-to-five letters column and sometimes it overlaps the sectioning +# titles (e.g., chapter, section). I tried to customize the value of +# `header.column.widths' and `page.margin.top' but it seems to be not +# there where I need to touch. +# +# 2. TOC's indentation is not rendered. Even the `toc.indent.width' +# property is set to 24 by default. +# +# 3. Inside lists, when items are more than one line, the indentation +# seems to work for the first line only. All other lines in the same +# item are not indented and begin completely unaligned. +# +# 4. Long file paths near the end of page-body aren't hyphenated. +# Even the `hyphenate' property is set to `true' by default. +# +# In this configuration and using default configuration settings, I've +# presented the following advantages: +# +# 1. It is possible to produce localized PDF outputs through +# `xml2po', the default way of producing localized content inside +# the `centos-art.sh' script. +# +# To make the whole process transparent, a temporal directory is +# created for intermediate works and final files are moved then to +# their final location. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setConversionXml2Pdf { + + # Print action message. + cli_printMessage "${FILE}.pdf" --as-creating-line + + local -a STYLE_TEMPLATE + local -a STYLE_INSTANCE + local STYLE_INSTANCE_FINAL='' + + # Define absolute path to DocBook source file. This is the + # repository documentation manual file where DOCTYPE and ENTITY + # definition lines are set. + local SRC=${INSTANCE} + + # Define absolute path to PDF target file. This is the final + # location the PDF file produced as result of DocBook to PDF + # transformation will be stored in. + local DST="${FILE}.pdf" + + # Define file name of formatting object (.fo) file. This file is + # an intermediate file needed to produced the PDF. + local FO=$(echo ${INSTANCE} | sed -r 's/docbook$/fo/g') + + # Define file name of PDF file. This is the file we were looking + # for and the one moved, once produced. + local PDF=$(echo ${INSTANCE} | sed -r 's/docbook$/pdf/g') + + # Prepare XSL final instances used in transformations. + docbook_setStyles "${DOCBOOK_XSL}/docbook2fo.xsl" + + # Create link to `Images' directory. This is the directory where + # images used by documentation are stored in. Be sure to remove + # previous links first to prevent a recursive creation of links. + ln -sf ${TCAR_WORKDIR}/Identity/Images/Webenv $(dirname ${INSTANCE})/Images + + # Create formatting object suppressing output from stderr. + xsltproc --output ${FO} ${STYLE_INSTANCE_FINAL} ${SRC} 2> /dev/null + + # Create PDF format from formatting object. Because we are using + # relative path to access `Images', it is necessary to move the + # directory stack into the temporal directory where instance files + # are created. Otherwise, the location used to load images will + # fail. + if [[ $? -eq 0 ]];then + pushd $(dirname ${INSTANCE}) > /dev/null + xmlto -o $(dirname ${FILE}) pdf ${FO} + popd > /dev/null + else + cli_printMessage "`gettext "Cannot produce the PDF file."`" --as-error-line + fi + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionLicenses.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionLicenses.sh new file mode 100755 index 0000000..cb3a032 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionLicenses.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# docbook_setExpansionLicenses.sh -- This function modifies the final +# DocBook instance to add license information. We are doing this way +# because using XInclude doesn't work and we want to reuse license +# information in all documents. So, if we cannot link the files, we +# modify the final instance and append the license information to it. +# Later, to reuse translation messages, the locale functionality takes +# care of merging po files related to licenses into documentation po +# file so changes made to licenses translations will also be available +# to documentation manuals in different languages. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setExpansionLicenses { + + local INSTANCE=$1 + + # Define absolute path to DocBook models. + local DOCBOOK_MODELS="${TCAR_WORKDIR}/Documentation/Models/Docbook" + + # Define list of files holding licenses you want to include. Note + # even this files are not inside the documentation structure + # itself, they are connected with it. The files holding license + # information does contain id information used inside the + # documentation structure at cross references. + local LICENSES="${DOCBOOK_MODELS}/Default/Licenses/Gpl/gpl.docbook \ + ${DOCBOOK_MODELS}/Default/Licenses/Gfdl/gfdl.docbook" + + # Define top level structure in the instance. This is the tag + # defined in the second field of DOCTYPE definition. + local DOCTYPE=$(egrep '^\n" + BLOCK="${BLOCK}\n\n" + BLOCK="${BLOCK}\n`gettext "Licenses"`\n" + BLOCK="${BLOCK}\n$(cat ${LICENSES} | sed -r '/<\?xml/,/]>/d')\n" + BLOCK="${BLOCK}\n\n" + BLOCK="${BLOCK}\n\n" + + # Expand the licenses section. Remove everything in-between + # Licenses and Back matter comment. Recreate the comments to + # support further actualizations and concatenate license + # information without their document type definitions preamble. + # This is required in order to prevent validation errors and reuse + # (through locale functionality) the translation messages already + # available for these license files. Finally, close any open tag. + sed -r -i -e "//,//c$(echo ${BLOCK})" $INSTANCE + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionSystemEntities.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionSystemEntities.sh new file mode 100755 index 0000000..090e09c --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setExpansionSystemEntities.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# docbook_setExpansionSystemEntities.sh -- This function expands system +# entities required by DocBook projects stored under +# `Documentation/Manuals' directory. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setExpansionSystemEntities { + + # Define absolute path to instance where all operations will take + # place in. + local INSTANCE=$1 + + # Define absolute path to both common and specific system + # entities. + local ENTITIES_PATHS="$(cli_getFilesList ${TCAR_WORKDIR}/Documentation/Models/Docbook/Default/Book $(dirname ${TEMPLATE}) \ + --pattern='^.*/[[:alpha:]-]+\.ent$' --maxdepth=1 --mindepth=1 --type='f')" + + # Build definition of both common and specific system entities. + local ENTITIES="$(\ + for ENTITY_PATH in $ENTITIES_PATHS;do + local ENTITY_NAME=$(basename ${ENTITY_PATH}) + echo '\n\t\n' + echo '\t%'${ENTITY_NAME}';' + done)" + + # Define both xml and docbook public definition. + local PREAMBLE="" + PREAMBLE="${PREAMBLE}\n" + + # Remove both xml and docbook preamble from instance and insert + # it again with definitions of required common and specific system + # entities. + sed -r -i "1,2c$(echo $PREAMBLE)" ${INSTANCE} + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setLastRendition.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setLastRendition.sh new file mode 100755 index 0000000..7205cd8 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setLastRendition.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# docbook_setLastRendition.sh -- This function performs last-rendition +# actions for DocBook files. These are the actions that take +# base-rendition and post-rendition output as input to produce output +# from it. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setLastRendition { + + # Presently, there is no last-rendition action for DocBook base + # rendition but the function should exist for consistency with + # other formats. + return + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setPostRendition.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setPostRendition.sh new file mode 100755 index 0000000..30afef9 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setPostRendition.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# docbook_setPostRendition.sh -- This function performs post-rendition +# actions for DocBook files. These are the actions that take +# base-rendition output as input to producing output from it. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setPostRendition { + + # Presently, there is no post-rendition action for DocBook base + # rendition but the function should exist for consistency with + # other formats. + return + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setStyles.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setStyles.sh new file mode 100755 index 0000000..8700f0f --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setStyles.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# docbook_setStyles.sh -- This function prepares styles' final +# instances, used in transformations and based on XSL or DSL +# templates. There might be translation markers inside the XSL and +# DSL templates that need to be expanded before they can be used for +# transformations. This function creates temporal instances of XSL +# and DSL templates with translation markers expanded inside so as for +# transformation commands (e.g., `xmltproc' or `openjade' through +# `docbook2pdf') to use as style definition. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setStyles { + + local STYLE_TEMPLATE_FILE='' + local STYLE_TEMPLATE_FILES=$@ + local STYLE_INSTANCE_COMMON='' + local COUNT=0 + + for STYLE_TEMPLATE_FILE in $STYLE_TEMPLATE_FILES;do + + STYLE_TEMPLATE[((++${#STYLE_TEMPLATE[*]}))]="${STYLE_TEMPLATE_FILE}" + STYLE_INSTANCE[((++${#STYLE_INSTANCE[*]}))]="$(cli_getTemporalFile ${STYLE_TEMPLATE_FILE})" + + # Keep track of array's real index value. Remember, it starts + # at zero but counting starts at 1 instead. So, subtracting 1 + # from counting we have the real index value we need to work + # with the information stored in the array. + COUNT=$(( ${#STYLE_INSTANCE[*]} - 1 )) + + # Create style instance from style template. + cp ${STYLE_TEMPLATE[$COUNT]} ${STYLE_INSTANCE[$COUNT]} + + # Define both final an common style instances based on style + # templates. + if [[ $STYLE_TEMPLATE_FILE =~ 'docbook2fo\.xsl$' ]];then + STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[$COUNT]} + elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2pdf\.dsl$' ]];then + STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[${COUNT}]} + elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2xhtml-(chunks|single)\.xsl$' ]];then + STYLE_INSTANCE_FINAL=${STYLE_INSTANCE[${COUNT}]} + elif [[ $STYLE_TEMPLATE_FILE =~ 'docbook2xhtml-common\.xsl$' ]];then + STYLE_INSTANCE_COMMON=${STYLE_INSTANCE[${COUNT}]} + fi + + done + + # Verify style final instance. This is the file used by + # transformation command (`xsltproc' or `openjade') to produce the + # specified output. We cannot continue without it. + cli_checkFiles -e $STYLE_INSTANCE_FINAL + + # Expand common translation markers in the common style instance, + # if it exists. + if [[ -f $STYLE_INSTANCE_COMMON ]];then + cli_expandTMarkers $STYLE_INSTANCE_COMMON + fi + + # Expand specific translation markers in final style instance. + sed -r -i "s!=STYLE_XHTML_COMMON=!${STYLE_INSTANCE_COMMON}!" ${STYLE_INSTANCE_FINAL} + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_setTranslation.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_setTranslation.sh new file mode 100755 index 0000000..1d6bad7 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_setTranslation.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# +# docbook_setTranslation.sh -- This function standardizes the way +# translation files are applied to DocBook design models in order to +# produce the translated instance that is used to expand translation +# markers and produce different output formats. +# +# Assuming no translation file exists, an untranslated instance is +# taken from the design model and created (i.e., just a copy) from it. +# Using a design model instance (translated or not) is required in +# order to expand translation markers safely. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function docbook_setTranslation { + + # Print final location of translation file. + cli_printMessage "${TRANSLATION}" --as-translation-line + + # Create translation instance to combine both template translation + # and licenses translations. + local TRANSLATION_INSTANCE=${TMPDIR}/messages.po + + # Define path to DocBook locales using models as reference. + local DOCBOOK_LOCALES=$(cli_getLocalizationDir "$DOCBOOK_MODELS") + + # Define list of all locale files you want to combine. This + # include the localization files related to all different kind of + # licenses you want to use in the main documentation file and the + # localization file of the main documentation file, as well. + local DOCBOOK_PO_FILES="${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gfdl/${CLI_LANG_LC}/messages.po \ + ${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gpl/${CLI_LANG_LC}/messages.po \ + ${TRANSLATION}" + + # Be sure the files we want to combine do exist. + cli_checkFiles -e ${DOCBOOK_PO_FILES} + + # Combine license translations with template translation in order + # to reuse licenses translations in template files without + # including them in template portable objects. In the case of + # DocBook templates, translations related to licenses are required + # because license content is expanded at execution time inside the + # DocBook instance used by XSL processor during transformation. + msgcat --output=${TRANSLATION_INSTANCE} \ + --width=70 --no-location --use-first ${DOCBOOK_PO_FILES} + + # At this point the translation instance with both licenses and + # manual translations have been saved. Now it is required to + # expand entities so it could be possible to create a translated + # instance with all the content inside. + + # Print action message. + cli_printMessage "${INSTANCE}" --as-translating-line + + # Create the translated instance of design model instance with all + # entities and translation markers expanded. + xml2po -a -l ${CLI_LANG_LL} \ + -p ${TRANSLATION_INSTANCE} \ + -o ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE} + + # Rename final instance so it can be treated as just instance. + mv ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE} + + # Remove .xml2po.mo temporal file. + if [[ -f ${PWD}/.xml2po.mo ]];then + rm ${PWD}/.xml2po.mo + fi + + # Verify instance existence. + cli_checkFiles -e $INSTANCE + +} diff --git a/Scripts/Bash/Functions/Render/render_setBaseRendition.sh b/Scripts/Bash/Functions/Render/render_setBaseRendition.sh new file mode 100755 index 0000000..8591dec --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setBaseRendition.sh @@ -0,0 +1,276 @@ +#!/bin/bash +# +# render_setBaseRendition.sh -- This function performs base-rendition +# action for all files. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_setBaseRendition { + + local -a FILES + local FILE='' + local OUTPUT='' + local TEMPLATE='' + local TEMPLATES='' + local PARENTDIR='' + local TRANSLATION='' + local EXTERNALFILE='' + local EXTERNALFILES='' + local THIS_FILE_DIR='' + local NEXT_FILE_DIR='' + local RENDER_EXTENSION='' + local EXPORTID='' + local COUNT=0 + + # Verify default directory where design models are stored in. + cli_checkFiles -e "${TCAR_WORKDIR}/Identity/Models/Themes/${FLAG_THEME_MODEL}" + + # Redefine parent directory for current workplace. + PARENTDIR=$(basename "${ACTIONVAL}") + + # Loop through list of supported file extensions. + for RENDER_EXTENSION in ${RENDER_EXTENSIONS};do + + # Redefine rendition format name based on supported file + # extension. + if [[ $RENDER_EXTENSION =~ '^(svgz|svg)$' ]];then + RENDER_FORMAT='svg' + elif [[ $RENDER_EXTENSION =~ '^(docbook)$' ]];then + RENDER_FORMAT='docbook' + elif [[ $RENDER_EXTENSION =~ '^(conf)$' ]];then + RENDER_FORMAT='conf' + else + cli_printMessage "`eval_gettext "The \\\"\\\$RENDER_EXTENSION\\\" file extension is not supported yet."`" --as-error-line + fi + + # Redefine specific function export id. + EXPORTID="${CLI_FUNCDIRNAM}/$(cli_getRepoName ${RENDER_FORMAT} -d)/$(cli_getRepoName ${RENDER_FORMAT} -f)" + + # Define base location of template files using paths passed to + # centos-art.sh script as argument to. + render_getDirTemplate + + # Verify whether or not the source location of the path + # provided as argument to centos-art.sh script accepts or not + # localization messages. Don't produce localized content for + # repository components that don't accept it. + if [[ ! ${CLI_LANG_LC} =~ '^en' ]];then + cli_runFnEnvironment locale --is-localizable ${TEMPLATE} + fi + + # Define the list of files to process. Use an array variable + # to store the list of files to process. This make possible to + # realize verifications like: is the current base directory + # equal to the next one in the list of files to process? + # Questions like this 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 render able extension like + # .docbook). In these situations we need to avoid such + # directories from being interpreted as a render able file. + # For this, pass the `--type="f"' option when building the + # list of files to process in order to retrieve 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 retrieved from and we need + # to avoid using localized content from being interpreted as + # design models. In that sake, build the list of files to + # process using the files directly stored in the directory + # passed as argument to centos-art.sh command-line. Don't go + # recursively here. + # + # Another issue to consider here, is the way of restricting + # the list of files to process. 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 specify 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-.*"'). + if [[ ${RENDER_FORMAT} =~ "^docbook$" ]];then + + # When the render format is docbook, don't build a list of + # files to process. Instead, build the absolute path of + # the main file used to render docbook from models to + # final output manuals. This file must be stored directly + # inside the main manual's directory and named as it but + # with all letters in lowercase. + for FILE in $(cli_getFilesList ${TEMPLATE} \ + --maxdepth="1" --mindepth="1" \ + --pattern="^.*$(cli_getRepoName ${TEMPLATE} -f)\.${RENDER_EXTENSION}$" \ + --type="f");do + FILES[((++${#FILES[*]}))]=$FILE + done + + elif [[ ${RENDER_FORMAT} =~ "^conf$" ]];then + + # When the render format is conf, be sure it refers to + # image.conf files only. Other configuration files (e.g., + # branding.conf) cannot be processed this way because + # their configuration options and values haven't any + # meaning in this context. + for FILE in $(cli_getFilesList ${TEMPLATE} \ + --pattern="^.+/images\.${RENDER_EXTENSION}$" \ + --type="f");do + FILES[((++${#FILES[*]}))]=$FILE + done + + else + + # For all other cases, build a list of files to process + # using the path value pass as argument. + for FILE in $(cli_getFilesList ${TEMPLATE} \ + --pattern="^.+/${FLAG_FILTER}.*\.${RENDER_EXTENSION}$" \ + --type="f");do + FILES[((++${#FILES[*]}))]=$FILE + done + + fi + + # Verify list of files to process. Assuming no file was found, + # evaluate the next supported file extension. + if [[ ${#FILES[*]} -eq 0 ]];then + continue + fi + + # Initialize format-specific functionalities. + cli_exportFunctions "${EXPORTID}" + + # Start processing the base rendition list of FILES. Fun part + # approaching :-). + 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 + + # Print action message based on file extension. + if [[ ${FILE} =~ 'images\.conf$' ]] && [[ $FLAG_WITH_BRANDS == 'true' ]];then + cli_printMessage "${FILE}" --as-processing-line + elif [[ ${FILE} =~ 'brands\.conf$' ]];then + continue + else + cli_printMessage "${FILE}" --as-template-line + fi + + # Verify design models file existence. We cannot continue + # with out it. + cli_checkFiles ${FILE} -f + + # Define final location of translation file. + TRANSLATION=$(dirname ${FILE} \ + | sed -r 's!(Documentation|Identity)!Locales/\1!')/${CLI_LANG_LC}/messages.po + + # Define final location of template file. + TEMPLATE=${FILE} + + # 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 variable path, the common + # point, and the file extension parts in the string + # holding the path retrieved from design models directory + # structure. Then we use the common path as relative path + # to store 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}) + + # Perform format base-rendition. + ${RENDER_FORMAT} + + # Remove template instance. + if [[ -f $INSTANCE ]];then + rm $INSTANCE + fi + + # Increment file counter. + COUNT=$(($COUNT + 1)) + + done + + # Reset counter to prevent accumulation of values. + COUNT=0 + + # Unset format-specific functionalities. + cli_unsetFunctions "${EXPORTID}" + + # Unset files list to prevent accumulation of values. + unset FILES + + done +} diff --git a/Scripts/Bash/Functions/Render/render_setBrands.sh b/Scripts/Bash/Functions/Render/render_setBrands.sh new file mode 100755 index 0000000..187c4df --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setBrands.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# render_setBrands.sh -- This function performs brand-specific +# rendition. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_setBrands { + + local BRANDS_MODELS_DIR=${TCAR_WORKDIR}/Identity/Models/Brands + local BRANDS_IMAGES_DIR=${TCAR_WORKDIR}/Identity/Images/Brands + + render_setBrandsDirValidates ${BRANDS_IMAGES_DIR} ${ACTIONVAL} + render_setBrandsDirStructure ${BRANDS_MODELS_DIR} ${BRANDS_IMAGES_DIR} + + render_setBaseRendition + +} diff --git a/Scripts/Bash/Functions/Render/render_setBrandsDirStructure.sh b/Scripts/Bash/Functions/Render/render_setBrandsDirStructure.sh new file mode 100755 index 0000000..453e90c --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setBrandsDirStructure.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# render_setBrandsDirectoryStructure.sh -- This function verifies the +# directory structure of brands images using the directory structure +# of brands models as reference. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_setBrandsDirStructure { + + local BRANDS_SOURCE_DIR=$(cli_checkRepoDirSource ${1}) + local BRANDS_TARGET_DIR=$(cli_checkRepoDirSource ${2}) + + cli_printMessage "${BRANDS_TARGET_DIR} `gettext "directory structures..."`" --as-checking-line + + cli_runFnEnvironment prepare ${BRANDS_SOURCE_DIR} ${BRANDS_TARGET_DIR} --directories + +} diff --git a/Scripts/Bash/Functions/Render/render_setBrandsDirValidates.sh b/Scripts/Bash/Functions/Render/render_setBrandsDirValidates.sh new file mode 100755 index 0000000..8622474 --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setBrandsDirValidates.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# render_setBrandsDirVerification.sh -- This function standardize path +# verification between path provided in the command line and +# repository directory structure. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + + +function render_setBrandsDirValidates { + + local BRANDS_PATH_OK=$(cli_checkRepoDirSource ${1}) + local BRANDS_PATH_UNKNOWN=$(cli_checkRepoDirSource ${2}) + + cli_checkFiles ${BRANDS_PATH_UNKNOWN} --match="^${BRANDS_PATH_OK}" + + local BRANDS_PATH_UNKNOWN_MODEL=$(echo ${BRANDS_PATH_UNKNOWN} \ + | sed -r "s,/Images/,/Models/,") + + cli_checkFiles ${BRANDS_PATH_UNKNOWN_MODEL} -d + +} diff --git a/Scripts/Bash/Functions/Render/render_setThemes.sh b/Scripts/Bash/Functions/Render/render_setThemes.sh new file mode 100755 index 0000000..7058525 --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setThemes.sh @@ -0,0 +1,153 @@ +#!/bin/bash +# +# render_setThemes.sh -- This function performs theme-specific +# rendition. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_setThemes { + + local -a DIRS + local COUNT=0 + local NEXTDIR='' + local MOTIF_NAME='' + local MOTIF_DIR='' + + # Define base directory of artistic motifs. This is the location + # where all artistic motifs are stored in. + local MOTIF_BASEDIR="${TCAR_WORKDIR}/Identity/Images/Themes" + + # Define base directory of design models. This is the location + # where all design models are stored in. + local MODEL_BASEDIR="${TCAR_WORKDIR}/Identity/Models/Themes" + + # Verify directory structure for all theme-specific directories. + render_setThemesDirStructure "${MODEL_BASEDIR}/${FLAG_THEME_MODEL}" "${MOTIF_BASEDIR}" + + # Define directory structure of design models. Design models + # directory structures are used as reference to create artistic + # motifs directory structure. Use the `--pattern' option to be + # sure any modification to FLAG_FILTER won't affect the output + # result. We need to make matching everything here, no matter what + # the FLAG_FILTER value be. + local MODEL_DIR='' + local MODEL_DIRS="$(cli_getFilesList ${MODEL_BASEDIR}/${FLAG_THEME_MODEL} \ + --pattern='^.+/[^.svn][[:alnum:]_/-]+$' --type="d" \ + | sed -e "s!^.*/${FLAG_THEME_MODEL}!!" \ + -e '/^[[:space:]]*$/d' \ + -e 's!^/!!')" + + # Define design model regular expression patterns from design + # models directory structure. + local MODEL_PATTERN=$(echo "$MODEL_DIRS" | tr "\n" '|' \ + | sed -e 's!^|!!' -e 's!|$!!') + + # Define regular expression pattern that match the theme artistic + # motif component inside the path strings. + local MOTIF_PATTERN=$(cli_getPathComponent --motif-pattern) + + # Define list of render-able directory structures inside the + # artistic motif. As reference, to build this list, use design + # model directory structure. The more specific you be in the path + # specification the more specific theme rendition will be. Thus, + # we use the path provided as argument and the --filter option as + # reference to control the amount of directories considered + # render-able directory. + local MOTIF_RENDERABLE_DIR='' + local MOTIF_RENDERABLE_DIRS=$(cli_getFilesList ${MOTIF_BASEDIR} \ + --pattern="^${TCAR_WORKDIR}/${MOTIF_PATTERN}/($MODEL_PATTERN)$" --type="d" \ + | grep "$(echo ${ACTIONVAL} | sed -r 's,/$,,')") + + # When no render-able directories are found, finish the script + # execution with an error message. There is an obvious typo in the + # path provided. + if [[ -z ${MOTIF_RENDERABLE_DIRS} ]];then + cli_printMessage "`gettext "Nothing to do."`" --as-error-line + fi + + # Rebuild list of render-able directory structures using an array + # variable. This let us to predict what directory is one step + # forward or backward from the current directory structure. + for MOTIF_RENDERABLE_DIR in $MOTIF_RENDERABLE_DIRS;do + DIRS[((++${#DIRS[*]}))]=${MOTIF_RENDERABLE_DIR} + done + + # Define total number of directories to process. This is required + # in order to correct the counting value and so, make it to match + # the zero based nature of bash array variables. + local DIRS_TOTAL=$((${#DIRS[*]} - 1)) + + while [[ $COUNT -le ${DIRS_TOTAL} ]];do + + # Redefine action value to refer the theme-specific render-able + # directory. + ACTIONVAL=${DIRS[$COUNT]} + + # Refine artistic motif name using the current action value. + MOTIF_NAME=$(cli_getPathComponent $ACTIONVAL --motif) + + # Verify artistic motif name. The name of the artistic motif + # must be present in order for theme rendition to happen. + # Theme rendition takes place inside artistic motifs and the + # artistic motif name is an indispensable part of it. Take + # care of not using design models directory structure as name + # for artistic motifs. They, sometimes, match the pattern used + # to verify artistic motifs names but must not be confused. + if [[ $MOTIF_NAME == '' ]] || [[ $MOTIF_NAME =~ "^($MODEL_PATTERN)" ]];then + COUNT=$(($COUNT + 1)) + continue + fi + + # Refine artistic motif directory. This is the top directory + # where all visual manifestations of an artistic motif are + # stored in (e.g., Backgrounds, Brushes, Concept, Distro, + # etc.). + MOTIF_DIR="${MOTIF_BASEDIR}/${MOTIF_NAME}" + + # Define what is the next directory in the list, so we could + # verify whether to render or not the current theme-specific + # render-able directory. + if [[ $COUNT -lt ${DIRS_TOTAL} ]];then + NEXTDIR=$(dirname ${DIRS[(($COUNT + 1))]}) + else + NEXTDIR='' + fi + + # Verify whether to render or not the current theme's + # render-able directory. This verification is needed in order + # to avoid unnecessary rendition loops. For example, don't + # render `path/to/dir/A' when `path/to/dir/A/B' does exist, + # that configuration would produce `/path/to/dir/A/B twice. + if [[ $ACTIONVAL =~ '[[:digit:]]$' ]] || [[ $ACTIONVAL == $NEXTDIR ]];then + COUNT=$(($COUNT + 1)) + continue + fi + + # Execute direct rendition on theme specific render-able + # directory as specified by action value. + render_setBaseRendition + + # Increment counter to match the correct count value. + COUNT=$(($COUNT + 1)) + + done + +} diff --git a/Scripts/Bash/Functions/Render/render_setThemesDirStructure.sh b/Scripts/Bash/Functions/Render/render_setThemesDirStructure.sh new file mode 100755 index 0000000..fed3eb9 --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_setThemesDirStructure.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# render_setThemeDirectoryStructre.sh -- This function verifies +# theme-specific directory structures using common theme models +# directory structure as pattern. If there are missing directories inside +# theme-specific directories, this function will create it. This is a +# requisite of rendition process, so be sure to call this function +# before building the list of render-able theme directories. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + + +function render_setThemesDirStructure { + + local THEMES_SOURCE_DIR=$(cli_checkRepoDirSource "${1}") + local THEMES_TARGET_DIR=$(cli_checkRepoDirSource "${2}") + + local THEMES_FILTER=$(cli_getPathComponent ${ACTIONVAL} --repo-dir) + + THEMES_TARGET_DIRS=$(cli_getFilesList ${THEMES_TARGET_DIR} \ + --pattern=".+/[[:digit:]]+$" --maxdepth=2 --mindepth=2 \ + | grep "${THEMES_FILTER}") + + for THEMES_TARGET_DIR in $THEMES_TARGET_DIRS;do + cli_printMessage "$THEMES_TARGET_DIR `gettext "directory structure..."`" --as-checking-line + cli_runFnEnvironment prepare ${THEMES_SOURCE_DIR} ${THEMES_TARGET_DIR} --directories + done + +}