ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FeepingCreaturism/Jargon.cpp
Revision: 213
Committed: 2004-09-04T20:54:02-07:00 (20 years, 9 months ago) by Douglas Thrift
File size: 6182 byte(s)
Log Message:
That's better.

File Contents

# User Rev Content
1 Douglas Thrift 196 // Feeping Creaturism
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Jargon.hpp"
8    
9 Douglas Thrift 203 Jargon::Jargon(const ext::String& path, bool include) : include(include)
10 Douglas Thrift 196 {
11 Douglas Thrift 201 std::vector<std::string> args(1, FeepingCreaturism::program);
12 Douglas Thrift 196
13     args.push_back(path);
14 Douglas Thrift 201 args.push_back("jargon.xsl");
15 Douglas Thrift 196
16     redi::pstreambuf pin("/usr/local/bin/Xalan", args, std::ios_base::in);
17 Douglas Thrift 203 ios::FromStreamBuf adaptor(pin);
18 Douglas Thrift 208
19 Douglas Thrift 196 ext::Handle<xml::Document> document(xml::Parse(adaptor));
20 Douglas Thrift 202 ext::Handle<xml::Node> jargon(*document/"jargon");
21 Douglas Thrift 196
22 Douglas Thrift 202 word = *jargon/"word";
23     pronunciation = *jargon/"pronunciation";
24     grammar = *jargon/"grammar";
25 Douglas Thrift 209 definition = *jargon/"definition"/"p";
26 Douglas Thrift 196 }
27    
28 Douglas Thrift 208 void Jargon::display(ios::PrintWriter& pout, xml::TextWriter& xhtml) const
29     {
30     {
31     xml::ScopeElement p(xhtml, "p");
32    
33     xhtml.OpenElement("strong");
34     xhtml.OutputText(word + ":");
35     xhtml.CloseElement();
36    
37 Douglas Thrift 213 if (!pronunciation.IsEmpty()) xhtml.OutputText(" " + pronunciation);
38     if (!pronunciation.IsEmpty() && !grammar.IsEmpty()) xhtml.OutputText(",");
39     if (!grammar.IsEmpty()) xhtml.OutputText(" " + grammar);
40 Douglas Thrift 208 }
41    
42     for (xml::NodeSet::ConstIterator node(definition.Begin());
43     node != definition.End(); ++node)
44     {
45     xml::ScopeElement p(xhtml, "p");
46    
47 Douglas Thrift 209 xhtml.OutputText(**node);
48 Douglas Thrift 208 }
49     }
50    
51 Douglas Thrift 203 struct Section
52 Douglas Thrift 196 {
53 Douglas Thrift 203 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 Douglas Thrift 196
59 Douglas Thrift 203 ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon)
60     {
61     if (jargon.include)
62     {
63 Douglas Thrift 208 xml::TextWriter xhtml(pout);
64 Douglas Thrift 196
65 Douglas Thrift 208 jargon.display(pout, xhtml);
66    
67 Douglas Thrift 203 return pout;
68     }
69 Douglas Thrift 196
70 Douglas Thrift 207 pout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
71 Douglas Thrift 203 << "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
72    
73 Douglas Thrift 207 xml::TextWriter xhtml(pout);
74 Douglas Thrift 203 xml::ScopeElement html(xhtml, "html");
75    
76     xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
77    
78     {
79     xml::ScopeElement head(xhtml, "head");
80    
81     xhtml.OpenElement("title");
82 Douglas Thrift 208 xhtml.OutputText("Douglas Thrift");
83    
84     pout << "'";
85    
86     xhtml.OutputText("s Computers Website | Jargon: " + jargon.word);
87 Douglas Thrift 203 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     }
104    
105     {
106     xml::ScopeElement body(xhtml, "body");
107    
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     }
162    
163     {
164     xml::ScopeElement div(xhtml, "div");
165    
166     xhtml.SetAttribute("class", "hr");
167     xhtml.OpenElement("h1");
168     xhtml.SetAttribute("id", "title");
169     xhtml.SetAttribute("class", "center");
170 Douglas Thrift 208 xhtml.OutputText("Jargon: " + jargon.word);
171 Douglas Thrift 203 xhtml.CloseElement();
172     }
173    
174     {
175     xml::ScopeElement div(xhtml, "div");
176    
177     xhtml.SetAttribute("class", "hr");
178 Douglas Thrift 208 jargon.display(pout, xhtml);
179 Douglas Thrift 203 }
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();
223     }
224     }
225    
226     return pout;
227 Douglas Thrift 196 }

Properties

Name Value
svn:eol-style native
svn:keywords Id