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 792 by douglas, 2006-06-01T23:55:43-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include "Jargon.hpp"
8 <
9 < Jargon::Jargon(const ext::String& path, bool include) : include(include)
10 < {
11 <        std::vector<std::string> args(1, FeepingCreaturism::program);
7 > #include <cxx/standard.hh>
8  
9 <        args.push_back(path);
14 <        args.push_back("jargon.xsl");
9 > #include <api/pcre/regex.hpp>
10  
11 <        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 < }
11 > #include "Jargon.hpp"
12  
13 < void Jargon::display(ios::PrintWriter& pout, xml::TextWriter& xhtml) const
13 > Jargon::Jargon(const cse::String &path, const cse::String &jargon, bool include, const cse::String &relative) : include(include)
14   {
15 <        {
16 <                xml::ScopeElement p(xhtml, "p");
17 <                
18 <                xhtml.OpenElement("strong");
19 <                xhtml.OutputText(word + ":");
20 <                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);
40 <        }
15 >        args.InsertLast(_B("--stringparam"));
16 >        args.InsertLast(_B("jargon"));
17 >        args.InsertLast(jargon);
18 >        args.InsertLast(_B("--param"));
19 >        args.InsertLast(("include"));
20 >        args.InsertLast(_S<ios::String>() << include << _B("()"));
21  
22 <        for (xml::NodeSet::ConstIterator node(definition.Begin());
43 <                node != definition.End(); ++node)
22 >        if (!relative.IsEmpty())
23          {
24 <                xml::ScopeElement p(xhtml, "p");
25 <
26 <                xhtml.OutputText(**node);
24 >                args.InsertLast(_B("--stringparam"));
25 >                args.InsertLast(_B("relative"));
26 >                args.InsertLast(relative);
27          }
49 }
28  
29 < struct Section
30 < {
31 <        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 < };
29 >        args.InsertLast(_B("jargon.xsl"));
30 >        args.InsertLast(_S<ios::String>() << path << _B("/") << jargon);
31 > }
32  
33 < ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon)
33 > ios::PrintWriter &operator<<(ios::PrintWriter &output, const Jargon &jargon)
34   {
35 <        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");
35 >        _S<api::Process> xslt(_B("/usr/local/bin/xsltproc"), jargon.args);
36  
37 <        xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
77 <
78 <        {
79 <                xml::ScopeElement head(xhtml, "head");
80 <
81 <                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 <        }
37 >        if (jargon.include) ios::ReadLine(*xslt.GetReader());
38  
39 +        if (jargon.include)
40          {
41 <                xml::ScopeElement body(xhtml, "body");
42 <                
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 <                }
41 >                ext::Buffer line;
42 >                api::Pcre::RegEx matcher(_B("^(.*) xmlns=\"http://www.w3.org/1999/xhtml\"(.*)$"));
43  
44 +                while (ios::ReadLine(*xslt.GetReader(), line))
45                  {
46 <                        xml::ScopeElement div(xhtml, "div");
47 <
166 <                        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>";
46 >                        while (api::Pcre::RegEx::Match match = matcher(line))
47 >                                line = _S<ios::Buffer>() << match[1] << match[2];
48  
49 <                        xhtml.CloseElement();
49 >                        output << line << ios::NewLine;
50                  }
51          }
52 +        else
53 +                ios::ReadToWrite(*xslt.GetReader(), output);
54  
55 <        return pout;
55 >        return output;
56   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines