Skip to content

Instantly share code, notes, and snippets.

@jelovirt
Created July 19, 2012 05:48
Show Gist options
  • Save jelovirt/3141029 to your computer and use it in GitHub Desktop.
Save jelovirt/3141029 to your computer and use it in GitHub Desktop.
DITA-OT porcelain script
#!/bin/bash
# This file is part of the DITA Open Toolkit project hosted on
# Sourceforge.net. See the accompanying license.txt file for
# applicable licenses.
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
usage() {
cat << EOF
Usage: ditaot options
Run DITA-OT process.
Required arguments:
-i, --input=FILE input file
-t, --transtype=ID transformation type
Optional:
--draft
--figurelink.style=TYPE
-l, --logfile=FILE log output file
--logdir=DIR
--tablelink.style=TYPE
-f, --filter=FILE profiling filter file
-o, --output=DIR output directory
--validate=BOOL
--clean.temp=BOOL
--temp=DIR temporary directory
--rellinks=TYPE output related links
TYPE is 'none', 'family', or 'all'
--dita.locale=LANG
XHTML options:
--artlbl
--breadcrumbs=BOOL
--copycss
--css=FILENAME
--csspath=DIRNAME
--cssroot=DIR
--ftr=FILE
--gen.default.meta=BOOL
--gen.task.lbl
--hdf=FILE
--hdr=FILE
--indexshow
--xhtml.toc.class=BOOL
--xhtml.classattr=BOOL
--xsl=FILE
--outext=EXT
--generate.copy.outer=TYPE
--onlytopic.in.map
--outer.control=TYPE
--xhtml.contenttarget=NAME
--xhtml.toc=FILENAME
PDF options:
--xsl.pdf=FILE
--fo.userconfig=FILE
--custom.xep.config=FILE
--bookmap-order=TYPE
--customization.dir=DIR
--pdf.formatter=NAME
ODT Options
--odt.img.embed=BOOL
Eclipse content options:
--eclipsecontent.toc=NAME
Eclipse help options:
--eclipsehelp.toc=FILENAME
--eclipse.country=COUNTRY
--eclipse.language=LANG
--eclipse.provider=NAME
--eclipse.version=VERSION
--eclipse.symbolic.name=ID
HTML Help options:
--htmlhelp.includefile=FILE
JavaHelp options
--javahelp.map=FILE
--javahelp.toc=FILE
Miscellaneous:
--grammar.cache=BOOL
--dita.ext=EXT
-v, --verbose enable verbose output
-q, --quiet enable quiet output
-h, --help display this help and exit
EOF
}
if [ "${DITA_HOME:+1}" != "1" ]; then
export DITA_HOME="$(dirname "$(dirname "$(realpath "$0")")")"
fi
if [ "${ANT_HOME:+1}" != "1" ]; then
export ANT_HOME="$DITA_HOME"/tools/ant
fi
export ANT_OPTS="-Xmx512m $ANT_OPTS"
export ANT_OPTS="$ANT_OPTS -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl"
NEW_CLASSPATH="$DITA_HOME/lib"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/dost.jar"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/commons-codec-1.4.jar"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/resolver.jar"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/icu4j.jar"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/saxon/saxon9.jar"
NEW_CLASSPATH="$NEW_CLASSPATH:$DITA_HOME/lib/saxon/saxon9-dom.jar"
if test -n "$CLASSPATH" ; then
export CLASSPATH="$NEW_CLASSPATH":"$CLASSPATH"
else
export CLASSPATH="$NEW_CLASSPATH"
fi
#debug=false
req_num=0
optspec=":ilhvoftq-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
temp=*)
val="${OPTARG#*=}"
args="$args -Ddita.temp.dir=\"${val}\""
;;
output=*)
val="${OPTARG#*=}"
args="$args -Doutput.dir=\"${val}\""
;;
logfile=*)
val="$(realpath "${OPTARG#*=}")"
args="$args -l \"${val}\""
;;
verbose)
args="$args -v"
;;
quiet)
args="$args -q"
;;
onlytopic.in.map)
val="${OPTARG#*=}"
opt=${OPTARG%%=*}
args="$args -D${OPTARG}=\"true\""
;;
transtype=*)
val="${OPTARG#*=}"
opt=${OPTARG%%=*}
args="$args -D${opt}=\"${val}\""
let "req_num += 1"
;;
dita.ext=*|validate=*|generate.copy.outer=*|\
outer.control=*|pdf.formatter=*|clean.temp=*)
val="${OPTARG#*=}"
opt=${OPTARG%%=*}
args="$args -D${opt}=\"${val}\""
;;
custom.xep.config=*|customization.dir=*)
val="$(realpath "${OPTARG#*=}")"
opt=${OPTARG%%=*}
args="$args -D${opt}=\"${val}\""
;;
debug)
args="$args -Dargs.${OPTARG}=\"yes\""
export ANT_OPTS="-showversion $ANT_OPTS"
#debug=true
;;
draft|artlbl|copycss|gen.task.lbl|indexshow)
args="$args -Dargs.${OPTARG}=\"yes\""
;;
figurelink.style=*|grammar.cache=*|tablelink.style=*|\
filter=*|breadcrumbs=*|css=*|csspath=*|gen.default.meta=*|xhtml.toc.class=*|\
xhtml.classattr=*|outext=*|rellinks=*|bookmap-order=*|\
odt.img.embed=*|eclipsecontent.toc=*|xhtml.contenttarget=*|xhtml.toc=*|eclipsehelp.toc=*|\
eclipse.country=*|eclipse.language=*|eclipse.provider=*|eclipse.version=*|eclipse.symbolic.name=*|\
dita.locale=*)
val="${OPTARG#*=}"
opt=${OPTARG%%=*}
args="$args -Dargs.${opt}=\"${val}\""
;;
input=*|logdir=*|xsl.pdf=*|fo.userconfig=*|xsl=*|hdf=*|hdr=*|ftr=*|cssroot=*|\
htmlhelp.includefile=*|javahelp.map=*|javahelp.toc=*)
val="$(realpath "${OPTARG#*=}")"
opt=${OPTARG%%=*}
args="$args -Dargs.${opt}=\"${val}\""
;;
input=*)
val="$(realpath "${OPTARG#*=}")"
opt=${OPTARG%%=*}
args="$args -Dargs.${opt}=\"${val}\""
let "req_num += 1"
;;
help)
usage
exit 2
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
fi
;;
esac
;;
i)
val="$(realpath "${!OPTIND}")"; OPTIND=$(( $OPTIND + 1 ))
args="$args -Dargs.input=\"${val}\""
let "req_num += 1"
;;
l)
val="$(realpath "${!OPTIND}")"; OPTIND=$(( $OPTIND + 1 ))
args="$args -l \"${val}\""
;;
t)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
args="$args -Dtranstype=\"${val}\""
let "req_num += 1"
;;
o)
val="$(realpath "${!OPTIND}")"; OPTIND=$(( $OPTIND + 1 ))
args="$args -Ddita.output.dir=\"${val}\""
;;
f)
val="$(realpath "${!OPTIND}")"; OPTIND=$(( $OPTIND + 1 ))
args="$args -Dargs.filter=\"${val}\""
;;
v)
args="$args -v"
;;
q)
args="$args -q"
;;
h)
usage
exit 2
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
fi
;;
esac
done
#if [ "${debug}" == "true" ]; then
# echo "Arguments: $args"
#fi
# verify number or required arguments
if [ "$req_num" -ne "2" ] ; then
usage
else
exec $ANT_HOME/bin/ant -f "$DITA_HOME/build.xml" $args
fi
@jelovirt
Copy link
Author

@numinasthmatic @robander Maybe instead of using only options, the usage should be

ditaot [options] INPUT

So that the first argument is the --input option. Or, it could be

ditaot [options] INPUT [OUTPUT]

This way we could deduce the transtype from the OUTPUT argument file extension; this is what .e.g DITAC does. Though, for XHTML I would probably want to call this

ditaot -t xhtml main.ditamap output/

And not specify the output file name, only the output directory, because XHTML generates multiple files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment