@@ -932,6 +932,71 @@ std::str2array () {
932932declare -xa str2array_ret
933933BLIB_VERSION=' 1.2-5-g84801fd'
934934#! /bin/bash
935+ # mod: main
936+ # txt: The ``main`` module contain the specified potion body.
937+
938+ readonly VERSION=" 2.0.1"
939+
940+ # fun: main::init
941+ # txt: print nice potion logo and some custom messages at the beginning.
942+ main::init () {
943+
944+ out::user " ${COLOR_WARN} , ,${COLOR_NONE} "
945+ out::user " ${COLOR_WARN} /////|${COLOR_NONE} "
946+ out::user " ${COLOR_WARN} ///// |${COLOR_NONE} ${COLOR_INFO} _ _ _ ${COLOR_NONE} "
947+ out::user " ${COLOR_WARN} |~~~| |${COLOR_NONE} ${COLOR_INFO} | |__ __ _ ___| |__ __| | ___ ___ ${COLOR_NONE} "
948+ out::user " ${COLOR_WARN} |===| |${COLOR_NONE} ${COLOR_INFO} | '_ \\ / _\` / __| '_ \\ / _\` |/ _ \\ / __|${COLOR_NONE} "
949+ out::user " ${COLOR_WARN} | | |${COLOR_NONE} ${COLOR_INFO} | |_) | (_| \\ __ \\ | | | (_| | (_) | (__ ${COLOR_NONE} "
950+ out::user " ${COLOR_WARN} | | |${COLOR_NONE} ${COLOR_INFO} |_.__/ \\ __,_|___/_| |_|\\ __,_|\\ ___/ \\ ___|${COLOR_NONE} "
951+ out::user " ${COLOR_WARN} | | /${COLOR_NONE} ${COLOR_USER} version ${VERSION}${COLOR_NONE} "
952+ out::user " ${COLOR_WARN} |===|/${COLOR_NONE} "
953+ out::user " ${COLOR_WARN} '---'${COLOR_NONE} "
954+
955+
956+
957+ }
958+
959+ opt_files=" "
960+ # general options handlers
961+ main::opt_version () { out::info " Bashdoc $VERSION " ; exit 0; }
962+ main::opt_title () { TITLE=" $1 " ; return 2; }
963+ main::opt_author () { AUTHOR=" $1 " ; return 2; }
964+ main::opt_output () { OUTPUT=" $1 " ; return 2; }
965+ main::opt_date () { DATE=" $( date +%Y-%m-%d) " ; return 1; }
966+ main::opt_file () { opt_files=" $opt_files $1 " ; return 2; }
967+ main::opt_api () { API=" $1 " ; return 2; }
968+ main::opt_style () { __opt__style=" $1 " ; echo " $@ " ; return 2; }
969+ main::opt_template () { __opt__template=" $1 " ; return 2; }
970+ main::opt_highlight () { __opt__highlight=" $1 " ; return 2; }
971+
972+ # main function really
973+ main::action () {
974+ main::init
975+ doc::generate " $@ "
976+ }
977+
978+ main () {
979+ arg::opt MAIN -V --version main::opt_version ' show program version number'
980+ arg::opt MAIN -T --title main::opt_title ' set the title of the document'
981+ arg::opt MAIN -a --author main::opt_author ' set the author of the document'
982+ arg::opt MAIN -o --output main::opt_output ' set the output file name'
983+ arg::opt MAIN -d --include-date main::opt_date ' add date to the document'
984+ arg::opt MAIN -f --file main::opt_file ' add more section files'
985+ arg::opt MAIN -A --api main::opt_api ' set api to be documented'
986+ arg::opt MAIN -s --style main::opt_style ' path to CSS stylesheet'
987+ arg::opt MAIN -t --template main::opt_template ' path to HTML template'
988+ arg::opt MAIN -H --highlight-theme main::opt_highlight \
989+ ' theme name to highlight code'
990+
991+ arg::main::help " Generate documentation for bash programs"
992+ arg::main::action main::action
993+
994+ arg::param MAIN " script+" \
995+ ' Path or URL to script to create documentation'
996+
997+ arg::parse " $@ "
998+ }
999+ #! /bin/bash
9351000# mod: doc
9361001# api: bashdoc
9371002# txt: The `doc` module provides functions to convert bash source code to
@@ -1022,15 +1087,23 @@ DOC_CSS='
10221087 font-style: italic;
10231088 }
10241089
1025- .module h2 { margin-bottom:0.2em; margin-top: 2.5em;}
1090+ .module h2 {
1091+ border-bottom:1px solid #444;
1092+ margin:2em 0 1em 0;
1093+ }
10261094 .module h2:before {
10271095 content: "module";
1028- color: #888 ;
1096+ color: #444 ;
10291097 font-family: monospace;
10301098 font-size: 90%;
10311099 padding-right:0.4em;
10321100 }
10331101
1102+ .module h3 {
1103+ border-bottom:1px solid #dadada;
1104+ margin:2em 0 1em 0;
1105+ }
1106+
10341107 .module h3:before {
10351108 content: "function";
10361109 color: #888;
@@ -1160,7 +1233,7 @@ DOCSTRING="${DOCSTRING:-# }"
11601233# use: doc::read_blocks v1 < script
11611234doc::read_blocks ()
11621235{
1163- local block_name=MAIN func_name= key=
1236+ local block_name=MAIN func_name
11641237 local in_opt=false in_env=false in_use=false in_pre=false indent=' '
11651238 __doc__apis=()
11661239 __doc__mods=()
@@ -1177,7 +1250,7 @@ doc::read_blocks ()
11771250 _reset_env () { in_env=false; }
11781251 _reset_use () { in_use=false; }
11791252
1180- while read line; do
1253+ while read -r line; do
11811254 # some minor replacements required for markdown parser
11821255 line=" ${line// </ \< } "
11831256 line=" ${line// >/ \> } "
@@ -1276,6 +1349,7 @@ doc::read_blocks ()
12761349
12771350 _reset_pre
12781351
1352+ declare -a sort_ret=()
12791353 std::sort " ${! __doc__mods[@]} "
12801354
12811355 for x in " ${sort_ret[@]} " ; do
@@ -1315,10 +1389,16 @@ doc::output ()
13151389 done
13161390 for doc in " $@ " ; do
13171391 local docname=" ${doc# ./ } "
1318- for api in ${API// ,/ } ; do
1319- echo " # $api API Reference" && echo
1320- doc::read_blocks " $api " < " $doc "
1321- done
1392+
1393+ if [[ " $API " ]]; then
1394+ for api in ${API// ,/ } ; do
1395+ echo " # $api API Reference" && echo
1396+ doc::read_blocks " $api " < " $doc "
1397+ done
1398+ else
1399+ echo " # API Reference" && echo
1400+ doc::read_blocks " " < " $doc "
1401+ fi
13221402 echo -e " \n---\n"
13231403 done
13241404}
@@ -1355,70 +1435,5 @@ doc::generate ()
13551435 <( echo " $( doc::output " $@ " ) " ) \
13561436 $output
13571437}
1358- #! /bin/bash
1359- # mod: main
1360- # txt: The ``main`` module contain the specified potion body.
1361-
1362- readonly VERSION=" 2.0.1"
1363-
1364- # fun: main::init
1365- # txt: print nice potion logo and some custom messages at the beginning.
1366- main::init () {
1367-
1368- out::user " ${COLOR_WARN} , ,${COLOR_NONE} "
1369- out::user " ${COLOR_WARN} /////|${COLOR_NONE} "
1370- out::user " ${COLOR_WARN} ///// |${COLOR_NONE} ${COLOR_INFO} _ _ _ ${COLOR_NONE} "
1371- out::user " ${COLOR_WARN} |~~~| |${COLOR_NONE} ${COLOR_INFO} | |__ __ _ ___| |__ __| | ___ ___ ${COLOR_NONE} "
1372- out::user " ${COLOR_WARN} |===| |${COLOR_NONE} ${COLOR_INFO} | '_ \\ / _\` / __| '_ \\ / _\` |/ _ \\ / __|${COLOR_NONE} "
1373- out::user " ${COLOR_WARN} | | |${COLOR_NONE} ${COLOR_INFO} | |_) | (_| \\ __ \\ | | | (_| | (_) | (__ ${COLOR_NONE} "
1374- out::user " ${COLOR_WARN} | | |${COLOR_NONE} ${COLOR_INFO} |_.__/ \\ __,_|___/_| |_|\\ __,_|\\ ___/ \\ ___|${COLOR_NONE} "
1375- out::user " ${COLOR_WARN} | | /${COLOR_NONE} ${COLOR_USER} version ${VERSION}${COLOR_NONE} "
1376- out::user " ${COLOR_WARN} |===|/${COLOR_NONE} "
1377- out::user " ${COLOR_WARN} '---'${COLOR_NONE} "
1378-
1379-
1380-
1381- }
1382-
1383- opt_files=" "
1384- # general options handlers
1385- main::opt_version () { out::info " Bashdoc $VERSION " ; exit 0; }
1386- main::opt_title () { TITLE=" $1 " ; return 2; }
1387- main::opt_author () { AUTHOR=" $1 " ; return 2; }
1388- main::opt_output () { OUTPUT=" $1 " ; return 2; }
1389- main::opt_date () { DATE=" $( date +%Y-%m-%d) " ; return 1; }
1390- main::opt_file () { opt_files=" $opt_files $1 " ; return 2; }
1391- main::opt_api () { API=" $1 " ; return 2; }
1392- main::opt_style () { __opt__style=" $1 " ; echo " $@ " ; return 2; }
1393- main::opt_template () { __opt__template=" $1 " ; return 2; }
1394- main::opt_highlight () { __opt__highlight=" $1 " ; return 2; }
1395-
1396- # main function really
1397- main::action () {
1398- main::init
1399- doc::generate " $@ "
1400- }
1401-
1402- main () {
1403- arg::opt MAIN -V --version main::opt_version ' show program version number'
1404- arg::opt MAIN -T --title main::opt_title ' set the title of the document'
1405- arg::opt MAIN -a --author main::opt_author ' set the author of the document'
1406- arg::opt MAIN -o --output main::opt_output ' set the output file name'
1407- arg::opt MAIN -d --include-date main::opt_date ' add date to the document'
1408- arg::opt MAIN -f --file main::opt_file ' add more section files'
1409- arg::opt MAIN -A --api main::opt_api ' set api to be documented'
1410- arg::opt MAIN -s --style main::opt_style ' path to CSS stylesheet'
1411- arg::opt MAIN -t --template main::opt_template ' path to HTML template'
1412- arg::opt MAIN -H --highlight-theme main::opt_highlight \
1413- ' theme name to highlight code'
1414-
1415- arg::main::help " Generate documentation for bash programs"
1416- arg::main::action main::action
1417-
1418- arg::param MAIN " script+" \
1419- ' Path or URL to script to create documentation'
1420-
1421- arg::parse " $@ "
1422- }
14231438std::installed ' pandoc' || err::trace ' pandoc is required but not found'
14241439main " $@ "
0 commit comments