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 352 by douglas, 2004-12-17T17:50:49-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Jargon.hpp"
8 + #include "Matcher/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, const ext::String& relative) : include(include)
11   {
12 <        std::vector<std::string> args(1, FeepingCreaturism::program);
12 >        args.InsertLast("--stringparam");
13 >        args.InsertLast("jargon");
14 >        args.InsertLast(jargon);
15 >        args.InsertLast("--param");
16 >        args.InsertLast("include");
17 >        args.InsertLast(ios::String() << include << "()");
18  
19 <        args.push_back(path);
20 <        args.push_back("jargon.xsl");
19 >        if (!relative.IsEmpty())
20 >        {
21 >                args.InsertLast("--stringparam");
22 >                args.InsertLast("relative");
23 >                args.InsertLast(relative);
24 >        }
25  
26 <        redi::pstreambuf pin("/usr/local/bin/Xalan", args, std::ios_base::in);
27 <        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";
26 >        args.InsertLast("jargon.xsl");
27 >        args.InsertLast(ios::String() << path << "/" << jargon);
28   }
29  
27 struct Section
28 {
29        Section(const ext::String& name, const ext::String& path,
30                const ext::String& subdomain = "www") : name(name), url("http://"
31                + subdomain + ".douglasthrift.net" + path) {}
32        ext::String name, url;
33 };
34
30   ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Jargon& jargon)
31   {
32 <        if (jargon.include)
38 <        {
39 <                //
40 <
41 <                return pout;
42 <        }
32 >        _S<api::Process> xslt("/usr/local/bin/xsltproc", jargon.args);
33  
34 <        xml::TextWriter xhtml(pout);
45 <
46 <        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");
52 <
53 <        {
54 <                xml::ScopeElement head(xhtml, "head");
55 <
56 <                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 <        }
34 >        if (jargon.include) ios::ReadLine(*xslt.GetReader());
35  
36 +        if (jargon.include)
37          {
38 <                xml::ScopeElement body(xhtml, "body");
39 <                
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 <                }
38 >                ext::String line;
39 >                Matcher matcher("^(.*) xmlns=\"http://www.w3.org/1999/xhtml\"(.*)$");
40  
41 +                while (ios::ReadLine(*xslt.GetReader(), line))
42                  {
43 <                        xml::ScopeElement div(xhtml, "div");
137 <
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>";
43 >                        while (line == matcher) line = matcher[1] + matcher[2];
44  
45 <                        xhtml.CloseElement();
45 >                        pout << line << ios::NewLine;
46                  }
47          }
48 +        else ios::ReadToWrite(*xslt.GetReader(), pout);
49  
50          return pout;
51   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines