Permalink
Browse files

Move gallery files to its own folder (next time use git-mv), add a bi…

…t of serverside rendering via handlebars templating.
  • Loading branch information...
1 parent 43c408f commit b35e716ff15ee325927009892dde34f519de7842 @jzaefferer committed Jan 3, 2012
View
@@ -3,3 +3,4 @@
*.patch
.DS_Store
node_modules/
+.monitor
File renamed without changes.
@@ -12,7 +12,7 @@ SimpleHistory.start(function(url) {
}, 50);
}
} else {
- $("#photo img").attr("src", path + ".jpg");
+ $("#photo img").attr("src", path.replace("/photos", "") + ".jpg");
$("#photo p").text( $("a[href='" + path + "'] p").text() );
}
});
@@ -3,64 +3,64 @@
<head>
<meta charset=utf-8>
<title>Photo Gallery</title>
- <link rel="stylesheet" href="/application.css">
+ <link rel="stylesheet" href="/gallery/gallery.css">
</head>
-<body>
+<body class="{{indexActive}}">
<div id="index">
<ul class="listing">
<li>
- <a href="/2011-09-29-everglades/DSC_1165">
+ <a href="/photos/2011-09-29-everglades/DSC_1165">
<img src="/2011-09-29-everglades/DSC_1165.jpg">
<p>Not a crocodile</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1166">
+ <a href="/photos/2011-09-29-everglades/DSC_1166">
<img src="/2011-09-29-everglades/DSC_1166.jpg">
<p>Another not a crocodile</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1211">
+ <a href="/photos/2011-09-29-everglades/DSC_1211">
<img src="/2011-09-29-everglades/DSC_1211.jpg">
<p>Alligator coming at you</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1217">
+ <a href="/photos/2011-09-29-everglades/DSC_1217">
<img src="/2011-09-29-everglades/DSC_1217.jpg">
<p>Alligator in the wild</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1223">
+ <a href="/photos/2011-09-29-everglades/DSC_1223">
<img src="/2011-09-29-everglades/DSC_1223.jpg">
<p>Alligator with greens</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1218">
+ <a href="/photos/2011-09-29-everglades/DSC_1218">
<img src="/2011-09-29-everglades/DSC_1218.jpg">
<p>Unzoom wild alligator</p>
</a>
</li>
<li>
- <a href="/2011-09-29-everglades/DSC_1221">
+ <a href="/photos/2011-09-29-everglades/DSC_1221">
<img src="/2011-09-29-everglades/DSC_1221.jpg">
<p>Alligator crossing</p>
</a>
</li>
</ul>
</div>
<div id="photo">
- <img>
- <p>...</p>
+ <img src="{{src}}">
+ <p>{{description}}</p>
</div>
<script src="/vendor/viewporter.js"></script>
<script src="/vendor/simple-history.js"></script>
<script src="/vendor/jquery-1.7.1.js"></script>
<script src="/lib/augment-debounce.js"></script>
<script src="/lib/url.js"></script>
- <script src="/application.js"></script>
+ <script src="/gallery/gallery.js"></script>
</body>
</html>
View
@@ -8,7 +8,8 @@
"url": "git@github.com:jzaefferer/pitfalls-examples.git"
},
"dependencies": {
- "connect": "~>1.8.1"
+ "connect": "~>1.8.1",
+ "handlebars": "1.0.2beta"
},
"engines": {
"node": "~>0.6.0"
View
@@ -1,22 +1,34 @@
#!/usr/bin/env node
-var connect = require('connect');
+var connect = require('connect');
+var fs = require('fs');
+var handlebars = require('handlebars');
-var defaultFile = "/index.html";
+var defaultFile = "/gallery/index.html";
var httpPort = 8085;
var httpHost = "localhost";
var staticDir = "app";
var routes = {
home: /^\/$/,
+ photo: /^\/photos\/.+/,
static: /\.(?:js|jpg|png|json|css|ico|html|manifest|mp3|txt)(?:\?.+)?$/,
wildcard: /.*/
};
-function route(app){
+// TODO tell nodemon to restart when this changes
+var homeTemplate = fs.readFileSync('app/gallery/index.html', 'utf8');
+var template = handlebars.compile( homeTemplate );
+
+function route(app) {
+ app.get(routes.photo, function(request, response, next) {
+ // TODO lookup description from same datasource as client
+ // also use that to generate list of images on index
+ response.end(template({indexActive: "", src: request.url.replace("/photos", "") + ".jpg", description: "..."}));
+ });
app.get(routes.home, function(request, response, next) {
- request.url = defaultFile;
- next();
+ response.end(template({indexActive: "indexActive"}));
});
+ // TODO drop wildcard
app.get(routes.wildcard, function(request, response, next) {
if (!routes.static.test(request.url)) {
request.url = defaultFile;
@@ -27,7 +39,7 @@ function route(app){
connect.createServer(
connect.router(route),
- connect.logger(),
+ //connect.logger(),
connect.static(staticDir)
).listen(httpPort, httpHost, function() {
console.log('HTTP Server running at http://%s:%d', httpHost, httpPort);

0 comments on commit b35e716

Please sign in to comment.