diff options
author | Loïc Hoguin <[email protected]> | 2016-10-31 17:49:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-10-31 18:12:10 +0200 |
commit | e466d925f69eb145b6576be6a2b7603bb8d0f9b4 (patch) | |
tree | e2827a4fd01d470d70e358d972dd21640a163290 /src | |
parent | b534d457c3813c4c2d905a04f6183e7317d66720 (diff) | |
download | asciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.tar.gz asciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.tar.bz2 asciideck-e466d925f69eb145b6576be6a2b7603bb8d0f9b4.zip |
Add compress and outdir options to man translator
Diffstat (limited to 'src')
-rw-r--r-- | src/asciideck.erl | 6 | ||||
-rw-r--r-- | src/asciideck_to_manpage.erl | 25 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/asciideck.erl b/src/asciideck.erl index cc50a57..749ccec 100644 --- a/src/asciideck.erl +++ b/src/asciideck.erl @@ -20,6 +20,7 @@ -export([parse/2]). -export([to_manpage/1]). +-export([to_manpage/2]). parse_file(Filename) -> parse_file(Filename, #{}). @@ -37,4 +38,7 @@ parse(Data, St) -> parse(iolist_to_binary(Data), St). to_manpage(AST) -> - asciideck_to_manpage:translate(AST). + asciideck_to_manpage:translate(AST, #{}). + +to_manpage(AST, Opts) -> + asciideck_to_manpage:translate(AST, Opts). 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); |