();
+
+ for (post in posts)
+ {
+ titlesToUrls.set(post.title, post.url);
+ }
+ for (page in pages)
+ {
+ titlesToUrls.set(page.title, page.url);
+ }
+
+ for (title in titlesToUrls.keys())
+ {
+ var titlePlaceholder = new EReg('\\[\\[${title}]]', "i");
+ if (titlePlaceholder.match(toReturn))
+ {
+ var titleLink = '${title}';
+ toReturn = titlePlaceholder.replace(toReturn, titleLink);
+ }
+ else
+ {
+ }
+ }
+ }
+
+ return toReturn;
+ }
}
diff --git a/test/butterfly/generator/HtmlGeneratorTest.hx b/test/butterfly/generator/HtmlGeneratorTest.hx
index 37c4ad2..7180721 100644
--- a/test/butterfly/generator/HtmlGeneratorTest.hx
+++ b/test/butterfly/generator/HtmlGeneratorTest.hx
@@ -47,11 +47,11 @@ class HtmlGeneratorTest
{
var layout = "
\n";
var gen = Factory.createHtmlGenerator(layout);
- var post = new Post();
+ var post = new Post();
post.title = "Regex Replacement in Haxe";
- var actual = gen.generatePostHtml(post, new ButterflyConfig());
- Assert.isTrue(actual.indexOf('${post.title}
') > -1);
+ var actual = gen.generatePostHtml(post, new ButterflyConfig());
+ Assert.isTrue(actual.indexOf('${post.title}
') > -1);
}
@Test
@@ -60,11 +60,11 @@ class HtmlGeneratorTest
{
var layout = "
\n";
var gen = Factory.createHtmlGenerator(layout);
- var post = new Post();
+ var post = new Post();
post.createdOn = Date.now();
- var actual = gen.generatePostHtml(post, new ButterflyConfig());
- Assert.isTrue(actual.indexOf('Posted on ${post.createdOn.format("%Y-%m-%d")}') > -1);
+ var actual = gen.generatePostHtml(post, new ButterflyConfig());
+ Assert.isTrue(actual.indexOf('Posted on ${post.createdOn.format("%Y-%m-%d")}') > -1);
}
@Test
@@ -73,11 +73,11 @@ class HtmlGeneratorTest
var layout = "
\n" +
'Published ';
var gen = Factory.createHtmlGenerator(layout);
- var post = new Post();
- post.createdOn = Date.now();
+ var post = new Post();
+ post.createdOn = Date.now();
- var actual = gen.generatePostHtml(post, new ButterflyConfig());
- Assert.isTrue(actual.indexOf('Crafted on ${post.createdOn.format("%Y-%m-%d")}') > -1);
+ var actual = gen.generatePostHtml(post, new ButterflyConfig());
+ Assert.isTrue(actual.indexOf('
Crafted on ${post.createdOn.format("%Y-%m-%d")}') > -1);
}
@Test
@@ -95,13 +95,31 @@ class HtmlGeneratorTest
@Test
public function generatePostHtmlReplacesCommentTagWithDisqusHtml()
{
- Assert.isTrue(true);
+ var post:Post = makePost("Unicorns", "http://unicorns.com");
+ post.content = "We love unicorns.";
+
+ var actual = new HtmlGenerator("", [post], [])
+ .generatePostHtml(post, new ButterflyConfig());
+
+ // Don't directly read the template, because it contains placeholders
+ // Instead, look for the word "disqus"
+ Assert.isTrue(actual.indexOf("disqus") > -1);
}
@Test
- public function GeneratePostHtmlAppendsPostTitleToHtmlTitleTag()
+ public function generatePostHtmlAppendsPostTitleToHtmlTitleTag()
{
- Assert.isTrue(true);
+ var postTitle:String = "Bananas";
+ var siteTitle:String = "V R Bananas";
+ var post:Post = makePost(postTitle, "http://wearebananas.com");
+ post.content = "We really are bananas. And sell bananas.";
+
+ var actual = new HtmlGenerator('
${siteTitle}', [post], [])
+ .generatePostHtml(post, new ButterflyConfig());
+
+ // Don't directly read the template, because it contains placeholders
+ // Instead, look for the word "disqus"
+ Assert.isTrue(actual.indexOf('${postTitle} | ${siteTitle}') > -1);
}
@Test
@@ -115,15 +133,13 @@ class HtmlGeneratorTest
var content = 'Do not ask [[${page.title}]]; just read this: [[${post.title}]]';
- var generator = new HtmlGenerator("",
- [post], [page]);
-
- var config = new ButterflyConfig();
+ var generator = new HtmlGenerator
+ ("", [post], [page]);
var postWithLinks = new Post();
postWithLinks.content = content;
- var actual = generator.generatePostHtml(postWithLinks, config);
+ var actual = generator.generatePostHtml(postWithLinks, new ButterflyConfig());
Assert.isTrue(actual.indexOf(post.url) > -1);
Assert.isTrue(actual.indexOf(page.url) > -1);
}
@@ -131,25 +147,51 @@ class HtmlGeneratorTest
@Test
public function generatePageHtmlReplacesContentTagWithContent()
{
- Assert.isTrue(true);
+ var page = makePage("Blueberry Smoothies", "Blueberry smoothies are very healthy.");
+
+ var generator = new HtmlGenerator
+ ("Fake.com
", [], [page]);
+
+ var actual = generator.generatePageHtml(page, new ButterflyConfig());
+ Assert.isTrue(actual.indexOf(page.content) > -1);
}
@Test
public function generatePageHtmlReplacesButterflyTitleTagWithTitle()
{
- Assert.isTrue(true);
+ var page = makePage("Raspberry Smoothies", "Raspberry smoothies are very healthy.");
+
+ var generator = new HtmlGenerator
+ ("
", [], [page]);
+
+ var actual = generator.generatePageHtml(page, new ButterflyConfig());
+ Assert.isTrue(actual.indexOf('${page.title}
') > -1);
}
@Test
public function generatePageHtmlReplacesCommentTagWithDisqusHtml()
{
- Assert.isTrue(true);
+ var page = makePage("Strawberry Smoothies", "Strawberry smoothies are very healthy.");
+
+ var generator = new HtmlGenerator
+ ("", [], [page]);
+
+ var actual = generator.generatePageHtml(page, new ButterflyConfig());
+ var divIndex = actual.indexOf("