Skip to content

Commit

Permalink
improved doc gen script; converts rst files to ipynb and html and sto…
Browse files Browse the repository at this point in the history
…res both
  • Loading branch information
sperka committed Jun 18, 2015
1 parent 743e667 commit f58970d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
35 changes: 27 additions & 8 deletions docs/make_rst_htmls.sh
@@ -1,25 +1,44 @@
#!/bin/bash

# set target output directory
TARGETDIR=_build/html
HTMLDIR=_build/html
IPYNBDIR=_build/ipynb

# if does not exist, create it
if [ ! -d "$TARGETDIR" ]; then
mkdir -p $TARGETDIR
if [ ! -d "$HTMLDIR" ]; then
mkdir -p $HTMLDIR
fi
if [ ! -d "$IPYNBDIR" ]; then
mkdir -p $IPYNBDIR
fi

# files to load from
# files' path
FILES=tutorials/*.rst

# convert the files
for f in $FILES
do
base=$(basename $f)
fname="${base%.*}"
echo "Converting $f..."
sh rst2html.sh $f $TARGETDIR/$fname.html

echo "Converting $f and moving results..."
sh rst2html.sh $f $IPYNBDIR/$fname.ipynb $HTMLDIR/$fname.html
#echo "sh rst2html.sh $f $IPYNBDIR/$fname.ipynb $HTMLDIR/$fname.html"
done

# copy assets next to htmls
echo "Copying assets/ to target directory"
cp -r assets/ $TARGETDIR/assets/
echo "Copying assets/ to html directory"

# copy assets/ dir to HTMLDIR/ -- but don't delete if they're the same
if [ -d "$HTMLDIR/assets" ]; then
ASSETS_ABSPATH_REAL=`cd "./assets/"; pwd`
ASSETS_ABSPATH_TARGET=`cd "$HTMLDIR/assets"; pwd`

if [ $ASSETS_ABSPATH_REAL -ne $ASSETS_ABSPATH_TARGET ]; then
if [ -d "$HTMLDIR/assets" ]; then
rm -rf $HTMLDIR/assets
fi

cp -r assets/ $HTMLDIR/assets/
fi
fi
44 changes: 28 additions & 16 deletions docs/rst2html.sh
Expand Up @@ -3,38 +3,50 @@
# Creates HTML that includes webgl visualization
#
# Input: file.rst
# Output: file.html
# Output: file.ipynb and file.html
# Tools required:
# - pandoc
# - notedown
# - ipython

# example: rst2html.sh file.rst file.html
# example: rst2html.sh file.rst file.ipynb file.html

INPUTFILE=$(basename $1)
INPUTDIR=$(dirname $1)
FILE="${INPUTFILE%.*}"
OUTPUT=$2
FILENAME="${INPUTFILE%.*}"

# if output file not provided
if [ -z "$OUTPUT" ]; then
OUTPUT=$INPUTDIR/$FILE.html
OUTPUT_IPYNB=$2
OUTPUT_HTML=$3

# if html output file not provided
if [ -z "$OUTPUT_HTML" ]; then
OUTPUT_HTML=$INPUTDIR/$FILENAME.html
fi

# if ipynb output not provided
if [ -z "$OUTPUT_IPYNB" ]; then
OUTPUT_IPYNB=$INPUTDIR/$FILENAME.ipynb
fi

OUTPUTDIR=$(dirname $OUTPUT)
# check output dirs
OUTPUTDIR_IPYNB=$(dirname $OUTPUT_IPYNB)
OUTPUTDIR_HTML=$(dirname $OUTPUT_HTML)
if [ ! -d "$OUTPUTDIR_IPYNB" ]; then
mkdir -p $OUTPUTDIR_IPYNB
fi
if [ ! -d "$OUTPUTDIR_HTML" ]; then
mkdir -p $OUTPUTDIR_HTML
fi

# convert RST to temp MD
pandoc -i $1 -o $FILE.md
pandoc -i $1 -o $FILENAME.md

echo "Converting $INPUTFILE to $OUTPUT_IPYNB"
# convert temp MD to IPYNB
notedown $FILE.md > $FILE.ipynb
notedown $FILENAME.md > $OUTPUT_IPYNB

# delete temp MD
rm $FILE.md
rm $FILENAME.md

# convert ipynb to html with custom template
ipython nbconvert --to html --template ./tpl/mbuild_ipynb_template.tpl $FILE.ipynb --output $OUTPUT
mv $FILE.ipynb $OUTPUTDIR/

# don't delete temp ipynb
#rm $FILE.ipynb
ipython nbconvert --to html --template ./tpl/mbuild_ipynb_template.tpl $OUTPUT_IPYNB --output $OUTPUT_HTML

0 comments on commit f58970d

Please sign in to comment.