This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to a JSON api rather html partials. Renaming a few bits and bobs
- Loading branch information
1 parent
3ba5808
commit 4cd9621
Showing
14 changed files
with
124 additions
and
105 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
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,53 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
var pathConfigs = require('../models/path-config.js'); | ||
|
||
function APIController(handlebarsInstance) { | ||
this.handlebarsInstance = handlebarsInstance; | ||
} | ||
|
||
// This method looks at the request path and renders the appropriate handlebars | ||
// template | ||
APIController.prototype.onRequest = function(req, res) { | ||
var urlSections = req.path.split('/'); | ||
urlSections = urlSections.filter(function(sectionString) { | ||
return sectionString.length > 0; | ||
}); | ||
|
||
var urlPath = null; | ||
if (urlSections.length === 1) { | ||
urlPath = '/'; | ||
} else { | ||
urlPath = '/' + urlSections[1]; | ||
} | ||
|
||
var pathConfig = pathConfigs.getConfig(urlPath); | ||
if (!pathConfig) { | ||
res.status(404).send(); | ||
return; | ||
} | ||
|
||
var viewPath = path.join( | ||
__dirname, | ||
'/../views', | ||
pathConfig.data.view + '.handlebars' | ||
); | ||
|
||
this.handlebarsInstance.render(viewPath, pathConfig) | ||
.then(function(renderedTemplate) { | ||
res.json({ | ||
title: pathConfig.data.title, | ||
partialinlinestyles: pathConfig.data.inlineStyles, | ||
partialremotestyles: pathConfig.data.remoteStyles, | ||
partialscripts: pathConfig.data.remoteScripts, | ||
partialhtml: renderedTemplate | ||
}); | ||
}) | ||
.catch(function(err) { | ||
res.status(500).send(); | ||
}); | ||
}; | ||
|
||
module.exports = APIController; |
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
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
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