Permalink
Browse files

brought sg up to date with latest emo and r4j

  • Loading branch information...
1 parent 2052825 commit ab596884a3b2c3e1b174a7be068bb566d786535f Frank Carver committed Mar 12, 2012
View
@@ -7,5 +7,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/emo"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/rack4java"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/rack4java-util"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -4,6 +4,6 @@
<body><div id="navbar">
<a href="index.html">Home</a> <b>Contact Us</b>
</div>
-<p>How to contact us</p><hr/><i>Copyright &copy; Frank Carver 2011</i>
+<p>How to contact us</p><hr/><i>Copyright &copy; Frank Carver 2012</i>
</body>
</html>
@@ -44,7 +44,7 @@
<li>Enter <tt>java -jar sitegrinder.jar input output</tt>
<p>A new file <tt>index.html</tt> will appear in the <tt>output</tt> directory. Open the file in a web browser
-to see your new (if minimal) web page with it's hello message.</p>
+to see your new (if minimal) web page with its hello message.</p>
<br/><div class="outfilename">index.html</div>
<div class="outexample">&lt;h1&gt;Hello from Stringtree Site Grinder&lt;/h1&gt;
@@ -81,7 +81,7 @@
<li>"Grind" the web site as above: <tt>java -jar sitegrinder.jar input output</tt>
<p>The file <tt>index.html</tt> will be re-generated, this time it will automatically pick up the common prologue and epilogue.
-Refresh your web browser to see your updated web page with it's page title.</p>
+Refresh your web browser to see your updated web page with its page title.</p>
<br/><div class="outfilename">index.html</div>
<div class="outexample">&lt;html&gt;
@@ -96,6 +96,6 @@
</li>
</ol>
-<hr/><i>Copyright &copy; Frank Carver 2011</i>
+<hr/><i>Copyright &copy; Frank Carver 2012</i>
</body>
</html>
@@ -6,11 +6,11 @@
import java.io.IOException;
import java.io.PrintStream;
-import org.stringtree.Context;
+import org.rack4java.Context;
+import org.rack4java.context.MapContext;
import org.stringtree.SystemContext;
import org.stringtree.Tract;
import org.stringtree.context.ConvertingContext;
-import org.stringtree.context.MapContext;
import org.stringtree.converter.TemplateFileConverter;
import org.stringtree.solomon.Session;
import org.stringtree.solomon.Template;
@@ -76,7 +76,7 @@ public void grind(File srcdir, File destdir) throws IOException {
File classdir = new File(srcdir, "_classes");
if (classdir.isDirectory()) {
- context.put(SystemContext.SYSTEM_CLASSLOADER, new SmartPathClassLoader(classdir.getPath(), getClass().getClassLoader()));
+ context.with(SystemContext.SYSTEM_CLASSLOADER, new SmartPathClassLoader(classdir.getPath(), getClass().getClassLoader()));
}
File spec = new File(srcdir, "_site.spec");
@@ -95,7 +95,7 @@ public void grind(File srcdir, File destdir) throws IOException {
public static Template template(File file, String parent, String type, String body) {
Template template = template(parent, type, file.getName(), body);
- template.put(FILE, file);
+ template.with(FILE, file);
return template;
}
@@ -105,18 +105,18 @@ public static Template template(String parent, String type, String name, String
String key = dot > 0 ? name.substring(0, dot) : name;
if (!StringUtils.isBlank(parent)) key = parent + "/" + key;
- template.put(TYPE, type);
- template.put(NAME, name);
- template.put(PAGE_KEY, key);
- template.put(PARENT, parent);
- if (null != body) template.setBody(body);
+ template.with(TYPE, type);
+ template.with(NAME, name);
+ template.with(PAGE_KEY, key);
+ template.with(PARENT, parent);
+ if (null != body) template.withBody(body);
return template;
}
public static Template folder(File file, String parent) {
Template ret = template(file, parent, TYPE_FOLDER, file.getName());
- ret.setBody(file.getName());
+ ret.withBody(file.getName());
return ret;
}
@@ -150,7 +150,7 @@ public void load(File srcdir, MutableTree<Template> pages, String parent, Contex
load(file, child, parent, context);
} else if (name.endsWith(".page")) {
Template template = page(file, parent, context);
- template.put(NAME, key + ".html");
+ template.with(NAME, key + ".html");
child.setValue(template);
} else {
Template template = binary(file, parent);
@@ -2,18 +2,18 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Map;
-import org.stringtree.Context;
+import org.rack4java.Context;
+import org.rack4java.context.FallbackContext;
import org.stringtree.Tract;
-import org.stringtree.context.ContextEntry;
-import org.stringtree.context.FallbackContext;
-import org.stringtree.solomon.Collector;
import org.stringtree.solomon.Session;
import org.stringtree.solomon.Template;
import org.stringtree.solomon.collector.StringBuilderCollector;
import org.stringtree.solomon.tokenstream.TokenSource;
import org.stringtree.solomon.tree.TreeTemplater;
import org.stringtree.tract.MapTract;
+import org.stringtree.util.Collector;
import org.stringtree.util.tree.MutableTree;
import org.stringtree.util.tree.Tree;
@@ -63,10 +63,10 @@ protected boolean visit(Tree<Template> from, MutableTree<Tract> to) {
Tract ret = new MapTract(collector.toString());
String newname = name.replaceAll("\\.page$", ".html");
- for (ContextEntry<String> entry : page) {
- ret.put(entry.getKey(), entry.getObjectValue());
+ for (Map.Entry<String, Object> entry : page) {
+ ret.with(entry.getKey(), entry.getValue());
}
- ret.put(SiteGrinder.NAME, newname);
+ ret.with(SiteGrinder.NAME, newname);
to.setValue(ret);
return true;
}
@@ -1,12 +1,13 @@
package example;
import java.util.Iterator;
+import java.util.Map;
-import org.stringtree.context.ContextEntry;
+import org.rack4java.context.ContextEntry;
import org.stringtree.context.ReadOnlyContext;
import org.stringtree.util.IntegerNumberUtils;
-public class Incrementer extends ReadOnlyContext<Integer> implements Iterator<ContextEntry<Integer>> {
+public class Incrementer extends ReadOnlyContext<Integer> implements Iterator<Map.Entry<String,Object>> {
private int current;
public Incrementer(int start) {
@@ -41,8 +42,8 @@ private Integer nextValue() {
return current++;
}
- @Override public ContextEntry<Integer> next() {
- return new ContextEntry<Integer>("value", nextValue());
+ @Override public Map.Entry<String,Object> next() {
+ return new ContextEntry<Object>("value", nextValue());
}
@Override public boolean hasNext() {
@@ -53,7 +54,7 @@ private Integer nextValue() {
throw new UnsupportedOperationException("can't remove from the set of all integers");
}
- @Override public Iterator<ContextEntry<Integer>> iterator() {
+ @Override public Iterator<Map.Entry<String,Object>> iterator() {
return this;
}
}
@@ -5,9 +5,9 @@
import junit.framework.TestCase;
-import org.stringtree.Context;
+import org.rack4java.Context;
+import org.rack4java.context.MapContext;
import org.stringtree.Tract;
-import org.stringtree.context.MapContext;
import org.stringtree.grinder.SiteGrinder;
import org.stringtree.solomon.Template;
import org.stringtree.util.tree.MutableTree;
@@ -3,12 +3,13 @@
import java.io.File;
import java.io.IOException;
import java.util.Collection;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
import junit.framework.TestCase;
-import org.stringtree.Context;
-import org.stringtree.context.MapContext;
+import org.rack4java.Context;
+import org.rack4java.context.MapContext;
import org.stringtree.grinder.SiteGrinder;
import org.stringtree.solomon.Template;
import org.stringtree.util.tree.MutableTree;
@@ -56,16 +57,15 @@ public void testMixedHierarchy() throws IOException {
assertFalse(pages.isEmpty());
assertEquals("test3", pages.getValue().getBodyAsString());
- Collection<Tree<Template>> children = pages.getChildren();
- assertEquals(2, children.size());
+ Map<String, Tree<Template>> kids = new HashMap<String, Tree<Template>>();
+ for (Tree<Template> child : pages.getChildren()) {
+ kids.put(child.getValue().get(SiteGrinder.TYPE), child);
+ }
+ assertEquals(2, kids.size());
+ assertEquals("products", kids.get("folder").getValue().get(SiteGrinder.NAME));
+ assertEquals("What is this?", kids.get("page").getValue().getBodyAsString());
- Iterator<Tree<Template>> it = children.iterator();
- Tree<Template> c1 = it.next();
- Tree<Template> c2 = it.next();
- assertEquals("products", c2.getValue().get(SiteGrinder.NAME));
- assertEquals("What is this?", c1.getValue().getBodyAsString());
-
- Collection<Tree<Template>> grandchildren = c2.getChildren();
+ Collection<Tree<Template>> grandchildren = kids.get("folder").getChildren();
assertEquals(2, grandchildren.size());
}
}
@@ -28,8 +28,10 @@ public void testProjectWebsite() throws IOException {
public void grind(String base) throws IOException {
File output = new File(base + "output");
- for (File child : output.listFiles()) {
+ if (output.exists()) for (File child : output.listFiles()) {
child.delete();
+ } else {
+ output.mkdirs();
}
SiteGrinder.main(new String[] {base + "input",base + "output"});
}
@@ -2,9 +2,9 @@
import junit.framework.TestCase;
-import org.stringtree.Context;
+import org.rack4java.Context;
+import org.rack4java.context.MapContext;
import org.stringtree.Tract;
-import org.stringtree.context.MapContext;
import org.stringtree.grinder.SiteGrinder;
import org.stringtree.grinder.TemplateTreeTransformVisitor;
import org.stringtree.solomon.Session;
@@ -55,7 +55,7 @@ private Template template(String content, Object... attributes) {
}
public void testSimpleSubstitution() {
- context.put("text", "Frank");
+ context.with("text", "Frank");
Template template = Helper.page("example ${text}");
from.setValue(template);
tttv.enter(from, to);
@@ -64,41 +64,41 @@ public void testSimpleSubstitution() {
public void testTractSubstitution() {
Template template = Helper.page("example ${text}");
- template.put("text", "Frank");
+ template.with("text", "Frank");
from.setValue(template);
tttv.enter(from, to);
assertEquals("example Frank", to.getValue().getBodyAsString());
}
public void testSubTemplate() {
- templates.put("text", new Template("Margaret"));
+ templates.with("text", new Template("Margaret"));
from.setValue(Helper.page("example ${*text}"));
tttv.enter(from, to);
assertEquals("example Margaret", to.getValue().getBodyAsString());
}
public void testSubTract() {
Template template = template("${name}", "name", "Katherine");
- templates.put("text", template);
- context.put("name", "Elizabeth");
+ templates.with("text", template);
+ context.with("name", "Elizabeth");
from.setValue(Helper.page("${name} ${*text} ${name}"));
tttv.enter(from, to);
assertEquals("Elizabeth Katherine Elizabeth", to.getValue().getBodyAsString());
}
public void testHeaderFooter() {
- templates.put(TemplateTreeTransformVisitor.PAGE_PROLOGUE, new Template("Before["));
- templates.put(TemplateTreeTransformVisitor.PAGE_EPILOGUE, new Template("]After"));
+ templates.with(TemplateTreeTransformVisitor.PAGE_PROLOGUE, new Template("Before["));
+ templates.with(TemplateTreeTransformVisitor.PAGE_EPILOGUE, new Template("]After"));
from.setValue(Helper.page("example text"));
tttv.enter(from, to);
assertEquals("Before[example text]After", to.getValue().getBodyAsString());
}
public void testHeaderFooterSubstitution() {
- templates.put(TemplateTreeTransformVisitor.PAGE_PROLOGUE, new Template("(title=${title})"));
+ templates.with(TemplateTreeTransformVisitor.PAGE_PROLOGUE, new Template("(title=${title})"));
Template template = Helper.page("example text");
- template.put("title", "Home");
+ template.with("title", "Home");
from.setValue(template);
tttv.enter(from, to);
assertEquals("(title=Home)example text", to.getValue().getBodyAsString());

0 comments on commit ab59688

Please sign in to comment.