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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines