PLearn 0.1
|
forward-declare More...
#include <HTMLHelpCommand.h>
Public Member Functions | |
HTMLHelpCommand () | |
virtual void | run (const vector< string > &args) |
Sole argument should be a filename containing an HTMLHelpConfig object. | |
virtual void | helpIndex (ostream &os, const HTMLHelpConfig *config) |
Generate a top-level index.html in the output stream given the config. | |
virtual void | helpCommands (ostream &os, const HTMLHelpConfig *config) |
Generate list of registered commands. | |
virtual void | helpClasses (ostream &os, const HTMLHelpConfig *config) |
Generate list of registered classes. | |
virtual void | helpOnCommand (const string &theCommand, ostream &os, const HTMLHelpConfig *config) |
Generate documentation for a given command; called by helpCommands. | |
virtual void | helpOnClass (const string &theClass, ostream &os, const HTMLHelpConfig *config) |
Generate documentation for a given class; called by helpClasses. | |
Protected Member Functions | |
virtual void | helpIndex () |
Generate a top-level index.html. | |
virtual void | helpCommands () |
Generate list of registered commands. | |
virtual void | helpClasses () |
Generate list of registered classes. | |
virtual void | helpOnCommand (const string &theCommand) |
Generate documentation for a given command; called by helpCommands. | |
virtual void | helpOnClass (const string &theClass) |
Generate documentation for a given class; called by helpClasses. | |
virtual void | copySnippet (ostream &os, const string &document) |
Copy the document snippet in filename into the ostream. | |
virtual string | quote (string s) const |
Basic HTML quoting of: < > # &. | |
virtual TVec< string > | parent_classes (string s) const |
Return the list of parent classes of a given classname. | |
virtual string | highlight_known_classes (string typestr) const |
Make link to known classes embedded within type name. | |
virtual string | format_free_text (string text) const |
DWIM for free text. | |
virtual string | make_http_hyperlinks (string text) const |
Highlight obvious hyperlinks in text; 'text' should NOT already contain hyperlinks. | |
virtual string | generated_by () const |
Generate a "generated by" remark. | |
virtual string | flagsAndLevelHeading (const string &classname) const |
Generate flags and level heading for class options. | |
Static Protected Attributes | |
static PLearnCommandRegistry | reg_ |
This allows to register the 'HTMLHelpCommand' command in the command registry. | |
Private Attributes | |
PP< HTMLHelpConfig > | config |
forward-declare
Definition at line 61 of file HTMLHelpCommand.h.
PLearn::HTMLHelpCommand::HTMLHelpCommand | ( | ) |
Definition at line 104 of file HTMLHelpCommand.cc.
: PLearnCommand("htmlhelp", "Output HTML-formatted help for PLearn", "This command provides basic HTML formatting for PLearn\n" "commands and classes. The command takes a single argument,\n" "a filename containing an HTMLHelpConfig object giving the\n" "configuration options for HTML generation." ) {}
void PLearn::HTMLHelpCommand::copySnippet | ( | ostream & | os, |
const string & | document | ||
) | [protected, virtual] |
Copy the document snippet in filename into the ostream.
Definition at line 132 of file HTMLHelpCommand.cc.
Referenced by helpClasses(), helpCommands(), helpIndex(), helpOnClass(), and helpOnCommand().
{ ifstream f(document.c_str()); if (f) while (f) { int c = f.get(); if (c > 0) os.put(c); } else PLERROR("HTMLHelpCommand::copySnippet: cannot open file '%s' for reading", document.c_str()); }
string PLearn::HTMLHelpCommand::flagsAndLevelHeading | ( | const string & | classname | ) | const [protected, virtual] |
Generate flags and level heading for class options.
Definition at line 311 of file HTMLHelpCommand.cc.
References PLearn::OptionBase::getCurrentOptionLevel(), PLearn::OptionBase::getLevelToStrMap(), and PLearn::tostring().
Referenced by helpOnClass().
{ string str= "<div class=\"levelnav\">"; /* * Don't display option flags for now str+= "OptionFlags:"; const OptionBase::StrToFlagMap& flag_map= OptionBase::getStrToFlagMap(); for(OptionBase::StrToFlagMap::const_iterator it= flag_map.begin(); it != flag_map.end(); ++it) { str+= "<a href=\"toggle_flag_" + tostring(it->second) + "\">"; str+= it->second & OptionBase::getCurrentFlags() ? "[+]" : "[-]"; str+= it->first + "</a>"; } str+= "<nbsp><nbsp><nbsp><nbsp>"; */ str+= "OptionLevel:"; const OptionBase::LevelToStrMap& lev_map= OptionBase::getLevelToStrMap(); for(OptionBase::LevelToStrMap::const_iterator it= lev_map.begin(); it != lev_map.end(); ++it) { if(it->first == OptionBase::getCurrentOptionLevel()) str+= "<b>" + it->second + "</b>"; else str+= "<a href=\"class_" + classname + ".html?level=" + tostring(it->first) + "\">" + it->second + "</a>"; } str+= "</div>"; return str; }
string PLearn::HTMLHelpCommand::format_free_text | ( | string | text | ) | const [protected, virtual] |
DWIM for free text.
Definition at line 652 of file HTMLHelpCommand.cc.
References make_http_hyperlinks(), and PLearn::removeblanks().
Referenced by helpOnClass(), and helpOnCommand().
{ // sort of DWIM HTML formatting for free-text; cannot use split since it // eats up consecutive delimiters text = removeblanks(text); size_t curpos = 0, curnl = text.find('\n'); bool ul_active = false; bool start_paragraph = false; string finallines; for ( ; curpos != string::npos ; curpos = curnl+(curnl!=string::npos), curnl = text.find('\n', curpos) ) { string curline = text.substr(curpos, curnl-curpos); // step 1: check if the line starts with a '-': if so, start a new <UL> // if not in one, or extend one if so if (removeblanks(curline).substr(0,1) == "-" || removeblanks(curline).substr(0,1) == "*" ) { curline = removeblanks(curline).substr(1); if (! ul_active) curline = "<ul><li>" + curline; else curline = "<li>" + curline; start_paragraph = false; ul_active = true; } // otherwise, a line that starts with some whitespace within a list // just extends the previous <li> :: don't touch it else if (ul_active && (curline == "" || curline.substr(0,1) == " " || curline.substr(0,1) == "\t")) { /* do nothing */ } // otherwise, normal processing else { // any line that is empty or starts with some whitespace gets its own <br> if (removeblanks(curline) == "") { // Don't start new paragraph right away; wait until we // encounter some text that's neither a <ul> or a <pre> start_paragraph = true; curline = ""; } else if (curline[0] == ' ' || curline[0] == '\t') { start_paragraph = false; curline = "<pre>" + curline + "</pre>"; } // if we were processing a list, close it first if (ul_active) { curline = "</ul>" + curline; ul_active = 0; } } if (!curline.empty() && start_paragraph) { finallines += "<p>"; start_paragraph = false; } finallines += curline + "\n"; } // Close any pending open blocks if (ul_active) finallines += "</ul>\n"; // Finally join the lines return make_http_hyperlinks(finallines); }
string PLearn::HTMLHelpCommand::generated_by | ( | ) | const [protected, virtual] |
Generate a "generated by" remark.
Definition at line 748 of file HTMLHelpCommand.cc.
References PLearn::version_string().
Referenced by helpClasses(), helpCommands(), helpIndex(), helpOnClass(), and helpOnCommand().
{ time_t curtime = time(NULL); struct tm *broken_down_time = localtime(&curtime); const int SIZE = 100; char time_buffer[SIZE]; strftime(time_buffer,SIZE,"%Y/%m/%d %H:%M:%S",broken_down_time); return string("<p> </p><address>Generated on " ) + time_buffer + " by " + version_string() + "</address>"; }
void PLearn::HTMLHelpCommand::helpClasses | ( | ostream & | os, |
const HTMLHelpConfig * | config | ||
) | [virtual] |
Generate list of registered classes.
Definition at line 279 of file HTMLHelpCommand.cc.
References copySnippet(), PLearn::endl(), generated_by(), PLearn::OptionBase::getCurrentOptionLevel(), PLearn::HTMLHelpConfig::html_epilog_document, PLearn::HTMLHelpConfig::html_prolog_document, i, PLearn::TypeFactory::instance(), and PLearn::tostring().
{ copySnippet(os, config->html_prolog_document); os << "<div class=\"generaltable\">" << endl << "<h2>Index of Available Classes</h2>" << endl << "<table cellspacing=\"0\" cellpadding=\"0\">" << endl; vector<string> args(1); int i=0; for(TypeMap::const_iterator it = TypeFactory::instance().getTypeMap().begin(), end = TypeFactory::instance().getTypeMap().end() ; it != end ; ++it) { string helpurl = string("class_") + it->first + ".html?level=" + tostring(OptionBase::getCurrentOptionLevel()); string helphtml = "<a href=\"" + helpurl + "\">" + it->first + "</a>"; os << string(" <tr class=\"") + (i++%2 == 0? "even" : "odd") + "\">" << endl << " <td>" + helphtml + "</td>" << endl << " <td>" + it->second.one_line_descr + "</td></tr>" << endl; } os << "</table>" << endl << "</div>" << endl; os << generated_by() << endl; copySnippet(os, config->html_epilog_document); }
void PLearn::HTMLHelpCommand::helpClasses | ( | ) | [protected, virtual] |
Generate list of registered classes.
Definition at line 263 of file HTMLHelpCommand.cc.
References config, helpOnClass(), PLearn::TypeFactory::instance(), and PLASSERT.
Referenced by PLearn::Plide::helpClasses(), and run().
{ PLASSERT( config ); ofstream os((config->output_dir + "/" + "class_index.html").c_str()); helpClasses(os, config); for(TypeMap::const_iterator it = TypeFactory::instance().getTypeMap().begin(), end = TypeFactory::instance().getTypeMap().end() ; it != end ; ++it) { // Generate help for this class helpOnClass(it->first); } }
void PLearn::HTMLHelpCommand::helpCommands | ( | ostream & | os, |
const HTMLHelpConfig * | config | ||
) | [virtual] |
Generate list of registered commands.
< row #1 is header
Definition at line 197 of file HTMLHelpCommand.cc.
References PLearn::PLearnCommandRegistry::commands(), copySnippet(), PLearn::endl(), generated_by(), PLearn::HTMLHelpConfig::html_epilog_document, PLearn::HTMLHelpConfig::html_prolog_document, and i.
{ copySnippet(os, config->html_prolog_document); os << "<div class=\"generaltable\">" << endl << "<h2>Index of Available Commands</h2>" << endl << "<table cellspacing=\"0\" cellpadding=\"0\">" << endl; int i=2; vector<string> args(1); for(PLearnCommandRegistry::command_map::iterator it = PLearnCommandRegistry::commands().begin(), end = PLearnCommandRegistry::commands().end() ; it != end ; ++it, ++i) { string helpurl = string("command_") + it->first + ".html"; string helphtml = "<a href=\"" + helpurl + "\">" + it->first + "</a>"; os << string(" <tr class=\"") + (i%2 == 0? "even" : "odd") + "\">" << endl << " <td>" + helphtml + "</td>" << "<td>" + it->second->description + "</td></tr>" << endl; } os << "</table>" << endl << "</div>" << endl; os << generated_by() << endl; copySnippet(os, config->html_epilog_document); }
void PLearn::HTMLHelpCommand::helpCommands | ( | ) | [protected, virtual] |
Generate list of registered commands.
Definition at line 181 of file HTMLHelpCommand.cc.
References PLearn::PLearnCommandRegistry::commands(), config, helpOnCommand(), and PLASSERT.
Referenced by PLearn::Plide::helpCommands(), and run().
{ PLASSERT( config ); ofstream os((config->output_dir + "/" + "command_index.html").c_str()); helpCommands(os, config); for(PLearnCommandRegistry::command_map::iterator it = PLearnCommandRegistry::commands().begin(), end = PLearnCommandRegistry::commands().end() ; it != end ; ++it) { // Generate help for this command helpOnCommand(it->first); } }
void PLearn::HTMLHelpCommand::helpIndex | ( | ) | [protected, virtual] |
Generate a top-level index.html.
Definition at line 149 of file HTMLHelpCommand.cc.
References config, and PLASSERT.
Referenced by PLearn::Plide::helpIndex(), and run().
{ PLASSERT( config ); ofstream os((config->output_dir + "/" + "index.html").c_str()); helpIndex(os, config); }
void PLearn::HTMLHelpCommand::helpIndex | ( | ostream & | os, |
const HTMLHelpConfig * | config | ||
) | [virtual] |
Generate a top-level index.html in the output stream given the config.
Definition at line 156 of file HTMLHelpCommand.cc.
References copySnippet(), PLearn::endl(), generated_by(), PLearn::HTMLHelpConfig::html_epilog_document, PLearn::HTMLHelpConfig::html_index_document, and PLearn::HTMLHelpConfig::html_prolog_document.
{ copySnippet(os, config->html_prolog_document); if (config->html_index_document.empty()) { os << "<div class=\"cmdname\">" << endl << "Welcome to PLearn User-Level Class and Commands Help" << endl << "</div>" << "<div class=\"cmdhelp\">" << endl << "<ul>" << endl << " <li> <a href=\"class_index.html\">Class Index</a>" << endl << " <li> <a href=\"command_index.html\">Command Index</a>" << endl << "</ul></div>" << endl; } else copySnippet(os, config->html_index_document); os << generated_by() << endl; copySnippet(os, config->html_epilog_document); }
void PLearn::HTMLHelpCommand::helpOnClass | ( | const string & | theClass, |
ostream & | os, | ||
const HTMLHelpConfig * | config | ||
) | [virtual] |
Generate documentation for a given class; called by helpClasses.
Definition at line 350 of file HTMLHelpCommand.cc.
References PLearn::RemoteMethodDoc::argListDoc(), PLearn::RemoteMethodDoc::argListType(), PLearn::RemoteMethodMap::begin(), PLearn::RemoteMethodDoc::bodyDoc(), PLearn::TypeMapEntry::constructor, copySnippet(), PLearn::RemoteTrampoline::documentation(), PLearn::RemoteMethodMap::end(), PLearn::endl(), flagsAndLevelHeading(), format_free_text(), generated_by(), PLearn::OptionBase::getCurrentFlags(), PLearn::OptionBase::getCurrentOptionLevel(), PLearn::TypeFactory::getTypeMap(), highlight_known_classes(), PLearn::HTMLHelpConfig::html_epilog_document, PLearn::HTMLHelpConfig::html_prolog_document, i, PLearn::RemoteMethodMap::inheritedMethods(), PLearn::TypeFactory::instance(), j, PLearn::join(), n, PLearn::TypeMapEntry::one_line_descr, parent_classes(), PLASSERT, PLERROR, quote(), PLearn::removeblanks(), PLearn::RemoteMethodDoc::returnDoc(), PLearn::RemoteMethodDoc::returnType(), PLearn::TVec< T >::size(), and PLearn::tostring().
{ copySnippet(out, config->html_prolog_document); const TypeMap& type_map = TypeFactory::instance().getTypeMap(); TypeMap::const_iterator it = type_map.find(classname); TypeMap::const_iterator itend = type_map.end(); if(it==itend) PLERROR("Object type %s unknown.\n" "Did you #include it, does it call the IMPLEMENT_NAME_AND_DEEPCOPY macro?\n" "and has it indeed been linked with your program?", classname.c_str()); const TypeMapEntry& entry = it->second; Object* obj = 0; out << flagsAndLevelHeading(classname); // Determine list of parent classes and print it out as crumbtrail TVec<string> parents = parent_classes(classname); out << "<div class=\"crumbtrail\">"; for (int i=0, n=parents.size() ; i<n ; ++i) { if (i < n-1) out << "<a href=\"class_" + parents[i] + ".html?level=" + tostring(OptionBase::getCurrentOptionLevel()) + "\">" << parents[i] << "</a> > "; else out << parents[i]; } out << "</div>"; // Output general information out << "<div class=\"classname\">" << quote(classname) << "</div>" << endl << "<div class=\"classdescr\">" << quote(entry.one_line_descr) << "</div>" << endl << "<div class=\"classhelp\">" << highlight_known_classes(format_free_text(quote(entry.multi_line_help))) << "</div>" << endl; if(entry.constructor) // it's an instantiable class obj = (*entry.constructor)(); else out << "<div class=\"classhelp\"><b>Note:</b>" << quote(classname) << " is a base-class with pure virtual methods that cannot be instantiated directly.\n" << "(default values for build options can only be displayed for instantiable classes, \n" << " so you'll only see question marks here.)</div>\n" << endl; // Output list of options out << "<div class=\"generaltable\">" << endl << "<h2>List of All Options</h2>" << endl << "<table cellspacing=\"0\" cellpadding=\"0\">" << endl; OptionList& options = (*entry.getoptionlist_method)(); int index = 0; for( OptionList::iterator olIt = options.begin(); olIt!=options.end(); ++olIt ) { string descr = (*olIt)->description(); string optname = (*olIt)->optionname(); string opttype = (*olIt)->optiontype(); string optlevel = (*olIt)->levelString(); string defclass = ""; string defaultval = "?"; // Determine the flag rendering string flag_string = join((*olIt)->flagStrings(), " | "); if((*olIt)->level() > OptionBase::getCurrentOptionLevel() || 0 == ((*olIt)->flags() & OptionBase::getCurrentFlags())) continue; if(obj) // it's an instantiable class { defaultval = (*olIt)->defaultval(); if(defaultval=="") defaultval = (*olIt)->writeIntoString(obj); defclass = (*olIt)->optionHolderClassName(obj); } out << string(" <tr class=\"") + (index++ % 2 == 0? "even" : "odd") + "\">" << endl << " <td>" << "<div class=\"opttype\">" << highlight_known_classes(quote(opttype)) << "</div>" << endl << " <div class=\"optname\">" << quote(optname) << "</div>" << endl; if (defaultval != "?") out << " <div class=\"optvalue\">= " << quote(defaultval) << "</div>" << endl; out << " <div class=\"opttype\"><i>(" << flag_string << ")</i></div>" << endl; out << " <div class=\"optlevel\"><i>(OptionLevel: " << optlevel << ")</i></div>" << endl; out << " </td>" << endl; if (removeblanks(descr) == "") descr = "(no description)"; out << " <td>" << highlight_known_classes(format_free_text(quote(descr))); if (defclass != "") { out << " <span class=\"fromclass\">" << "(defined by " << highlight_known_classes(defclass) << ")" << "</span>" << endl; } out << " </td>" << endl << " </tr>" << endl; } if (index == 0) out << "<tr><td>This class does not specify any build options.</td></tr>" << endl; out << "</table></div>" << endl; if(obj) delete obj; // Output instantiable derived classes out << "<div class=\"generaltable\">" << endl << "<h2>List of Instantiable Derived Classes</h2>" << endl << "<table cellspacing=\"0\" cellpadding=\"0\">" << endl; index = 0; for(it = type_map.begin(); it!=itend; ++it) { const TypeMapEntry& e = it->second; if(e.constructor && it->first!=classname) { Object* o = (*e.constructor)(); if( (*entry.isa_method)(o) ) { string helpurl = string("class_") + it->first + ".html" + "?level=" + tostring(OptionBase::getCurrentOptionLevel()); out << string(" <tr class=\"") + (index++%2 == 0? "even" : "odd") + "\">" << endl << " <td><a href=\"" << helpurl << "\">" << quote(it->first) << "</a></td><td>" << quote(e.one_line_descr) << " </td>" << " </tr>" << endl; } if(o) delete o; } } if (index == 0) out << "<tr><td>This class does not have instantiable derived classes.</td></tr>" << endl; out << "</table></div>" << endl; // Output remote-callable methods const RemoteMethodMap* rmm = &(*entry.get_remote_methods)(); out << "<div class=\"rmitable\">" << endl << "<h2>List of Remote-Callable Methods</h2>" << endl << "<table cellspacing=\"0\" cellpadding=\"0\">" << endl; index = 0; while (rmm) { RemoteMethodMap::MethodMap::const_iterator rmmIt = rmm->begin(), end = rmm->end(); for ( ; rmmIt != end ; ++rmmIt ) { const string& method_name = rmmIt->first.first; const RemoteTrampoline* t = rmmIt->second; PLASSERT( t ); const RemoteMethodDoc& doc = t->documentation(); // Generate the method signature and argument-list table in HTML form string return_type = highlight_known_classes(quote(doc.returnType())); string args = ""; string arg_table = ""; list<ArgDoc>::const_iterator adit = doc.argListDoc().begin(), adend = doc.argListDoc().end(); list<string>::const_iterator tyit = doc.argListType().begin(), tyend = doc.argListType().end(); int j=0; for ( ; tyit != tyend ; ++tyit) { string arg_type = highlight_known_classes(quote(*tyit)); string arg_name = ""; string arg_doc = "(no documentation)"; if (adit != adend) { arg_name = quote(adit->m_argument_name); arg_doc = highlight_known_classes(format_free_text(adit->m_doc)); ++adit; } if (! args.empty()) args += ", "; args += arg_type + ' ' + arg_name; if (! arg_table.empty()) arg_table += "</tr><tr><td></td>"; string td1_class = (++j % 2 == 0? "argnameeven" : "argnameodd"); string td2_class = ( j % 2 == 0? "argdoceven" : "argdocodd"); arg_table += " <td class=\"" + td1_class + "\">" + arg_type + ' ' + arg_name + "</td>" + " <td class=\"" + td2_class + "\">" + arg_doc + "</td>"; } string tr_class = (index++ == 0? "first" : "others"); out << "<tr class=\"" << tr_class << + + "\">" << endl << "<td colspan=\"3\"><div class=\"rmiprototype\">" << return_type << " <span class=\"rmifuncname\">" << method_name << "</span>" << '(' << args << ')' << "</div>" << endl << "</tr><tr><td></td><td colspan=\"2\">" << doc.bodyDoc() << "</td></tr>" << endl; if (! arg_table.empty()) out << "<tr>" << endl << "<td class=\"rmititle\">Arguments</td>" << endl << arg_table << "</tr>" << endl; string td1_class = (++j % 2 == 0? "argnameeven" : "argnameodd"); string td2_class = ( j % 2 == 0? "argdoceven" : "argdocodd"); if (! doc.returnType().empty() || ! doc.returnDoc().empty()) { string form_ret = highlight_known_classes(format_free_text(doc.returnDoc())); out << "<tr>" << endl << "<td class=\"rmititle\">Returns</td>" << endl << "<td class=\"" + td1_class + "\">" << return_type << "</td>" << "<td class=\"" + td2_class + "\">" << form_ret << "</td>" << endl << "</tr>" << endl; } } // Inspect base classes rmm = rmm->inheritedMethods(); } if (index == 0) out << "<tr><td>This class does not define any remote-callable methods.</td></tr>" << endl; out << "</table></div>" << endl; out << generated_by() << endl; copySnippet(out, config->html_epilog_document); }
void PLearn::HTMLHelpCommand::helpOnClass | ( | const string & | theClass | ) | [protected, virtual] |
Generate documentation for a given class; called by helpClasses.
Definition at line 343 of file HTMLHelpCommand.cc.
References config, and PLASSERT.
Referenced by helpClasses(), and PLearn::Plide::helpOnClass().
{ PLASSERT( config ); ofstream out((config->output_dir + "/class_" + classname + ".html").c_str()); helpOnClass(classname, out, config); }
void PLearn::HTMLHelpCommand::helpOnCommand | ( | const string & | theCommand | ) | [protected, virtual] |
Generate documentation for a given command; called by helpCommands.
Definition at line 229 of file HTMLHelpCommand.cc.
References config, and PLASSERT.
Referenced by helpCommands(), and PLearn::Plide::helpOnCommand().
{ PLASSERT( config ); ofstream os((config->output_dir + "/" + "command_"+theCommand+".html").c_str()); helpOnCommand(theCommand, os, config); }
void PLearn::HTMLHelpCommand::helpOnCommand | ( | const string & | theCommand, |
ostream & | os, | ||
const HTMLHelpConfig * | config | ||
) | [virtual] |
Generate documentation for a given command; called by helpCommands.
Definition at line 236 of file HTMLHelpCommand.cc.
References PLearn::PLearnCommandRegistry::commands(), copySnippet(), PLearn::endl(), format_free_text(), generated_by(), PLearn::HTMLHelpConfig::html_epilog_document, PLearn::HTMLHelpConfig::html_prolog_document, PLERROR, and quote().
{ copySnippet(os, config->html_prolog_document); PLearnCommandRegistry::command_map::iterator it = PLearnCommandRegistry::commands().find(theCommand), end = PLearnCommandRegistry::commands().end(); if (it == end) PLERROR("HTMLHelpCommand::helpOnCommand: no help for command '%s'", theCommand.c_str()); else os << "<div class=\"cmdname\">" << quote(theCommand) << "</div>" << endl << "<div class=\"cmddescr\">" << quote(it->second->description) << "</div>" << endl << "<div class=\"cmdhelp\">" << format_free_text(quote(it->second->helpmsg)) << "</div>" << endl; os << generated_by() << endl; copySnippet(os, config->html_epilog_document); }
string PLearn::HTMLHelpCommand::highlight_known_classes | ( | string | typestr | ) | const [protected, virtual] |
Make link to known classes embedded within type name.
Definition at line 629 of file HTMLHelpCommand.cc.
References PLearn::OptionBase::getCurrentOptionLevel(), PLearn::TypeFactory::getTypeMap(), i, PLearn::TypeFactory::instance(), n, PLearn::split(), and PLearn::tostring().
Referenced by helpOnClass().
{ vector<string> tokens = split(typestr, " \t\n\r<>,.';:\""); set<string> replaced; // Carry out replacements for a given token only once const TypeMap& type_map = TypeFactory::instance().getTypeMap(); vector<string>::size_type n=tokens.size(); for (unsigned int i=0; i<n ; ++i) { TypeMap::const_iterator it = type_map.find(tokens[i]); if (it != type_map.end() && replaced.find(tokens[i]) == replaced.end()) { replaced.insert(tokens[i]); // ensure we only match whole words with the regular expression const boost::regex e("\\<" + tokens[i] + "\\>"); const string repl_str("<a href=\"class_$&.html\\?level=" + tostring(OptionBase::getCurrentOptionLevel()) +"\">$&</a>"); typestr = regex_replace(typestr, e, repl_str, boost::match_default | boost::format_default); } } return typestr; }
string PLearn::HTMLHelpCommand::make_http_hyperlinks | ( | string | text | ) | const [protected, virtual] |
Highlight obvious hyperlinks in text; 'text' should NOT already contain hyperlinks.
Definition at line 725 of file HTMLHelpCommand.cc.
References PLearn::join().
Referenced by format_free_text().
{ // Find elements of the form XYZ://x.y.z/a/b/c and make them into // hyperlink. An issue is to determine when static const char* recognized_protocols[] = { "http://", "https://", "ftp://", "mailto:" }; // for now... static const vector<string> protocols_vector( recognized_protocols, recognized_protocols + sizeof(recognized_protocols) / sizeof(recognized_protocols[0])); // Match everything that starts with the recognized protocol up to the // following whitespace, excluding trailing punctuation if any. // Make sure the URL is NOT enclosed in quotes static const boost::regex e( string("(?!\")") + "(" + "(?:" + join(protocols_vector, "|") + ")" + "\\S+(?:\\w|/)" + ")" + "(?!\")" + "([[:punct:]]*\\s|$)"); const string repl_str("<a href=\"$1\">$1</a>$2"); text = regex_replace(text, e, repl_str, boost::match_default | boost::format_default); return text; }
TVec< string > PLearn::HTMLHelpCommand::parent_classes | ( | string | s | ) | const [protected, virtual] |
Return the list of parent classes of a given classname.
Definition at line 600 of file HTMLHelpCommand.cc.
References PLearn::endl(), PLearn::TVec< T >::find(), PLearn::TypeFactory::getTypeMap(), PLearn::TVec< T >::insert(), PLearn::TypeFactory::instance(), and PLWARNING.
Referenced by helpOnClass().
{ const TypeMap& type_map = TypeFactory::instance().getTypeMap(); TVec<string> parents; while (classname != "") { TypeMap::const_iterator it = type_map.find(classname); if (it == type_map.end()) { PLWARNING("HTMLHelpCommand::parent_classes: cannot find class '%s'", classname.c_str()); static bool printed_parents = false; if (! printed_parents) { MODULE_LOG << "Registered classes are:" << endl; for (TypeMap::const_iterator types_it = type_map.begin(), types_end = type_map.end() ; types_it != types_end ; ++types_it) MODULE_LOG << types_it->first << endl; printed_parents = true; } break; } parents.insert(0,classname); if (classname != it->second.parent_class) // Object is its own parent classname = it->second.parent_class; else break; } return parents; }
string PLearn::HTMLHelpCommand::quote | ( | string | s | ) | const [protected, virtual] |
Basic HTML quoting of: < > # &.
Definition at line 590 of file HTMLHelpCommand.cc.
References PLearn::search_replace().
Referenced by helpOnClass(), and helpOnCommand().
{ search_replace(s, "&", "&"); search_replace(s, "<", "<"); search_replace(s, ">", ">"); search_replace(s, "\"", """); return s; }
void PLearn::HTMLHelpCommand::run | ( | const vector< string > & | args | ) | [virtual] |
Sole argument should be a filename containing an HTMLHelpConfig object.
The actual implementation of the 'HTMLHelpCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 114 of file HTMLHelpCommand.cc.
References config, PLearn::endl(), helpClasses(), helpCommands(), helpIndex(), PLearn::PLearnCommand::helpmsg, PLearn::macroLoadObject(), and PLERROR.
{ if (args.size() != 1) { cout << helpmsg << endl; } const string& fname = args[0]; config = dynamic_cast<HTMLHelpConfig*>(macroLoadObject(fname)); if (!config) PLERROR("HTMLHelpCommand::run: the file '%s' must contain an " "object of type HTMLHelpConfig", fname.c_str()); helpCommands(); helpClasses(); helpIndex(); }
PP<HTMLHelpConfig> PLearn::HTMLHelpCommand::config [private] |
Definition at line 63 of file HTMLHelpCommand.h.
Referenced by helpClasses(), helpCommands(), helpIndex(), helpOnClass(), helpOnCommand(), and run().
PLearnCommandRegistry PLearn::HTMLHelpCommand::reg_ [static, protected] |
This allows to register the 'HTMLHelpCommand' command in the command registry.
Definition at line 130 of file HTMLHelpCommand.h.