Skip to content

Commit 6b5ce0d

Browse files
committed
Merged default CSS into template.
Made publisher expect a StringTemplate group file rather than a directory when alternative templates are specified.
1 parent 48f31ad commit 6b5ce0d

File tree

4 files changed

+37
-96
lines changed

4 files changed

+37
-96
lines changed

CHANGELOG.txt

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Changes in version 1.2
2828

2929
* Added filter to exclude articles where headlines match a certain regex.
3030

31+
* Upgraded to StringTemplate 4.0.7.
32+
33+
* Templates are now specified by a StringTemplate group file (.stg).
34+
3135

3236
Changes in version 1.1
3337
----------------------

publisher/src/java/main/org/uncommons/zeitgeist/publisher/Publisher.java

+12-36
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.grlea.log.SimpleLogger;
4444
import org.stringtemplate.v4.ST;
4545
import org.stringtemplate.v4.STGroup;
46-
import org.stringtemplate.v4.STGroupDir;
4746
import org.stringtemplate.v4.STGroupFile;
4847
import org.uncommons.zeitgeist.Article;
4948
import org.uncommons.zeitgeist.ArticleFetcher;
@@ -87,11 +86,7 @@ public Publisher()
8786
*/
8887
public Publisher(File templateDir)
8988
{
90-
if (!templateDir.isDirectory())
91-
{
92-
throw new IllegalArgumentException("Template path must be a directory.");
93-
}
94-
this.group = new STGroupDir(templateDir.getAbsolutePath());
89+
this.group = new STGroupFile(templateDir.getAbsolutePath());
9590
}
9691

9792

@@ -117,44 +112,25 @@ public void publish(List<Topic> topics,
117112

118113
// Publish HTML.
119114
ST htmlTemplate = group.getInstanceOf("news");
120-
publishTemplate(topics, title, feedCount, articleCount, htmlTemplate, new File("index.html"));
121-
if (group instanceof STGroupDir)
122-
{
123-
StreamUtils.copyFile(outputDir,
124-
new File(((STGroupDir) group).groupDirName, "zeitgeist.css"), "zeitgeist.css");
125-
}
126-
else
127-
{
128-
StreamUtils.copyClasspathResource(outputDir, "zeitgeist.css", "zeitgeist.css");
129-
}
115+
htmlTemplate.add("topics", topics);
116+
htmlTemplate.add("title", title);
117+
htmlTemplate.add("dateTime", new Date());
118+
htmlTemplate.add("feedCount", feedCount);
119+
htmlTemplate.add("articleCount", articleCount);
120+
publishTemplate(htmlTemplate, new File("index.html"));
130121

131122
if (group.isDefined("snippet"))
132123
{
133124
List<Topic> snippetTopics = topics.subList(0, Math.min(5, topics.size())); // Include no more than 5 topics.
134125
ST syndicateTemplate = group.getInstanceOf("snippet");
135-
publishTemplate(snippetTopics,
136-
title,
137-
feedCount,
138-
articleCount,
139-
syndicateTemplate,
140-
new File("snippet.html"));
126+
syndicateTemplate.add("topics", snippetTopics);
127+
publishTemplate(syndicateTemplate, new File("snippet.html"));
141128
}
142129
}
143130

144131

145-
private void publishTemplate(List<Topic> topics,
146-
String title,
147-
int feedCount,
148-
int articleCount,
149-
ST template,
150-
File outputFile) throws IOException
132+
private void publishTemplate(ST template, File outputFile) throws IOException
151133
{
152-
Date date = new Date();
153-
template.add("topics", topics);
154-
template.add("title", title);
155-
template.add("dateTime", date);
156-
template.add("feedCount", feedCount);
157-
template.add("articleCount", articleCount);
158134
Writer writer = new OutputStreamWriter(new FileOutputStream(outputFile), ENCODING);
159135
try
160136
{
@@ -370,8 +346,8 @@ public static void main(String[] args) throws IOException
370346
Integer.parseInt(properties.getProperty("zeitgeist.minSourcesPerTopic")),
371347
Integer.parseInt(properties.getProperty("zeitgeist.minArticleRelevance"))).getTopics();
372348
LOG.info(topics.size() + " topics identified.");
373-
String templatesDir = properties.getProperty("zeitgeist.templatesDir");
374-
Publisher publisher = templatesDir != null ? new Publisher(new File(templatesDir)) : new Publisher();
349+
String templatesFile = properties.getProperty("zeitgeist.templatesFile");
350+
Publisher publisher = templatesFile != null ? new Publisher(new File(templatesFile)) : new Publisher();
375351
publisher.publish(topics,
376352
properties.getProperty("zeitgeist.title"),
377353
feeds.size(),

publisher/src/java/resources/zeitgeist.css

-58
This file was deleted.

publisher/src/java/resources/zeitgeist.stg

+21-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,26 @@ news(topics, title, dateTime, feedCount, articleCount) ::= <<
4141
<html>
4242
<head>
4343
<title>$title;format="xml-encode"$</title>
44-
<link href="zeitgeist.css" rel="stylesheet" type="text/css" />
44+
<style>
45+
body {font-family: Lucida Sans Unicode, Lucida Grande, sans-serif; font-size: 62.5%; line-height: 2em; margin: 2em;}
46+
a {color: #0077cc; text-decoration: none;}
47+
a:hover {color: #004499;}
48+
a img {border: 0;}
49+
h1 {font-size: 4em; font-family: Palatino Linotype, Palatino, serif; font-weight: bold; margin-top: 0;}
50+
h2 {font-size: 3em; font-family: Palatino Linotype, Palatino, serif; line-height: 1.3333em; margin-bottom: .3333em;}
51+
h2 a {color: #333333; font-variant: small-caps;}
52+
p {font-size: 1.5em; margin-bottom: 1.3333em;}
53+
54+
.datetime {font-size: 1.2em; margin-top: -1.6667em; margin-bottom: 1.6667em;}
55+
.about {color: #666666;}
56+
.topic {clear: both; margin-top: 2em; margin-bottom: 2em;}
57+
.links {display: table-cell; font-size: 1.5em; padding-left: 1em; padding-bottom: .25em;}
58+
.picture {float: left; margin-bottom: 2em; max-width: 200px;}
59+
.picture img {max-width: 100%}
60+
.credit {font-size: 1em;}
61+
.logo {max-height: 30px; max-width: 150px; margin-left: .5em; vertical-align: middle;}
62+
.icon {width: 16px; height: 16px; vertical-align: bottom;}
63+
</style>
4564
</head>
4665
<body>
4766
<h1>$title;format="xml-encode"$</h1>
@@ -57,7 +76,7 @@ news(topics, title, dateTime, feedCount, articleCount) ::= <<
5776
>>
5877

5978

60-
snippet(topics, title, dateTime, feedCount, articleCount) ::= <<
79+
snippet(topics) ::= <<
6180
<div id="snippet">
6281
$first(topics):{topic|
6382
$first(topic.images):picture()$

0 commit comments

Comments
 (0)