Skip to content

Instantly share code, notes, and snippets.

@michaelweinberg
Last active August 29, 2015 14:22
Show Gist options
  • Save michaelweinberg/ea28b202f5fcf7b859f9 to your computer and use it in GitHub Desktop.
Save michaelweinberg/ea28b202f5fcf7b859f9 to your computer and use it in GitHub Desktop.
/*ROUTE CODE*/
server.route({
method:"GET",
path: "/books",
handler: function(request, reply){
fs.readFile("books.json", "utf8", function(err,data){
var links =[];
var list = JSON.parse(data);
for(key in list.books){
links.push(key);
}
reply.view("book-list", {
title: "Books",
books: links
});
});
}
});
-------------
/*TEMPLATE CODE*/
<ul>
{{#books}}
<li><a
href="books/{{this}} "
class="class-link">
{{#this}}{{name}}{{/this}}</a></li>
{{/books}}
</ul>
-----
/*JSON OBJECT*/
{
"books":{
"old_man_and_the_sea":{
"name":"The Old Man and the Sea",
"pages":"20",
"link":"old-man-and-the-sea",
"author": "Ernest Hemmingway",
"cover": "http://cdn8.openculture.com/wp-content/uploads/2014/07/old-man-and-the-sea-review.jpg"},
"ulysses":{
"name":"Ulysses",
"pages":"like 10 million",
"link":"ulysses",
"author": "James Joyce",
"cover": "http://upload.wikimedia.org/wikipedia/commons/a/ab/JoyceUlysses2.jpg"},
"frankenstein":{
"name":"Frankenstein",
"pages":"250",
"link":"frankenstein",
"author": "Mary Shelley",
"cover": "http://ciervoblanco.club/wp-content/uploads/2014/11/frankenstein-mary-shelley.jpg"},
"lord-jim":{
"name":"Lord Jim",
"pages":"400",
"link":"lord-jim",
"author": "Joseph Conrad",
"cover": "http://www.modernlib.com/authors/cAuthors/Conrad%20images/ConradJim35.big.jpg"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment