-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c8fd60
commit d602719
Showing
21 changed files
with
238 additions
and
106 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package org.jbake.template.model; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.jbake.app.ConfigUtil.Keys; | ||
import org.jbake.app.ContentStore; | ||
import org.jbake.app.Crawler; | ||
import org.jbake.app.DBUtil; | ||
import org.jbake.app.DocumentList; | ||
import org.jbake.template.ModelExtractor; | ||
|
||
|
@@ -16,20 +14,31 @@ | |
* | ||
* This extractor model will list of categories from all published content. | ||
* | ||
* @author Manik MAgar <[email protected]> | ||
* @author Manik Magar <[email protected]> | ||
* | ||
*/ | ||
public class AllCategoriesExtractor implements ModelExtractor<Set<String>> { | ||
public class AllCategoriesExtractor implements ModelExtractor<DocumentList> { | ||
|
||
@Override | ||
public Set<String> get(ContentStore db, Map model, String key) { | ||
DocumentList query = db.getAllCategoriesFromPublishedPosts(); | ||
Set<String> result = new HashSet<String>(); | ||
for (Map<String, Object> document : query) { | ||
String[] categories = DBUtil.toStringArray(document.get(Crawler.Attributes.CATEGORIES)); | ||
Collections.addAll(result, categories); | ||
} | ||
return result; | ||
public DocumentList get(ContentStore db, Map model, String key) { | ||
DocumentList dl = new DocumentList(); | ||
Map<String, Object> config = (Map<String, Object>) model.get("config"); | ||
|
||
String categoryPath = config.get(Keys.CATEGORY_PATH.replace(".", "_")).toString(); | ||
|
||
for (String category : db.getCategories()){ | ||
Map<String, Object> newCategory = new HashMap<String, Object>(); | ||
String tagName = category; | ||
newCategory.put("name",tagName); | ||
|
||
String uri = categoryPath + File.separator + category + config.get(Keys.OUTPUT_EXTENSION.replace(".", "_")).toString(); | ||
|
||
newCategory.put("uri", uri); | ||
newCategory.put("posts", db.getPublishedPostsByCategories(category)); | ||
newCategory.put("documents", db.getPublishedDocumentsByCategory(category)); | ||
dl.push(newCategory); | ||
} | ||
return dl; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/jbake/template/model/CategoryDocumentsExtractor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jbake.template.model; | ||
|
||
import java.util.Map; | ||
|
||
import org.jbake.app.ContentStore; | ||
import org.jbake.app.Crawler; | ||
import org.jbake.app.DocumentList; | ||
import org.jbake.template.ModelExtractor; | ||
|
||
|
||
public class CategoryDocumentsExtractor implements ModelExtractor<DocumentList> { | ||
|
||
@Override | ||
public DocumentList get(ContentStore db, Map model, String key) { | ||
String category = null; | ||
if (model.get(Crawler.Attributes.CATEGORY) != null) { | ||
category = model.get(Crawler.Attributes.CATEGORY).toString(); | ||
} | ||
DocumentList query = db.getPublishedDocumentsByCategory(category); | ||
return query; | ||
} | ||
|
||
} |
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
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
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
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
7 changes: 5 additions & 2 deletions
7
src/test/java/org/jbake/app/template/JadeTemplateEngineRenderingTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package org.jbake.app.template; | ||
|
||
import java.util.Arrays; | ||
|
||
public class JadeTemplateEngineRenderingTest extends AbstractTemplateEngineRenderingTest { | ||
|
||
public JadeTemplateEngineRenderingTest() { | ||
super("jadeTemplates", "jade"); | ||
} | ||
|
||
@Override | ||
public void renderCategories() throws Exception { | ||
|
||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
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
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
src/test/resources/fixture/groovyMarkupTemplates/categories-index.tpl
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fixture.groovyMarkupTemplates | ||
|
||
layout 'layout/main.tpl', | ||
bodyContents: contents { | ||
div(class:"row-fluid marketing"){ | ||
div(class:"span12"){ | ||
h1("Category List") | ||
div{ | ||
categories.each { cat -> | ||
a(href:"${cat.uri}","${cat.name}") | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
hr() | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/resources/fixture/groovyMarkupTemplates/category.tpl
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fixture.groovyMarkupTemplates | ||
|
||
layout 'layout/main.tpl', | ||
bodyContents: contents { | ||
div(class:"row-fluid marketing"){ | ||
div(class:"span12"){ | ||
h2('Category') | ||
def last_month | ||
category_posts.each { post -> | ||
if (last_month) { | ||
if (post.date.format("MMMM yyyy") != last_month) { | ||
h3("${post.date.format("MMMM yyyy")}") | ||
} | ||
} | ||
else { | ||
h3("${post.date.format("MMMM yyyy")}") | ||
} | ||
|
||
h4 { | ||
yield "${post.date.format("dd MMMM")} - " | ||
a(href:"${post.uri}","${post.title}") | ||
} | ||
last_month = post.date.format("MMMM yyyy") | ||
} | ||
} | ||
} | ||
|
||
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
File renamed without changes.
Oops, something went wrong.