diff options
author | Shaun McCance <shaunm@gnome.org> | 2014-02-03 10:27:28 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2014-02-03 10:27:28 -0500 |
commit | a4b1ac7e764d1a0de861592422d5043e051c3688 (patch) | |
tree | ab60373338ea500b953cb93de2fcd5194a00726f /tools | |
parent | 960e74869e67ec49d6c8fc3d12635e8906205172 (diff) | |
download | yelp-tools-a4b1ac7e764d1a0de861592422d5043e051c3688.tar.gz |
yelp-build: Added -p option for fallback path for files
Especially when doing translations, it's common to have only some
of the source files in the current directory, and for the rest to
just live untranslated in another directory. This makes it much
easier to use yelp-build for that case, without manually copying
or linking files first.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/yelp-build.in | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/tools/yelp-build.in b/tools/yelp-build.in index 50f28f5..c245174 100755 --- a/tools/yelp-build.in +++ b/tools/yelp-build.in @@ -117,6 +117,7 @@ yelp_usage_epub () { echo " -c CACHE Use the existing Mallard cache CACHE" echo " -o OUT Output en EPUB file named OUT" echo " -x CUSTOM Import the custom XSLT file CUSTOM" + echo " -p PATHS Extra paths to search for files" ) 1>&2 } yelp_usage_html () { @@ -131,6 +132,7 @@ yelp_usage_html () { echo " -c CACHE Use the existing Mallard cache CACHE" echo " -o OUT Output files in the directory OUT" echo " -x CUSTOM Import the custom XSLT file CUSTOM" + echo " -p PATHS Extra paths to search for files" ) 1>&2 } @@ -139,6 +141,12 @@ if [ $# = 0 ]; then exit 1 fi +yelp_paths_normalize () { + for path in $(echo "$1" | sed -e 's/[: ]/\n/g'); do + (cd "$path" && pwd) + done | tr '\n' ' ' +} + yelp_cache_in () { echo '<cache:cache xmlns:cache="http://projectmallard.org/cache/1.0/"' echo ' xmlns="http://projectmallard.org/1.0/">' @@ -180,7 +188,8 @@ yelp_cache () { yelp_usage_cache exit 1 fi - yelp_cache_in "$@" | xsltproc --xinclude -o "$cache_out" "$xsl_mal_cache" - + yelp_cache_in "$@" | xsltproc --path "$html_paths" \ + --xinclude -o "$cache_out" "$xsl_mal_cache" - } yelp_html_xsl_common () { @@ -260,7 +269,7 @@ yelp_html_db2html () { echo '<xsl:import href="'"$xsl"'"/>' yelp_html_xsl_common echo '</xsl:stylesheet>' - ) | xsltproc --xinclude -o "$html_out"/ - "$xml" + ) | xsltproc --path "$html_paths" --xinclude -o "$html_out"/ - "$xml" # Copy media if [ "x$xmldir" != "x$html_out" ]; then ( @@ -278,11 +287,23 @@ yelp_html_db2html () { echo ' </xsl:for-each>' echo '</xsl:template>' echo '</xsl:stylesheet>' - ) | xsltproc --xinclude - "$xml" | while read media; do + ) | xsltproc --path "$html_paths" --xinclude - "$xml" | while read media; do mfile=`echo "$media" | urldecode` minput="$xmldir/$mfile" moutput="$html_out/$mfile" mkdir_p `dirname "$moutput"` + if [ ! -f "$minput" -a "x$html_paths" != "x" ]; then + if [ $(expr index "$minput" "$(pwd)/") = 1 ]; then + minput_rel=$(expr substr "$minput" \ + $(expr length "$(pwd)//") $(expr length "$minput")) + for path in $html_paths; do + if [ -f "$path/$minput_rel" ]; then + minput="$path/$minput_rel" + break + fi + done + fi + fi cp "$minput" "$moutput" done fi @@ -312,7 +333,7 @@ yelp_html_db2html () { echo ' </xsl:for-each>' echo '</xsl:template>' echo '</xsl:stylesheet>' - ) | xsltproc --xinclude - "$xml" | sort | uniq | while read icon; do + ) | xsltproc --path "$html_paths" --xinclude - "$xml" | sort | uniq | while read icon; do cp "${yelp_icon_dir}/${icon}.png" "$html_out/$html_internal_datadir" done; # Copy jQuery @@ -342,7 +363,7 @@ yelp_html_db2html () { echo ' </xsl:for-each>' echo '</xsl:template>' echo '</xsl:stylesheet>' - ) | xsltproc --xinclude - "$xml" | sort | uniq \ + ) | xsltproc --path "$html_paths" --xinclude - "$xml" | sort | uniq \ | grep '^contents syntax ' | sed -e 's/^contents syntax brush-/brush./' \ | while read js; do cp "${yelp_js_dir}/jquery.syntax.${js}.js" "$html_out/$html_internal_datadir" @@ -393,7 +414,8 @@ yelp_html_mal2html () { echo '</xsl:for-each>' echo '</xsl:template>' echo '</xsl:stylesheet>' - ) | (cd "$html_out" && xsltproc $html_profile --xinclude \ + ) | (cd "$html_out" && xsltproc $html_profile \ + --path "$html_paths" --xinclude \ --stringparam mal.files.copy.icon.dir "$yelp_icon_dir" \ --stringparam mal.files.copy.js.dir "$yelp_js_dir" \ - "$html_tmp_infile") | sort | uniq | \ @@ -407,6 +429,18 @@ yelp_html_mal2html () { else line_dest="$html_out/"`echo "$line" | cut -d' ' -f2` fi + if [ ! -f "$line_src" -a "x$html_paths" != "x" ]; then + if [ $(expr index "$line_src" "$(pwd)/") = 1 ]; then + line_src_rel=$(expr substr "$line_src" \ + $(expr length "$(pwd)//") $(expr length "$line_src")) + for path in $html_paths; do + if [ -f "$path/$line_src_rel" ]; then + line_src="$path/$line_src_rel" + break + fi + done + fi + fi line_dest=`echo "$line_dest" | urldecode` if [ "$line_src" != "$line_dest" ]; then line_dir=`dirname "$line_dest"` @@ -438,6 +472,11 @@ yelp_html () { html_custom="$1" shift ;; + "-p") + shift + html_paths=$(yelp_paths_normalize "$1") + shift + ;; "--profile") html_profile="--profile" shift @@ -489,6 +528,11 @@ yelp_epub () { html_custom="$1" shift ;; + "-p") + shift + html_paths=$(yelp_paths_normalize "$1") + shift + ;; *) break ;; @@ -517,11 +561,13 @@ yelp_epub () { epub_id=`uuidgen` epub_data=`(cd "$html_out" && ls yelp/*.*)` xsltproc \ + --path "$html_paths" \ -o "$html_out/opf.opf" \ --stringparam opf.id "$epub_id" \ --stringparam opf.data "$epub_data" \ "$xsl_mal_opf" "$epub_cache_file" xsltproc \ + --path "$html_paths" \ -o "$html_out/ncx.ncx" \ --stringparam ncx.id "$epub_id" \ "$xsl_mal_ncx" "$epub_cache_file" |