diff options
author | 2009-11-12 06:38:28 +0100 | |
---|---|---|
committer | 2011-02-14 14:24:38 +0000 | |
commit | ab058c01e39001bc66963b054bbd8ad9ea3638c6 (patch) | |
tree | fe3e7ab93aff69ea5aca937c1d510cec467d5140 | |
parent | 2ad523ba2aa17d5834ba413a5161878db1110836 (diff) | |
download | paludis-ab058c01e39001bc66963b054bbd8ad9ea3638c6.tar.gz paludis-ab058c01e39001bc66963b054bbd8ad9ea3638c6.tar.xz |
Args::DocWriter: Add support for asciidoc output
-rw-r--r-- | paludis/args/man.cc | 231 | ||||
-rw-r--r-- | paludis/args/man.hh | 61 |
2 files changed, 292 insertions, 0 deletions
diff --git a/paludis/args/man.cc b/paludis/args/man.cc index d976caf7d..0cf31e119 100644 --- a/paludis/args/man.cc +++ b/paludis/args/man.cc @@ -2,6 +2,7 @@ /* * Copyright (c) 2006, 2007, 2008, 2009, 2010 Ciaran McCreesh + * Copyright (c) 2011 Ingmar Vanhassel * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -203,6 +204,236 @@ DocWriter::~DocWriter() { } +AsciidocWriter::AsciidocWriter(std::ostream & os) : + _os(os) +{ +} + +AsciidocWriter::~AsciidocWriter() +{ +} + +void +AsciidocWriter::heading(const std::string & name, const std::string & section_, const std::string & synopsis) +{ + std::string name_no_spaces(name); + std::replace(name_no_spaces.begin(), name_no_spaces.end(), ' ', '-'); + _os << name_no_spaces << "(" << section_ << ")" << endl; + _os << std::string(name_no_spaces.size() + 3, '=') << endl << endl << endl; + _os << "NAME" << endl; + _os << "----" << endl << endl; + _os << name_no_spaces << " - " << synopsis << endl << endl; +} + +void +AsciidocWriter::start_usage_lines() +{ + _os << "SYNOPSIS" << endl; + _os << "--------" << endl << endl; +} + +void +AsciidocWriter::usage_line(const std::string & name, const std::string & line) +{ + _os << "*" << name << " " << line << "*" << endl << endl; +} + +void +AsciidocWriter::start_description(const std::string & description) +{ + _os << "DESCRIPTION" << endl; + _os << "-----------" << endl; + _os << description << endl; +} + +void +AsciidocWriter::extra_description(const std::string & description) +{ + _os << description << endl << endl; +} + +void +AsciidocWriter::end_description() +{ + _os << endl; +} + +void +AsciidocWriter::start_options(const std::string & s) +{ + std::string upper_s; + std::transform(s.begin(), s.end(), std::back_inserter(upper_s), &::toupper); + _os << upper_s << endl; + _os << std::string(s.size(), char('-')) << endl; +} + +void +AsciidocWriter::start_arg_group(const std::string & name, const std::string & description) +{ + _os << name << endl; + _os << std::string(name.size(), char('~')) << endl; + _os << description << endl << endl; +} + +void +AsciidocWriter::arg_group_item(const char & short_name, const std::string & long_name, + const std::string & negated_long_name, const std::string & description) +{ + _os << "*"; + if (short_name) + _os << "-" << short_name << " , "; + _os << "--" << long_name; + if (! negated_long_name.empty()) + _os << " (" << "--" << negated_long_name << ")"; + _os << "*::" << endl; + _os << " " << description << endl; + _os << endl; +} + +void +AsciidocWriter::start_extra_arg() +{ +} + +void +AsciidocWriter::extra_arg_enum(const AllowedEnumArg & e, const std::string & default_arg) +{ + std::string default_string; + + if (e.long_name() == default_arg) + default_string = " (default)"; + _os << " *" << e.long_name(); + if (e.short_name()) + _os << " (" << std::string(1, e.short_name()) << ")"; + _os << "*;;" << endl; + _os << " " << e.description() << default_string << endl << endl; +} + +void +AsciidocWriter::extra_arg_string_set(const std::string & first, const std::string & second) +{ + _os << first << endl; + _os << second << endl; +} + +void +AsciidocWriter::end_extra_arg() +{ + _os << endl; +} + +void +AsciidocWriter::end_arg_group() +{ + _os << endl; +} + +void +AsciidocWriter::end_options() +{ + _os << endl; +} + +void +AsciidocWriter::start_environment() +{ + _os << "ENVIRONMENT" << endl; + _os << "-----------" << endl; +} + +void +AsciidocWriter::environment_line(const std::string & first, const std::string & second) +{ + _os << first << "::" << endl; + _os << second << endl; +} + +void +AsciidocWriter::end_environment() +{ + _os << endl; +} + +void +AsciidocWriter::start_examples() +{ + _os << "EXAMPLES" << endl; + _os << "--------" << endl; +} + +void +AsciidocWriter::example(const std::string & first, const std::string & second) +{ + _os << first << "::" << endl; + _os << second << endl; +} + +void +AsciidocWriter::end_examples() +{ + _os << endl; +} + +void +AsciidocWriter::start_notes() +{ + _os << "NOTES" << endl; + _os << "-----" << endl; +} + +void +AsciidocWriter::note(const std::string & s) +{ + _os << "* " << s << endl; +} + +void +AsciidocWriter::end_notes() +{ + _os << endl; +} + +void +AsciidocWriter::section(const std::string & title) +{ + _os << title << endl; + _os << std::string(title.size(), '-') << endl; +} + +void +AsciidocWriter::subsection(const std::string & title) +{ + _os << title << endl; + _os << std::string(title.size(), '~') << endl; +} + +void +AsciidocWriter::paragraph(const std::string & text) +{ + _os << text << endl; +} + +void +AsciidocWriter::start_see_alsos() +{ + _os << "SEE ALSO" << endl; + _os << "--------" << endl; +} + +void +AsciidocWriter::see_also(const std::string & page, const int s, const bool) +{ + // FIXME: Bold page + _os << "*" << page << "*(" << s << ")" << endl; +} + +void +AsciidocWriter::end_see_alsos() +{ + _os << endl; +} + + HtmlWriter::HtmlWriter(std::ostream & os) : _os(os) { diff --git a/paludis/args/man.hh b/paludis/args/man.hh index 0305390eb..3ea947a4b 100644 --- a/paludis/args/man.hh +++ b/paludis/args/man.hh @@ -2,6 +2,7 @@ /* * Copyright (c) 2006, 2007, 2009, 2010 Ciaran McCreesh + * Copyright (c) 2011 Ingmar Vanhassel * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General @@ -99,6 +100,66 @@ namespace paludis }; /** + * Create Asciidoc documentation from args classes. + * + * \ingroup grplibpaludisargs + * \nosubgrouping + */ + class PALUDIS_VISIBLE AsciidocWriter : + public DocWriter + { + private: + std::ostream & _os; + + public: + ///\name Basic operations + ///\{ + AsciidocWriter(std::ostream & os); + ~AsciidocWriter(); + ///\} + + void heading(const std::string & name, const std::string & section, + const std::string & synopis); + void start_usage_lines(); + void usage_line(const std::string & name, const std::string & line); + + void start_description(const std::string & description); + void extra_description(const std::string & description); + void end_description(); + + void start_options(const std::string & s); + void start_arg_group(const std::string & name, const std::string & description); + void arg_group_item(const char & short_name, const std::string & long_name, + const std::string & negated_long_name, const std::string & description); + void start_extra_arg(); + void extra_arg_enum(const AllowedEnumArg &, const std::string & default_arg); + void extra_arg_string_set(const std::string & first, const std::string & second); + void end_extra_arg(); + void end_arg_group(); + void end_options(); + + void start_environment(); + void environment_line(const std::string & first, const std::string & second); + void end_environment(); + + void start_examples(); + void example(const std::string &, const std::string &); + void end_examples(); + + void start_notes(); + void note(const std::string &); + void end_notes(); + + void section(const std::string & title); + void subsection(const std::string & title); + void paragraph(const std::string & text); + + void start_see_alsos(); + void see_also(const std::string &, const int, const bool first); + void end_see_alsos(); + }; + + /** * Create HTML documentation from args classes. * * \ingroup grplibpaludisargs |