Setting tag myplc-5.3-5
[myplc.git] / docbook2drupal.sh
1 #!/bin/bash
2
3 # quick and dirty - might break anytime if docbook html output changes
4 function docbook_html_to_drupal () {
5     title=$1; shift
6     html=$1; shift
7     php=$1; shift
8
9     mkdir -p $(dirname $php)
10     if [ ! -f $html ] ; then
11         cat << __header_no_doc__ > $php
12 <?php
13 require_once 'plc_drupal.php';
14 drupal_set_title("$title - unavailable");
15 ?>
16 <p class='plc-warning'> Build-time error - could not locate documentation $html</p>
17 __header_no_doc__
18     else
19         # insert header, makes sure we have a trailing eol
20         (cat << __header_doc__ ; cat $html ) > $php
21 <?php
22 require_once 'plc_drupal.php';
23 drupal_set_title("$title");
24 ?>
25 __header_doc__
26         # ignore ed return status
27         set +e
28         # cuts off around the <body> </body>
29         # preserves the 4 first lines that we just added as a header
30         ed -s $php << __ed_script__
31 /BODY/
32 />/
33 s,><,<,
34 5,-d
35 $
36 ?/BODY?
37 s,><.*,>,
38 +
39 ;d
40 w
41 q
42 __ed_script__
43         set -e
44     fi
45 }   
46
47 docbook_html_to_drupal "$@"