Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now rendering pages into master.html and added /templates resource fo…

…r a collection of templates and directives (json)
  • Loading branch information...
commit 2addc97ae6a265e049c5e820f85de4465c8e3566 1 parent df9cf74
@tmpvar authored
View
23 browser/core.js
@@ -0,0 +1,23 @@
+(function($) {
+ var
+ cacheTemplates = function(json) {
+ }
+
+
+ $.ajax({
+ url : '/templates',
+ dataType : 'json',
+ success : function() {
+
+ },
+ error : function(text) {
+ $('.fatalError').show().text('Could not contact template service');
+ }
+ });
+
+
+
+
+}(jQuery));
+
+
View
12 browser/templates.js
@@ -1,12 +0,0 @@
-window.cacheTemplates = function() {
- $.ajax({
- url : '/templates',
- dataType : 'json',
- success : function(data) {
-
- },
- error : function(text) {
-
- }
- });
-};
View
14 server/run.js
@@ -18,9 +18,17 @@ var server = connect.createServer(
connect.bodyDecoder(),
connect.router(function(r) {
r.get('/', templates.renderRoute('index'));
-
- r.get('/templates', function() {
-
+ r.get('/contacts', templates.renderRoute('contact/list'));
+
+ r.get('/templates', function(req, res) {
+ var json = JSON.stringify(renderer.templates, null, ' ');
+
+ res.writeHead(200, {
+ 'Content-type' : 'application/json',
+ 'Content-length' : json.length
+ });
+
+ res.end(json);
});
})
);
View
10 server/templates.js
@@ -8,7 +8,8 @@ var jsdom = require('jsdom').jsdom,
ProcessExternalResources : false,
MutationEvents : false
}
- });
+ }),
+ pageContent = doc.getElementById('page-content');
exports.renderRoute = function(template, directive) {
// Register the incoming template
@@ -20,8 +21,11 @@ exports.renderRoute = function(template, directive) {
{});
return function(req, res) {
- var frag = renderer.render(template),
- html = frag.innerHTML;
+ pageContent.innerHTML = "";
+ pageContent.appendChild(renderer.render(template));
+
+ var html = doc.outerHTML;
+
res.writeHead(200, {
'Content-type' : 'text/html',
View
11 shared/renderer.js
@@ -1,5 +1,4 @@
-
-var templates = {};
+var templates = exports.templates = {};
exports.register = function(name, doc, string, directive) {
var frag = doc.createDocumentFragment();
@@ -7,9 +6,15 @@ exports.register = function(name, doc, string, directive) {
templates[name] = {
string : string,
+ directive : directive,
document : doc,
fragment : frag,
- directive : directive
+ toJSON : function() {
+ return {
+ string : this.string,
+ directive : this.directive
+ }
+ }
};
};
View
2  shared/template/master.html
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="/c/style.css" type="text/css" media="screen" />
</head>
<body>
- <div class="page-content">
+ <div id="page-content">
<!-- Templates are placed here -->
</div>
<script type="text/javascript" src="/c/jquery.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.