ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FeepingCreaturism/Jargon.cpp
(Generate patch)

Comparing FeepingCreaturism/Jargon.cpp (file contents):
Revision 209 by Douglas Thrift, 2004-09-02T03:41:06-07:00 vs.
Revision 230 by Douglas Thrift, 2004-09-06T20:50:27-07:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Jargon.hpp"
8 + #include "Matcher.hpp"
9  
10 < Jargon::Jargon(const ext::String& path, bool include) : include(include)
10 > Jargon::Jargon(const ext::String& path, const ext::String& jargon, bool include,
11 >        const ext::String& relative) : include(include),
12 >        args(1, FeepingCreaturism::program)
13   {
14 <        std::vector<std::string> args(1, FeepingCreaturism::program);
14 >        args.push_back("-m");
15 >        args.push_back("-p");
16 >        args.push_back("jargon");
17 >        args.push_back("\"" + jargon + "\"");
18 >        args.push_back("-p");
19 >        args.push_back("include");
20 >        args.push_back(lexical_cast<ext::String>(include) + "()");
21  
22 <        args.push_back(path);
14 <        args.push_back("jargon.xsl");
15 <
16 <        redi::pstreambuf pin("/usr/local/bin/Xalan", args, std::ios_base::in);
17 <        ios::FromStreamBuf adaptor(pin);
18 <        
19 <        ext::Handle<xml::Document> document(xml::Parse(adaptor));
20 <        ext::Handle<xml::Node> jargon(*document/"jargon");
21 <
22 <        word = *jargon/"word";
23 <        pronunciation = *jargon/"pronunciation";
24 <        grammar = *jargon/"grammar";
25 <        definition = *jargon/"definition"/"p";
26 < }
27 <
28 < void Jargon::display(ios::PrintWriter& pout, xml::TextWriter& xhtml) const
29 < {
22 >        if (!relative.IsEmpty())
23          {
24 <                xml::ScopeElement p(xhtml, "p");
25 <                
26 <                xhtml.OpenElement("strong");
34 <                xhtml.OutputText(word + ":");
35 <                xhtml.CloseElement();
36 <                xhtml.OutputText(" " + pronunciation);
37 <
38 <                if (!grammar.IsEmpty()) xhtml.OutputText(", " + grammar);
24 >                args.push_back("-p");
25 >                args.push_back("relative");
26 >                args.push_back("\"" + relative + "\"");
27          }
28  
29 <        for (xml::NodeSet::ConstIterator node(definition.Begin());
30 <                node != definition.End(); ++node)
43 <        {
44 <                xml::ScopeElement p(xhtml, "p");
45 <
46 <                xhtml.OutputText(**node);
47 <        }
29 >        args.push_back(path + "/" + jargon);
30 >        args.push_back("jargon.xsl");
31   }
32  
50 struct Section
51 {
52        Section(const ext::String& name, const ext::String& path,
53                const ext::String& subdomain = "www") : name(name), url("http://"
54                + subdomain + ".douglasthrift.net" + path) {}
55        ext::String name, url;
56 };
57
33   ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon)
34   {
35 <        if (jargon.include)
61 <        {
62 <                xml::TextWriter xhtml(pout);
63 <
64 <                jargon.display(pout, xhtml);
65 <
66 <                return pout;
67 <        }
68 <
69 <        pout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
70 <                << "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
71 <
72 <        xml::TextWriter xhtml(pout);
73 <        xml::ScopeElement html(xhtml, "html");
74 <
75 <        xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
35 >        redi::ipstream pin("/usr/local/bin/Xalan", jargon.args);
36  
37 +        if (jargon.include)
38          {
39 <                xml::ScopeElement head(xhtml, "head");
79 <
80 <                xhtml.OpenElement("title");
81 <                xhtml.OutputText("Douglas Thrift");
82 <
83 <                pout << "'";
39 >                std::string ignore;
40  
41 <                xhtml.OutputText("s Computers Website | Jargon: " + jargon.word);
86 <                xhtml.CloseElement();
87 <                xhtml.OpenElement("link");
88 <                xhtml.SetAttribute("rel", "stylesheet");
89 <                xhtml.SetAttribute("href", "../../stylesheets/regular.css");
90 <                xhtml.SetAttribute("type", "text/css");
91 <                xhtml.CloseElement();
92 <                xhtml.OpenElement("link");
93 <                xhtml.SetAttribute("rel", "Icon");
94 <                xhtml.SetAttribute("href", "../../favicon.ico");
95 <                xhtml.SetAttribute("type", "image/ico");
96 <                xhtml.CloseElement();
97 <                xhtml.OpenElement("script");
98 <                xhtml.SetAttribute("src", "../../nav/functions.js");
99 <                xhtml.SetAttribute("type", "text/javascript");
100 <                xhtml.OutputText("");
101 <                xhtml.CloseElement();
41 >                std::getline(pin, ignore);
42          }
43  
44 +        do
45          {
46 <                xml::ScopeElement body(xhtml, "body");
106 <                
107 <                {
108 <                        xml::ScopeElement div(xhtml, "div");
109 <
110 <                        xhtml.OpenElement("p");
111 <                        xhtml.SetAttribute("class", "center");
112 <                        xhtml.OpenElement("a");
113 <                        xhtml.SetAttribute("href", Section("", "/", "computers").url);
114 <                        xhtml.OpenElement("img");
115 <                        xhtml.SetAttribute("src", "../../masthead.png");
116 <                        xhtml.SetAttribute("alt", "Douglas Thrift's Computers Website");
117 <                        xhtml.SetAttribute("title", "Douglas Thrift's Computers Website");
118 <                        xhtml.CloseElement();
119 <                        xhtml.CloseElement();
120 <                        xhtml.CloseElement();
121 <                        xhtml.OpenElement("p");
122 <                        xhtml.SetAttribute("class", "center nav");
123 <
124 <                        std::vector<Section> sections;
125 <
126 <                        sections.push_back(Section("Home", "/"));
127 <                        sections.push_back(Section("Blog", "/blog/"));
128 <                        sections.push_back(Section("Computers", "/", "computers"));
129 <                        sections.push_back(Section("Movies", "/", "movies"));
130 <                        sections.push_back(Section("Music", "/", "music"));
131 <                        sections.push_back(Section("TV Shows", "/", "tvshows"));
132 <                        sections.push_back(Section("Sitemap", "/sitemap.xml"));
133 <                        sections.push_back(Section("Contact", "/contact.php"));
134 <                        sections.push_back(Section("Linking", "/linking.xml"));
135 <                        sections.push_back(Section("Search", "/search.cgi"));
136 <
137 <                        for (std::vector<Section>::size_type index(0);
138 <                                index < sections.size(); ++index)
139 <                        {
140 <                                if (index > 0) xhtml.OutputText(" | ");
141 <
142 <                                xhtml.OpenElement("a");
143 <                                xhtml.SetAttribute("href", sections[index].url);
144 <
145 <                                if (index != 2)
146 <                                {
147 <                                        xhtml.SetAttribute("onmouseout", "deselect("
148 <                                                + lexical_cast<ext::String>(index + 1) + ")");
149 <                                        xhtml.SetAttribute("onmouseover", "select("
150 <                                                + lexical_cast<ext::String>(index + 1) + ")");
151 <                                        xhtml.SetAttribute("class", "nav");
152 <                                }
153 <                                else xhtml.SetAttribute("class", "nav select");
154 <
155 <                                xhtml.OutputText(sections[index].name);
156 <                                xhtml.CloseElement();
157 <                        }
46 >                std::string line;
47  
48 <                        xhtml.CloseElement();
160 <                }
48 >                std::getline(pin, line);
49  
50 +                while (jargon.include && line.find(" xmlns=") != std::string::npos)
51                  {
52 <                        xml::ScopeElement div(xhtml, "div");
52 >                        std::string::size_type position(line.find(" xmlns="));
53  
54 <                        xhtml.SetAttribute("class", "hr");
166 <                        xhtml.OpenElement("h1");
167 <                        xhtml.SetAttribute("id", "title");
168 <                        xhtml.SetAttribute("class", "center");
169 <                        xhtml.OutputText("Jargon: " + jargon.word);
170 <                        xhtml.CloseElement();
54 >                        line.replace(position, 37, "");
55                  }
56  
57 <                {
174 <                        xml::ScopeElement div(xhtml, "div");
175 <
176 <                        xhtml.SetAttribute("class", "hr");
177 <                        jargon.display(pout, xhtml);
178 <                }
179 <
180 <                {
181 <                        xml::ScopeElement div(xhtml, "div");
182 <
183 <                        xhtml.SetAttribute("class", "hr");
184 <                        xhtml.OpenElement("p");
185 <                        xhtml.SetAttribute("class", "center");
186 <                        xhtml.OutputText("Copyright "); pout << "&copy;"; // XXX hmm?
187 <                        xhtml.OutputText(" 2002-2004, ");
188 <                        xhtml.OpenElement("a");
189 <                        xhtml.SetAttribute("href", Section("", "/contact.php").url);
190 <                        xhtml.OutputText("Douglas Thrift");
191 <                        xhtml.CloseElement();
192 <                        xhtml.OutputText(". All Rights Reserved.");
193 <                        xhtml.CloseElement();
194 <                        xhtml.OpenElement("p");
195 <                        xhtml.SetAttribute("class", "center");
196 <                        xhtml.OutputText("");
197 <
198 <                        pout << "<a href=\"http://validator.w3.org/check/referer\">";
199 <
200 <                        {
201 <                                xml::ScopeElement img(xhtml, "img");
202 <
203 <                                xhtml.SetAttribute("src", "../../w3c_images/vxh10.png");
204 <                                xhtml.SetAttribute("alt", "Valid XHTML 1.0!");
205 <                                xhtml.SetAttribute("title", "Valid XHTML 1.0!");
206 <                        }
207 <
208 <                        pout << "</a> <a href=\"http://jigsaw.w3.org/css-validator/check"
209 <                                << "/referer\">";
210 <
211 <                        {
212 <                                xml::ScopeElement img(xhtml, "img");
213 <
214 <                                xhtml.SetAttribute("src", "../../w3c_images/vcss.png");
215 <                                xhtml.SetAttribute("alt", "Valid CSS!");
216 <                                xhtml.SetAttribute("title", "Valid CSS!");
217 <                        }
218 <
219 <                        pout << "</a>";
220 <
221 <                        xhtml.CloseElement();
222 <                }
57 >                pout << line << '\n';
58          }
59 +        while (pin.good());
60  
61          return pout;
62   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines