This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(new FreeMarkerRoute("/article/create") { | |
@Override | |
public Object handle(Request request, Response response) { | |
Map<String, Object> viewObjects = new HashMap<String, Object>(); | |
viewObjects.put("templateName", "articleForm.ftl"); | |
return modelAndView(viewObjects, "layout.ftl"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#if hasNoArticles??> | |
<div class="starter-template"> | |
<h1>${hasNoArticles}</h1> | |
</div> | |
<#else> | |
<div class="starter-template"> | |
<#list articles as article> | |
<h3>${article.getTitle()}</h3> | |
<h4>${article.getCreatedAt()}</h4> | |
<h4>${article.getSummaryLink()}</h4> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Freemarker</title> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css"> | |
<link rel="stylesheet" href="http://getbootstrap.com/examples/starter-template/starter-template.css"> | |
</head> | |
<body> | |
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(new FreeMarkerRoute("/") { | |
@Override | |
public ModelAndView handle(Request request, Response response) { | |
Map<String, Object> viewObjects = new HashMap<String, Object>(); | |
if(HelloSpark.articles.isEmpty()) { | |
viewObjects.put("hasNoArticles", "Welcome, please click \"Write Article\" to begin."); | |
} else { | |
ArrayList<Article> showArticles = new ArrayList<Article>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Freemarker</title> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css"> | |
<link rel="stylesheet" href="http://getbootstrap.com/examples/starter-template/starter-template.css"> | |
</head> | |
<body> | |
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(new FreeMarkerRoute("/freemarker") { | |
@Override | |
public ModelAndView handle(Request request, Response response) { | |
Map<String, Object> attributes = new HashMap<String, Object>(); | |
attributes.put("blogTitle", "Spark Blog!"); | |
attributes.put("descriptionTitle", "We're using Twitter Bootstrap 3"); | |
attributes.put("descriptionBody1", "Special thanks to Twitter for being so dang awesome and helping us"); | |
attributes.put("descriptionBody2", "No seriously... the web would be so ugly without Bootstrap"); | |
// Place the freemarker template within src/test/resources/spark/template/freemarker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>sparkle</groupId> | |
<artifactId>sparkle</artifactId> | |
<version>1.0-SNAPSHOT</version> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(new Route("/article/delete/:id") { | |
@Override | |
public Object handle(Request request, Response response) { | |
Integer id = Integer.parseInt(request.params(":id")); | |
for(Article article : HelloSpark.articles) { | |
if(id.equals(article.getId())) { | |
article.delete(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post(new Route("/article/update/:id") { | |
@Override | |
public Object handle(Request request, Response response) { | |
String title = request.queryParams("article-title"); | |
String summary = request.queryParams("article-summary"); | |
String content = request.queryParams("article-content"); | |
Integer id = Integer.parseInt(request.queryParams("article-id")); | |
for(Article article : HelloSpark.articles) { | |
if(id.equals(article.getId())) { |