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 203 by Douglas Thrift, 2004-09-01T02:10:19-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 <        ext::Handle<xml::Document> document(xml::Parse(adaptor));
19 <        ext::Handle<xml::Node> jargon(*document/"jargon");
20 <
21 <        word = *jargon/"word";
22 <        pronunciation = *jargon/"pronunciation";
23 <        grammar = *jargon/"grammar";
24 <        definition = *jargon/"definition";
25 < }
11 > #include "Jargon.hpp"
12  
13 < struct Section
13 > Jargon::Jargon(const cse::String &path, const cse::String &jargon, bool include, const cse::String &relative) : include(include)
14   {
15 <        Section(const ext::String& name, const ext::String& path,
16 <                const ext::String& subdomain = "www") : name(name), url("http://"
17 <                + subdomain + ".douglasthrift.net" + path) {}
18 <        ext::String name, url;
19 < };
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 < ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon)
36 < {
37 <        if (jargon.include)
22 >        if (!relative.IsEmpty())
23          {
24 <                //
25 <
26 <                return pout;
24 >                args.InsertLast(_B("--stringparam"));
25 >                args.InsertLast(_B("relative"));
26 >                args.InsertLast(relative);
27          }
28  
29 <        xml::TextWriter xhtml(pout);
30 <
31 <        pout << "\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
47 <                << "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
48 <
49 <        xml::ScopeElement html(xhtml, "html");
50 <
51 <        xhtml.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
29 >        args.InsertLast(_B("jargon.xsl"));
30 >        args.InsertLast(_S<ios::String>() << path << _B("/") << jargon);
31 > }
32  
33 <        {
34 <                xml::ScopeElement head(xhtml, "head");
33 > ios::PrintWriter &operator<<(ios::PrintWriter &output, const Jargon &jargon)
34 > {
35 >        _S<api::Process> xslt(_B("/usr/local/bin/xsltproc"), jargon.args);
36  
37 <                xhtml.OpenElement("title");
57 <                xhtml.OutputText("Douglas Thrift's Computers Website | Jargon: \""
58 <                        + jargon.word + "\"");
59 <                xhtml.CloseElement();
60 <                xhtml.OpenElement("link");
61 <                xhtml.SetAttribute("rel", "stylesheet");
62 <                xhtml.SetAttribute("href", "../../stylesheets/regular.css");
63 <                xhtml.SetAttribute("type", "text/css");
64 <                xhtml.CloseElement();
65 <                xhtml.OpenElement("link");
66 <                xhtml.SetAttribute("rel", "Icon");
67 <                xhtml.SetAttribute("href", "../../favicon.ico");
68 <                xhtml.SetAttribute("type", "image/ico");
69 <                xhtml.CloseElement();
70 <                xhtml.OpenElement("script");
71 <                xhtml.SetAttribute("src", "../../nav/functions.js");
72 <                xhtml.SetAttribute("type", "text/javascript");
73 <                xhtml.OutputText("");
74 <                xhtml.CloseElement();
75 <        }
37 >        if (jargon.include) ios::ReadLine(*xslt.GetReader());
38  
39 +        if (jargon.include)
40          {
41 <                xml::ScopeElement body(xhtml, "body");
42 <                
80 <                {
81 <                        xml::ScopeElement div(xhtml, "div");
82 <
83 <                        xhtml.OpenElement("p");
84 <                        xhtml.SetAttribute("class", "center");
85 <                        xhtml.OpenElement("a");
86 <                        xhtml.SetAttribute("href", Section("", "/", "computers").url);
87 <                        xhtml.OpenElement("img");
88 <                        xhtml.SetAttribute("src", "../../masthead.png");
89 <                        xhtml.SetAttribute("alt", "Douglas Thrift's Computers Website");
90 <                        xhtml.SetAttribute("title", "Douglas Thrift's Computers Website");
91 <                        xhtml.CloseElement();
92 <                        xhtml.CloseElement();
93 <                        xhtml.CloseElement();
94 <                        xhtml.OpenElement("p");
95 <                        xhtml.SetAttribute("class", "center nav");
96 <
97 <                        std::vector<Section> sections;
98 <
99 <                        sections.push_back(Section("Home", "/"));
100 <                        sections.push_back(Section("Blog", "/blog/"));
101 <                        sections.push_back(Section("Computers", "/", "computers"));
102 <                        sections.push_back(Section("Movies", "/", "movies"));
103 <                        sections.push_back(Section("Music", "/", "music"));
104 <                        sections.push_back(Section("TV Shows", "/", "tvshows"));
105 <                        sections.push_back(Section("Sitemap", "/sitemap.xml"));
106 <                        sections.push_back(Section("Contact", "/contact.php"));
107 <                        sections.push_back(Section("Linking", "/linking.xml"));
108 <                        sections.push_back(Section("Search", "/search.cgi"));
109 <
110 <                        for (std::vector<Section>::size_type index(0);
111 <                                index < sections.size(); ++index)
112 <                        {
113 <                                if (index > 0) xhtml.OutputText(" | ");
114 <
115 <                                xhtml.OpenElement("a");
116 <                                xhtml.SetAttribute("href", sections[index].url);
117 <
118 <                                if (index != 2)
119 <                                {
120 <                                        xhtml.SetAttribute("onmouseout", "deselect("
121 <                                                + lexical_cast<ext::String>(index + 1) + ")");
122 <                                        xhtml.SetAttribute("onmouseover", "select("
123 <                                                + lexical_cast<ext::String>(index + 1) + ")");
124 <                                        xhtml.SetAttribute("class", "nav");
125 <                                }
126 <                                else xhtml.SetAttribute("class", "nav select");
127 <
128 <                                xhtml.OutputText(sections[index].name);
129 <                                xhtml.CloseElement();
130 <                        }
131 <
132 <                        xhtml.CloseElement();
133 <                }
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 <
138 <                        xhtml.SetAttribute("class", "hr");
139 <                        xhtml.OpenElement("h1");
140 <                        xhtml.SetAttribute("id", "title");
141 <                        xhtml.SetAttribute("class", "center");
142 <                        xhtml.OutputText("Jargon: \"" + jargon.word + "\"");
143 <                        xhtml.CloseElement();
144 <                }
145 <
146 <                {
147 <                        xml::ScopeElement div(xhtml, "div");
148 <
149 <                        xhtml.SetAttribute("class", "hr");
150 <                }
151 <
152 <                {
153 <                        xml::ScopeElement div(xhtml, "div");
154 <
155 <                        xhtml.SetAttribute("class", "hr");
156 <                        xhtml.OpenElement("p");
157 <                        xhtml.SetAttribute("class", "center");
158 <                        xhtml.OutputText("Copyright "); pout << "&copy;"; // XXX hmm?
159 <                        xhtml.OutputText(" 2002-2004, ");
160 <                        xhtml.OpenElement("a");
161 <                        xhtml.SetAttribute("href", Section("", "/contact.php").url);
162 <                        xhtml.OutputText("Douglas Thrift");
163 <                        xhtml.CloseElement();
164 <                        xhtml.OutputText(". All Rights Reserved.");
165 <                        xhtml.CloseElement();
166 <                        xhtml.OpenElement("p");
167 <                        xhtml.SetAttribute("class", "center");
168 <                        xhtml.OutputText("");
169 <
170 <                        pout << "<a href=\"http://validator.w3.org/check/referer\">";
171 <
172 <                        {
173 <                                xml::ScopeElement img(xhtml, "img");
174 <
175 <                                xhtml.SetAttribute("src", "../../w3c_images/vxh10.png");
176 <                                xhtml.SetAttribute("alt", "Valid XHTML 1.0!");
177 <                                xhtml.SetAttribute("title", "Valid XHTML 1.0!");
178 <                        }
179 <
180 <                        pout << "</a> <a href=\"http://jigsaw.w3.org/css-validator/check"
181 <                                << "/referer\">";
182 <
183 <                        {
184 <                                xml::ScopeElement img(xhtml, "img");
185 <
186 <                                xhtml.SetAttribute("src", "../../w3c_images/vcss.png");
187 <                                xhtml.SetAttribute("alt", "Valid CSS!");
188 <                                xhtml.SetAttribute("title", "Valid CSS!");
189 <                        }
190 <
191 <                        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