--- FeepingCreaturism/Jargon.cpp 2004/09/06 05:45:32 221 +++ FeepingCreaturism/Jargon.cpp 2004/09/06 09:13:51 224 @@ -5,217 +5,34 @@ // $Id$ #include "Jargon.hpp" +#include "Matcher.hpp" -Jargon::Jargon(const ext::String& path, bool include) : include(include) +Jargon::Jargon(const ext::String& path, bool include) { std::vector args(1, FeepingCreaturism::program); + args.push_back("-p"); + args.push_back("include"); + args.push_back(lexical_cast(include) + "()"); args.push_back(path); args.push_back("jargon.xsl"); - redi::pstreambuf pin("/usr/local/bin/Xalan", args, std::ios_base::in); - ios::FromStreamBuf adaptor(pin); - - ext::Handle document(xml::Parse(adaptor)); - ext::Handle jargon(*document/"jargon"); - - word = *jargon/"word"; - pronunciation = *jargon/"pronunciation"; - grammar = *jargon/"grammar"; - definition = *jargon/"definition"/"p"; -} + redi::ipstream pin("/usr/local/bin/Xalan", args); -void Jargon::display(ios::PrintWriter& pout, xml::TextWriter& xhtml) const -{ + if (include) { - xml::ScopeElement p(xhtml, "p"); - - xhtml.OpenElement("strong"); - xhtml.OutputText(word + ":"); - xhtml.CloseElement(); - - if (!pronunciation.IsEmpty()) xhtml.OutputText(" " + pronunciation); - if (!pronunciation.IsEmpty() && !grammar.IsEmpty()) xhtml.OutputText(","); - if (!grammar.IsEmpty()) xhtml.OutputText(" " + grammar); - } - - definition.WriteTo(xhtml); -} - -struct Section -{ - Section(const ext::String& name, const ext::String& path, - const ext::String& subdomain = "www") : name(name), url("http://" - + subdomain + ".douglasthrift.net" + path) {} - ext::String name, url; -}; - -ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon) -{ - if (jargon.include) - { - xml::TextWriter xhtml(pout, false); - - jargon.display(pout, xhtml); + std::string ignore; - return pout; - } - - pout << "\n"; - - xml::TextWriter xhtml(pout, false); - xml::ScopeElement html(xhtml, "html"); - - xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml"); - - { - xml::ScopeElement head(xhtml, "head"); - - xhtml.OpenElement("title"); - xhtml.OutputText("Douglas Thrift"); - - pout << "'"; - - xhtml.OutputText("s Computers Website | Jargon: " + jargon.word); - xhtml.CloseElement(); - xhtml.OpenElement("link"); - xhtml.SetAttribute("rel", "stylesheet"); - xhtml.SetAttribute("href", "../../stylesheets/regular.css"); - xhtml.SetAttribute("type", "text/css"); - xhtml.CloseElement(); - xhtml.OpenElement("link"); - xhtml.SetAttribute("rel", "Icon"); - xhtml.SetAttribute("href", "../../favicon.ico"); - xhtml.SetAttribute("type", "image/ico"); - xhtml.CloseElement(); - xhtml.OpenElement("script"); - xhtml.SetAttribute("src", "../../nav/functions.js"); - xhtml.SetAttribute("type", "text/javascript"); - xhtml.OutputText(""); - xhtml.CloseElement(); + std::getline(pin, ignore); } + do { - xml::ScopeElement body(xhtml, "body"); - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", Section("", "/", "computers").url); - xhtml.OpenElement("img"); - xhtml.SetAttribute("src", "../../masthead.png"); - xhtml.SetAttribute("alt", "Douglas Thrift's Computers Website"); - xhtml.SetAttribute("title", "Douglas Thrift's Computers Website"); - xhtml.CloseElement(); - xhtml.CloseElement(); - xhtml.CloseElement(); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center nav"); - - std::vector
sections; - - sections.push_back(Section("Home", "/")); - sections.push_back(Section("Blog", "/blog/")); - sections.push_back(Section("Computers", "/", "computers")); - sections.push_back(Section("Movies", "/", "movies")); - sections.push_back(Section("Music", "/", "music")); - sections.push_back(Section("TV Shows", "/", "tvshows")); - sections.push_back(Section("Sitemap", "/sitemap.xml")); - sections.push_back(Section("Contact", "/contact.php")); - sections.push_back(Section("Linking", "/linking.xml")); - sections.push_back(Section("Search", "/search.cgi")); - - for (std::vector
::size_type index(0); - index < sections.size(); ++index) - { - if (index > 0) xhtml.OutputText(" | "); - - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", sections[index].url); - - if (index != 2) - { - xhtml.SetAttribute("onmouseout", "deselect(" - + lexical_cast(index + 1) + ")"); - xhtml.SetAttribute("onmouseover", "select(" - + lexical_cast(index + 1) + ")"); - xhtml.SetAttribute("class", "nav"); - } - else xhtml.SetAttribute("class", "nav select"); - - xhtml.OutputText(sections[index].name); - xhtml.CloseElement(); - } - - xhtml.CloseElement(); - } - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.SetAttribute("class", "hr"); - xhtml.OpenElement("h1"); - xhtml.SetAttribute("id", "title"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText("Jargon: " + jargon.word); - xhtml.CloseElement(); - } - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.SetAttribute("class", "hr"); - jargon.display(pout, xhtml); - } - - { - xml::ScopeElement div(xhtml, "div"); - - xhtml.SetAttribute("class", "hr"); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText("Copyright "); pout << "©"; // XXX hmm? - xhtml.OutputText(" 2002-2004, "); - xhtml.OpenElement("a"); - xhtml.SetAttribute("href", Section("", "/contact.php").url); - xhtml.OutputText("Douglas Thrift"); - xhtml.CloseElement(); - xhtml.OutputText(". All Rights Reserved."); - xhtml.CloseElement(); - xhtml.OpenElement("p"); - xhtml.SetAttribute("class", "center"); - xhtml.OutputText(""); - - pout << ""; - - { - xml::ScopeElement img(xhtml, "img"); - - xhtml.SetAttribute("src", "../../w3c_images/vxh10.png"); - xhtml.SetAttribute("alt", "Valid XHTML 1.0!"); - xhtml.SetAttribute("title", "Valid XHTML 1.0!"); - } - - pout << " "; - - { - xml::ScopeElement img(xhtml, "img"); - - xhtml.SetAttribute("src", "../../w3c_images/vcss.png"); - xhtml.SetAttribute("alt", "Valid CSS!"); - xhtml.SetAttribute("title", "Valid CSS!"); - } + std::string line; - pout << ""; + std::getline(pin, line); - xhtml.CloseElement(); - } + buffer << line << '\n'; } - - return pout; + while (pin.good()); }