gnome-doc-process script



Hi,

Attached is a patch that adds a new script called gnome-doc-process to
gnome-doc-utils. The idea is to provide a wrapper around xsltproc that's
slightly easier to use for common operations. It'll guess default values
for a lot of the XSL template parameters and make sure that you specify
the ones that can't be guessed. For instance, to make HTML out of a
sample docbook file, I just do:

gnome-doc-process -m html -t top.xhtml ../press_release/docbook/C/press_release.xml 

in the simplest case. This automatically dumps the output into
press_release/C/, with the toplevel output into
press_release/C/top.xhtml. There's also a cute feature where if you pass
a "--lang ja" option, it'll do the same processing with /C/ replaces
with /ja/ in the input and output. Hopefully this will make it easy to
automate doc generation in makefiles.

I also have sketchy support for an OMF mode that will use the db2omf
template. My hope is to use develop specialized XSL templates for
generating web-friendly HTML and then add another mode to use those
templates: "-m htmlweb" or something like that.

Comments? This is obviously not perfect, but I think it's a good
starting point for some kind of tool that will make everyone's life
easier.

Peter

-- 
Peter Williams / peter newton cx

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-doc-utils/ChangeLog,v
retrieving revision 1.298
diff -u -r1.298 ChangeLog
--- ChangeLog	18 Dec 2005 20:39:56 -0000	1.298
+++ ChangeLog	20 Dec 2005 21:58:15 -0000
@@ -1,3 +1,12 @@
+2005-12-20  Peter Williams  <peter newton cx>
+
+	* configure.in (AC_OUTPUT): Add gnome-doc-process.
+
+	* Makefile.am (bin_SCRIPTS): Add gnome-doc-process to bin_SCRIPTS.
+
+	* xslt/docbook/common/db-xref.xsl: Replace an obsoleted call to
+	format.mailto.tooltip with a call to the email.tooltip l10n template.
+
 2005-12-18  Shaun McCance  <shaunm gnome org>
 
 	* NEWS:
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-doc-utils/Makefile.am,v
retrieving revision 1.22
diff -u -r1.22 Makefile.am
--- Makefile.am	27 Nov 2005 21:10:11 -0000	1.22
+++ Makefile.am	20 Dec 2005 21:58:15 -0000
@@ -19,7 +19,7 @@
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gnome-doc-utils.pc
 
-bin_SCRIPTS = gnome-doc-prepare
+bin_SCRIPTS = gnome-doc-prepare gnome-doc-process
 endif
 
 # doc must go last
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-doc-utils/configure.in,v
retrieving revision 1.79
diff -u -r1.79 configure.in
--- configure.in	18 Dec 2005 20:39:56 -0000	1.79
+++ configure.in	20 Dec 2005 21:58:15 -0000
@@ -34,6 +34,7 @@
 AC_OUTPUT([
 Makefile
 gnome-doc-prepare
+gnome-doc-process
 gnome-doc-utils.pc
 doc/Makefile
 doc/gnome-doc-make/Makefile
Index: gnome-doc-process.in
===================================================================
RCS file: gnome-doc-process.in
diff -N gnome-doc-process.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnome-doc-process.in	20 Dec 2005 21:58:15 -0000
@@ -0,0 +1,268 @@
+#! /bin/sh
+# gnome-doc-process - Process DocBook files into various output formats
+# @configure_input@
+# Copyright (C) 2005 Peter Williams <peter newton cx>
+#
+# Derived very roughly from gnome-doc-prepare.in (arg handling, skeleton
+# stuff.)
+#
+# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# The name of this program.
+progname=`echo "$0" | sed 's%^.*/%%'`
+
+# Constants.
+PROGRAM=gnome-doc-process
+PACKAGE= PACKAGE@
+VERSION= VERSION@
+
+# Directory names.
+prefix= prefix@
+datarootdir= datarootdir@
+datadir= datadir@
+
+# FIXME: I am not sure whether we should get this info
+# through pkg-config or not. Since this file is generated
+# at build time, it seems saner just to use the hardcoded
+# value, rather than rely on an external program (pkg-config)
+# and possible environmental vagaries (PKG_CONFIG_PATH,
+# for example.)
+
+xsltdir=${datadir}/xml/gnome/xslt
+
+# programs
+
+xsltproc="xsltproc"
+
+# args
+
+dry_run=no
+mode=unset
+outdir=unset
+mylang=C
+topname=unset
+helpdir=unset
+omfdir=unset
+omf_in=unset
+options=
+globaloptions=
+help="Try '$progname --help' for more information."
+
+while test $# -gt 0 ; do
+  case "$1" in
+  --help)
+    cat <<EOF
+Usage: $progname [OPTION]... DOCBOOKFILE [DOCBOOKFILE2]...
+
+Process DOCBOOKFILE into formatted output
+
+-m, --mode MODE         what kind of output to generate: one of
+                           html omf
+                        html is the default
+-o, --outdir DIR        the directory to output into, default {first input name}/C
+-t, --top-name NAME     the filename to output the top output
+                        (what xsltproc dumps to stdout) into, default
+                        depends on MODE
+-l, --lang LANG         Operate on files for language code LANG
+                        (substitutes /C/ -> /LANG/ in paths, default is C)
+
+OMF mode only:
+
+    --omf-in FILE       Path to a .omf.in template file
+    --helpdir DIR       The directory in which help files are installed
+    --omfdir DIR        The directory in which OMF files are installed
+
+Miscellaneous options:
+
+    --debug             enable verbose shell tracing
+-n, --dry-run           print commands rather than running them
+    --help              display this message and exit
+    --version           print version information and exit
+EOF
+    exit 0
+    ;;
+
+  -m | --mode)
+    shift
+    mode="$1"
+    ;;
+
+  -n | --dry-run)
+    if test "$dry_run" != yes; then
+      dry_run=yes
+      xsltproc="echo $xsltproc"
+    fi
+    ;;
+
+  -o | --outdir)
+    shift
+    outdir="$1"
+    ;;
+
+  -t | --top-name)
+    shift
+    topname="$1"
+    ;;
+
+  -l | --lang)
+    shift
+    mylang="$1"
+    ;;
+
+  --omf-in)
+    shift
+    omf_in="$1"
+    ;;
+
+  --helpdir)
+    shift
+    helpdir="$1"
+    ;;
+
+  --omfdir)
+    shift
+    omfdir="$1"
+    ;;
+
+# boring options
+
+  --version)
+    echo "$PROGRAM (GNU $PACKAGE) $VERSION"
+    exit 0
+    ;;
+
+  --debug)
+    echo "$progname: enabling shell trace mode"
+    set -x
+    ;;
+
+  -*)
+    echo "$progname: unrecognized option '$arg'" 1>&2
+    echo "$help" 1>&2
+    exit 1
+    ;;
+
+  *)
+     break
+    ;;
+  esac
+
+  shift
+done
+
+if test $# -lt 1 ; then
+    echo "$progname: at least one DocBook file to process must be specified" 1>&2
+    echo "$help" 1>&2
+    exit 1
+fi
+
+# FIXME: we will break later on filenames with $IFS 
+# in them later because of this. No biggie, probably.
+infiles=`echo $@ |sed -e "s,/C/,/$mylang/,g"`
+docbase=`basename $1 |sed -e 's,\([^.]*\)\.[^.]*,\1,'`
+
+if test x"$outdir" = xunset ; then
+    outdir="${docbase}/$mylang"
+fi
+
+# Setup mode
+
+if test x"$mode" = xunset ; then
+    echo "$progname: warning: assuming mode is 'html'; this default may change in the future." 1>&2
+    echo "$progname: you can explicitly set the mode with a '-m MODE' argument." 1>&2
+    mode=html
+fi
+
+case "$mode" in
+    html)
+	stylesheet="$xsltdir/docbook/html/db2html.xsl"
+	topname_default=index.xhtml
+	options="--stringparam db.chunk.extension .xhtml"
+	options="$options --stringparam db.chunk.info_basename ${docbase}-info"
+	;;
+    omf)
+	# report as many errors as possible to save time for people 
+	# fooling with the command line
+	error=false
+	if [ x"$omf_in" = xunset ] ; then
+	    echo "$progname: you must specify a .omf.in template file with the --omf-in flag" 1>&2
+	    error=true
+	elif [ ! -f "$omf_in" ] ; then
+	    echo "$progname: the specified.omf.in template file '$omf_in' doesn't exist" 1>&2
+	    error=true
+	fi
+	if [ x"$omfdir" = xunset ] ; then
+	    echo "$progname: you must specify the OMF install directory with the --omfdir flag" 1>&2
+	    error=true
+	fi
+	if [ x"$helpdir" = xunset ] ; then
+	    echo "$progname: you must specify the help install directory with the --helpdir flag" 1>&2
+	    error=true
+	fi
+	$error && exit 1
+
+	# Canonicalize to full path for xsltproc
+	if echo $omf_in |grep '^[^/]' 1>/dev/null 2>&1 ; then
+	    omf_in=`pwd`/"$omf_in"
+	fi
+
+	stylesheet="$xsltdir/docbook/omf/db2omf.xsl"
+	topname_default="${docbase}-${mylang}.omf"
+	options="--stringparam db2omf.basename $docbase"
+	options="$options --stringparam db2omf.format docbook"
+	options="$options --stringparam db2omf.lang $mylang"
+	options="$options --stringparam db2omf.omf_dir $omfdir"
+	options="$options --stringparam db2omf.help_dir $helpdir"
+	options="$options --stringparam db2omf.omf_in $omf_in"
+	#options="$options --stringparam db2omf.dtd "
+	;;
+    *)
+	echo "$progname: unrecognized mode '$mode'" 1>&2
+	echo "$help" 1>&2
+	exit 1
+	;;
+esac
+
+if test ! -f "$stylesheet" ; then
+    echo "$progname: can't find the needed stylesheet file '$stylesheet'" 1>&2
+    echo "$programe: something is probably wrong with your installation of $PACKAGE" 1>&2
+    exit 1
+fi
+
+if test x"$topname" = xunset ; then
+    topname="$topname_default"
+fi
+
+# Do it!
+
+status=0
+
+if $xsltproc --xinclude -o "$outdir/$topname" $globaloptions $options "$stylesheet" $infiles ; then :
+else
+    status=1
+    echo "$progname: xsltproc reported an error. See any messages reported above." 1>&2
+fi
+
+exit $status
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]