Skip to content

Instantly share code, notes, and snippets.

@taywils
Created November 10, 2013 21:30
Show Gist options
  • Save taywils/7404222 to your computer and use it in GitHub Desktop.
Save taywils/7404222 to your computer and use it in GitHub Desktop.
spark_blog_step_4_2
get(new Route("/") {
@Override
public Object handle(Request request, Response response) {
String title = "My Blog";
String createArticleLink = "<a href='/article/create'>Write Article</a>";
StringBuilder html = new StringBuilder();
html.append("<h1>").append(title).append("</h1>").append(createArticleLink);
html.append("<hr>");
if(HelloSpark.articles.isEmpty()) {
html.append("<b>No articles have been posted</b>");
} else {
for(Article article : HelloSpark.articles) {
if(article.readable()) {
html.append("Title: ").append(article.getTitle())
.append("<br/>")
.append(article.getCreatedAt())
.append("<br/>")
.append("Summary: ").append(article.getSummaryLink())
.append("<br/>")
.append(article.getEditLink()).append(" | ").append(article.getDeleteLink())
.append("</p>");
}
}
}
return html.toString();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment