Skip to content

Commit

Permalink
commited working hem module and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Orther committed Apr 2, 2012
1 parent ff239f2 commit 95c7f93
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 43 deletions.
3 changes: 0 additions & 3 deletions examples/css/import.less

This file was deleted.

5 changes: 0 additions & 5 deletions examples/css/index.less

This file was deleted.

4 changes: 4 additions & 0 deletions examples/css/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: black;
color: white;
}
2 changes: 1 addition & 1 deletion examples/html/__footer.eco
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<hr>
<p>Goodbye!</p>
<p>Footer :: Goodbye!</p>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/html/__global.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports =
module.exports =
siteName: 'Example Site'
pageName: null
4 changes: 3 additions & 1 deletion examples/html/__header.eco
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title><%= @title %>- <%= @pageName %></title>
<title><%= @siteName %> - <%= @pageName %></title>
<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="/application.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<h1>siteName = <%= @siteName %></h1>
<h2>pageName = <%= @pageName %></h2>
<a href="/">Home</a>
<a href="/contact.html">Contact</a>
2 changes: 1 addition & 1 deletion examples/html/contact.eco
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%- @render "__header.eco", {pageName: 'Contact'} %>
<p>Conatact me in person.</p>
<p>Conatact me in person or else!</p>
<%- @render "__footer.eco", %>
2 changes: 1 addition & 1 deletion examples/html/index.eco
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%- @render "__header.eco", {pageName: 'Home'} %>
<p>This is the home page boooy!!!!!!!</p>
<p>This is the home page my fine lad.</p>
<%- @render "__footer.eco" %>
2 changes: 0 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"es5-shimify": "~0.0.1",
"json2ify": "~0.0.1",
"jqueryify": "~0.0.1",
"amplifyjsify": "~0.0.3",
"bootstrap-stylus": "0.2.1",
"spine": "~1.0.6"
}
}
10 changes: 6 additions & 4 deletions examples/public/contact.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>- Contact</title>
<title>Example Site - Contact</title>
<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="/application.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<h1>siteName = </h1>
<h1>siteName = Example Site</h1>
<h2>pageName = Contact</h2>
<a href="/">Home</a>
<a href="/contact.html">Contact</a>

<p>Conatact me in person.</p>
<p>Conatact me in person or else!</p>

<hr>
<p>Goodbye!</p>
<p>Footer :: Goodbye!</p>
</body>
</html>
10 changes: 6 additions & 4 deletions examples/public/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>- Home</title>
<title>Example Site - Home</title>
<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="/application.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<h1>siteName = </h1>
<h1>siteName = Example Site</h1>
<h2>pageName = Home</h2>
<a href="/">Home</a>
<a href="/contact.html">Contact</a>

<p>This is the home page boooy!!!!!!!</p>
<p>This is the home page my fine lad.</p>
<hr>
<p>Goodbye!</p>
<p>Footer :: Goodbye!</p>
</body>
</html>

2 changes: 0 additions & 2 deletions examples/slug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var hem = new (require('../lib/hem-render-html'));
var argv = process.argv.slice(2);

//hem.compilers.less = require('hem-render-html').compiler;

hem.exec(argv[0]);
5 changes: 4 additions & 1 deletion lib/hem-render-html.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lib/html.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions lib/render-eco.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@
}

RenderEco.prototype.render = function(templateFile, localContext, includeGlobalContext) {
var context, k, template, v;
var context, k, template, v, _ref;
if (localContext == null) localContext = {};
if (includeGlobalContext == null) includeGlobalContext = false;
if (includeGlobalContext == null) includeGlobalContext = true;
context = {};
if (includeGlobalContext) {
context = this.globalContext;
for (k in localContext) {
v = localContext[k];
_ref = this.globalContext;
for (k in _ref) {
v = _ref[k];
context[k] = v;
}
} else {
context = localContext;
}
for (k in localContext) {
v = localContext[k];
context[k] = v;
}
context['render'] = this.render;
template = fs.readFileSync("" + this.srcPath + "/" + templateFile, 'utf-8');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"dependencies": {
"eco": "1.1.0-rc-3",
"hem": "~0.1.7"
"hem": "~0.1.7",
"watch" : "~0.4.0"
},
"licenses": [{
"type": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/hem-render-html.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ class HemRenderHtml extends Hem
@htmlPackage().compile()

watch: ->
console.log "WATCH HTML"
@watchHtml()
super

watchHtml: ->
@buildHtml()
console.log path.existsSync(@options.html)
dir = path.dirname(@options.html)
dir = @options.html
if path.existsSync(dir)
require('watch').watchTree dir, (file, curr, prev) =>
if curr and (curr.nlink is 0 or +curr.mtime isnt +prev?.mtime)
console.log "#{file} changed. Rebuilding all HTML files."
console.log "#{file} changed. Rebuilding all HTML files."
@buildHtml()

htmlPackage: ->
Expand Down
1 change: 0 additions & 1 deletion src/html.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class HTML
@renderPath = path.resolve(renderPath)
@renderEngine = new RenderEco(@srcPath)
catch e
console.log e

compile: ->
return unless @srcPath and @renderPath
Expand Down
10 changes: 5 additions & 5 deletions src/render-eco.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class RenderEco
delete require.cache[path]
@globalContext = require(path)

render: (templateFile, localContext = {}, includeGlobalContext = no) =>
render: (templateFile, localContext = {}, includeGlobalContext = yes) =>
context = {}
if includeGlobalContext
context = @globalContext
context[k] = v for k, v of localContext
else
context = localContext
context[k] = v for k, v of @globalContext

context[k] = v for k, v of localContext

# add render helper to context
context['render'] = @render
Expand Down

0 comments on commit 95c7f93

Please sign in to comment.