#!/bin/bash

#   eLyXer -- convert LyX source files to HTML output.
#
#   Copyright (C) 2009 Alex Fernández
#
#   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 3 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, see <http://www.gnu.org/licenses/>.

# Alex 20100131: convert all LyX guides

# convert all LyX files in the given directory and its subdirectories

report="\nConversion errors:\n"

function convertall {
for file in "$@"; do
	name=$(dirname "$file")/$(basename "$file" .lyx)
	./elyxer.py --quiet --css ../docs/lyx.css "$name.lyx" "$name.html"
	result=$?
	if [ $result == "0" ]; then echo "$name.lyx OK"; fi
	if [ $result != "0" ]; then
		echo "$name.lyx KO"
		report="$report  conversion of $name.lyx failed\n"
	fi
done
}

echo "Converting all LyX guides in $1"
convertall $1/*.lyx
convertall $1/**/*.lyx
echo -e $report

