Skip to content

Commit

Permalink
Fixed param passing to partials, styled up examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Feb 12, 2011
1 parent d50db62 commit 8e873c1
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 33 deletions.
13 changes: 5 additions & 8 deletions examples/layouts/default
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<html>
<head>
<title>Default Layout</title>
<title>{title}</title>
<link rel="stylesheet" href="styles/default.css" type="text/css"/>
<script type="text/javascript" src="scripts/default.js"></script>
</head>
<body>
{fn.include('header')}
<div>
{foreach page in params.pages}
<a href="{page}.html">{page}</a> -
{end}
<div id="doc">
{include('header')}
{body}
{include('footer')}
</div>
{body}
{fn.include('footer')}
</body>
</html>
5 changes: 0 additions & 5 deletions examples/pages/books.html

This file was deleted.

4 changes: 0 additions & 4 deletions examples/pages/books/list.html

This file was deleted.

4 changes: 0 additions & 4 deletions examples/pages/books/reference/encyclopedia.html

This file was deleted.

2 changes: 2 additions & 0 deletions examples/pages/cars/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="stylesheet" href="styles/cars.css" type="text/css"/>
TODO cars list here
1 change: 1 addition & 0 deletions examples/pages/cars/original/original.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO original AE86 here
1 change: 1 addition & 0 deletions examples/pages/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO contact here
7 changes: 4 additions & 3 deletions examples/pages/home.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<h1>Home Page</h1>
<h2>Home</h2>
<p>
I'm Home Page.
Hi,<br/>
We're AE86 specialist based in Melbourne, Australia.
</p>
<script type="text/javascript">
write('OHAI');
write('Speedstar Racing');
</script>
4 changes: 3 additions & 1 deletion examples/params.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exports.params = {
pages: [ 'home', 'books', 'books/list', 'books/reference/encyclopedia' ]
title: 'AE86 Workshop',
pages: [ 'Home', 'Cars', 'Original', 'Contact' ],
pageLinks: [ 'home.html', 'cars/list.html', 'cars/original/original.html', 'contact.html' ]
};
2 changes: 1 addition & 1 deletion examples/partials/footer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div id="footer">
<p>Copyright &copy; 2011 Footer Partial</p>
<p>Copyright &copy; 2010 - 2011 AE86 Workshop</p>
</div>
8 changes: 6 additions & 2 deletions examples/partials/header
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<div id="header">
<h1>Header Partial</h1>
<img src="images/logo.png"/>
<h1><img src="images/logo.png"/> {title}</h1>
</div>
<div id="nav">
{foreach page in pages}
<a href="{page}.html">{page}</a> -
{end}
</div>
Binary file modified examples/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
35 changes: 34 additions & 1 deletion examples/static/styles/default.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
body {
background-color: #666666;
margin: 0;
padding: 0;
}
div#doc {
background-color: #ffffff;
color: #000000;
font-family: serif;
margin: auto;
padding: 20px;
width: 960px;
}
div#header {
border-bottom: 3px solid #000000;
text-align: center;
}
div#nav {
font-weight: bold;
padding: 10px;
text-align: center;
}
div#footer {
border-top: 3px solid #000000;
font-weight: bold;
text-align: right;
}
h1 {
border: 1px solid #0000ff;
font-size: 250%;
}
h2 {
font-style: italic;
}
a {
color: #ff0000;
}
16 changes: 12 additions & 4 deletions lib/engines/jazz.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@ Engine.prototype.prepareFile = function (options, file) {
var data = fs.readFileSync(file, options.encoding);
return jazz.compile(data);
};
Engine.prototype._predefined = function (params) {
Engine.prototype._combine = function (objects) {
var combined = {}, i, j;
for (i in objects) {
for (j in objects[i]) {
combined[j] = objects[i][j];
}
}
return combined;
};
Engine.prototype._predefined = function () {
var that = this;
return {
'include': function (file, cb) {
var data = fs.readFileSync(path.join(that.options.partials, file), that.options.encoding);
jazz.compile(data).eval(params, cb);
jazz.compile(data).eval(that._combine([that.options.params, that._predefined()]), cb);
}
};
};
Engine.prototype.merge = function (layout, page, cb) {
var that = this;
page.eval({}, function (data) {
var layoutParams = { fn: that._predefined(layoutParams), body: data, params: that.options.params };
layout.eval(layoutParams, cb);
layout.eval(that._combine([that.options.params, that._predefined(), { body: data }]), cb);
});
};

Expand Down

0 comments on commit 8e873c1

Please sign in to comment.