aboutsummaryrefslogtreecommitdiffstats
path: root/src/asciideck_to_manpage.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-10-31 17:49:49 +0200
committerLoïc Hoguin <[email protected]>2016-10-31 18:12:10 +0200
commite466d925f69eb145b6576be6a2b7603bb8d0f9b4 (patch)
treee2827a4fd01d470d70e358d972dd21640a163290 /src/asciideck_to_manpage.erl
parentb534d457c3813c4c2d905a04f6183e7317d66720 (diff)
downloadasciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.tar.gz
asciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.tar.bz2
asciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.zip
Add compress and outdir options to man translator
Diffstat (limited to 'src/asciideck_to_manpage.erl')
-rw-r--r--src/asciideck_to_manpage.erl25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/asciideck_to_manpage.erl b/src/asciideck_to_manpage.erl
index 4158b4d..eafd275 100644
--- a/src/asciideck_to_manpage.erl
+++ b/src/asciideck_to_manpage.erl
@@ -12,26 +12,37 @@
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+%% The Groff documentation section 4.1 has a pretty good
+%% description of the format expected for man pages.
-module(asciideck_to_manpage).
--export([translate/1]).
+-export([translate/2]).
-translate(AST) ->
- Output = man(AST),
- file:write_file("/tmp/man.3.gz", zlib:gzip(Output)),
- ok.
+translate(AST, Opts) ->
+ {Man, Section, Output0} = man(AST),
+ {CompressExt, Output} = case Opts of
+ #{compress := gzip} -> {".gz", zlib:gzip(Output0)};
+ _ -> {"", Output0}
+ end,
+ case Opts of
+ #{outdir := Path} ->
+ file:write_file(binary_to_list(iolist_to_binary(
+ [Path, "/", Man, ".", Section, CompressExt])), Output);
+ _ ->
+ Output
+ end.
man([{title, #{level := 0}, Title0, _Ann}|AST]) ->
[Title, << Section:1/binary, _/bits >>] = binary:split(Title0, <<"(">>),
Extra1 = "2016-10-17", %% @todo
Extra2 = "Project 1.0", %% @todo
Extra3 = "Project Function Reference", %% @todo
- [
+ {Title, Section, [
".TH \"", Title, "\" \"", Section, "\" \"",
Extra1, "\" \"", Extra2, "\" \"", Extra3, "\"\n"
".ta T 4n\n\\&\n",
man(AST, [])
- ].
+ ]}.
man([], Acc) ->
lists:reverse(Acc);