Blame Scripts/Bash/Functions/Help/Texinfo/texinfo_createChapter.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_createChapter.sh -- This function standardizes chapter
878a2b
# creation insdie the manual structure.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function texinfo_createChapter {
878a2b
878a2b
    # Verify chapter directory inside the manual structure.  The
878a2b
    # chapter directory is where chapter-specific information (e.g.,
878a2b
    # chapter definition files and sections) are stored in.  If this
878a2b
    # directory already exist, assume it was created correctly in the
878a2b
    # past. Otherwise, request confirmation for creating it.
878a2b
    if [[ -d $MANUAL_CHAPTER_DIR ]];then
878a2b
        return
878a2b
    else
bc31d9
        cli_printMessage "`gettext "The following documentation chapter doesn't exist:"`" --as-stdout-line
878a2b
        cli_printMessage "${MANUAL_CHAPTER_DIR}" --as-response-line
bc31d9
        cli_printMessage "`gettext "Do you want to create it now?"`" --as-yesornorequest-line
878a2b
    fi
878a2b
878a2b
    # Initialize chapter node, chapter index and chapter title.
878a2b
    local MANUAL_CHAPTER_NODE=''
878a2b
    local MANUAL_CHAPTER_TITLE=''
878a2b
    local MANUAL_CHAPTER_CIND=''
878a2b
878a2b
    # Request the user to enter a chapter title.
576c84
    cli_printMessage "`gettext "Enter chapter's title"`" --as-request-line
878a2b
    read MANUAL_CHAPTER_TITLE
878a2b
878a2b
    # Sanitate chapter node, chapter index and chapter title.
878a2b
    MANUAL_CHAPTER_NODE=$(texinfo_getEntryNode "$MANUAL_CHAPTER_NAME")
878a2b
    MANUAL_CHAPTER_CIND=$(texinfo_getEntryIndex "$MANUAL_CHAPTER_TITLE")
878a2b
    MANUAL_CHAPTER_TITLE=$(texinfo_getEntryTitle "$MANUAL_CHAPTER_TITLE")
878a2b
878a2b
    # Define list of template files used to build the chapter main
878a2b
    # definition files.
878a2b
    local FILE=''
878a2b
    local FILES=$(cli_getFilesList "${MANUAL_TEMPLATE_L10N}/Chapters" \
878a2b
        --maxdepth='1' \
878a2b
        --pattern="chapter(-menu|-nodes)?\.${MANUAL_EXTENSION}")
878a2b
878a2b
    # Create chapter directory using subversion. This is the place
878a2b
    # where all chapter-specific files will be stored in.
878a2b
    if [[ ! -d ${MANUAL_CHAPTER_DIR} ]];then
576c84
        cli_printMessage "${MANUAL_CHAPTER_DIR}" --as-creating-line
576c84
        cli_runFnEnvironment svn --quiet --mkdir ${MANUAL_CHAPTER_DIR}
878a2b
    fi
878a2b
878a2b
    # Create chapter-specific files using template files as reference.
878a2b
    for FILE in $FILES;do
878a2b
878a2b
        # Verify texinfo templates used as based to build the chapter
878a2b
        # structure.  Be sure they are inside the working copy of
878a2b
        # The CentOS Artwork Repository (-w) and under version control
878a2b
        # (-n), too.
a46862
        cli_checkFiles ${FILE} --is-versioned
576c84
576c84
        # Print action name.
576c84
        cli_printMessage "${MANUAL_CHAPTER_DIR}/$(basename ${FILE})" --as-creating-line
dce515
        
878a2b
        # Copy template files into the chapter directory.
576c84
        cli_runFnEnvironment svn --quiet --copy ${FILE} ${MANUAL_CHAPTER_DIR}
878a2b
878a2b
    done
878a2b
878a2b
    # Before expanding chapter information, be sure the slash (/)
878a2b
    # character be scaped. Otherwise, if the slashes aren't scape,
878a2b
    # they will be interpreted as sed's separator and might provoke
878a2b
    # sed to complain.
878a2b
    MANUAL_CHAPTER_NODE=$(echo "$MANUAL_CHAPTER_NODE" | sed -r 's/\//\\\//g')
878a2b
    MANUAL_CHAPTER_CIND=$(echo "$MANUAL_CHAPTER_CIND" | sed -r 's/\//\\\//g')
878a2b
    MANUAL_CHAPTER_TITLE=$(echo "$MANUAL_CHAPTER_TITLE" | sed -r 's/\//\\\//g')
878a2b
    MANUAL_CHAPTER_NAME=$(echo "$MANUAL_CHAPTER_NAME" | sed -r 's/\//\\\//g')
878a2b
878a2b
    # Expand translation markers inside chapter main definition file.  
878a2b
    sed -i -r \
878a2b
        -e "s/=CHAPTER_NODE=/${MANUAL_CHAPTER_NODE}/" \
878a2b
        -e "s/=CHAPTER_TITLE=/${MANUAL_CHAPTER_TITLE}/" \
878a2b
        -e "s/=CHAPTER_CIND=/${MANUAL_CHAPTER_CIND}/" \
878a2b
        -e "s/=CHAPTER_NAME=/${MANUAL_CHAPTER_NAME}/" \
878a2b
        ${MANUAL_CHAPTER_DIR}/chapter.${MANUAL_EXTENSION}
878a2b
878a2b
    # Remove content from `chapter-nodes.texinfo' file to start with a
878a2b
    # clean node structure. This file is also used to create new
878a2b
    # documentation entries, but we don't need that information right
878a2b
    # now (when the chapter structure is created), just an empty copy
878a2b
    # of the file. The node structure of chapter is created
878a2b
    # automatically based on action value.
878a2b
    echo "" > ${MANUAL_CHAPTER_DIR}/chapter-nodes.${MANUAL_EXTENSION}
878a2b
878a2b
    # Update chapter information inside the manual's texinfo
878a2b
    # structure.
878a2b
    texinfo_updateChapterMenu
878a2b
    texinfo_updateChapterNodes
878a2b
878a2b
}