Forked from michaelweinberg/gist:ea28b202f5fcf7b859f9
Last active
August 29, 2015 14:22
-
-
Save thomaswilburn/88547673c448815a9bdf to your computer and use it in GitHub Desktop.
This file contains hidden or 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); | |
reply.view("book-list", { | |
title: "Books", | |
//don't re-parse the data, just pass in the objetc | |
books: list.books | |
}); | |
}); | |
} | |
}); | |
------------- | |
/*TEMPLATE CODE*/ | |
<ul> | |
{{#each books}} | |
<li><a | |
{{! @key is a preset variable created by the #each helper }} | |
href="books/{{@key}} " | |
class="class-link"> | |
{{! stop using `this`, it's not a good idea and you don't need it}} | |
{{name}}</a></li> | |
{{/each}} | |
</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