Last active
August 29, 2015 14:22
-
-
Save michaelweinberg/ea28b202f5fcf7b859f9 to your computer and use it in GitHub Desktop.
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
/*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