Skip to content

Commit 4454f70

Browse files
author
Tracy
committed
Merge pull request #18 from knode/move-to-base
Add base.hbs + wrap.hbs & helpers.
2 parents 56f67f1 + fd71b97 commit 4454f70

17 files changed

+154
-855
lines changed

bin/compile.js

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = compile
22

33
var handlebars = require('handlebars')
44
, marked = require('marked')
5+
, path = require('path')
56
, fs = require('fs')
67

78
var cities = [
@@ -81,29 +82,86 @@ function compile(ready) {
8182
var keys = Object.keys(template_contextfn)
8283
, pending = keys.length
8384

84-
keys.forEach(function(template) {
85-
var outputFile = template.replace('hbs', 'html')
86-
, ctxFn = template_contextfn[template]
87-
, ctx = template_contextfn[template]()
85+
add_helpers(onhelpers)
8886

89-
fs.readFile('templates/' + template, 'utf8', function(err, txt) {
90-
if(err) {
91-
return ready(err)
92-
}
93-
var output = handlebars.compile(txt)(ctx)
87+
function onhelpers(err) {
88+
if(err) {
89+
return ready(err)
90+
}
91+
92+
keys.forEach(function(template) {
93+
var outputFile = template.replace('hbs', 'html')
94+
, ctxFn = template_contextfn[template]
95+
, ctx = template_contextfn[template]()
9496

95-
fs.writeFile('output/' + outputFile, output, function(err) {
97+
fs.readFile(path.join(
98+
__dirname
99+
, '..'
100+
, 'templates'
101+
, template
102+
), 'utf8', onread)
103+
104+
function onread(err, txt) {
96105
if(err) {
97106
return ready(err)
98107
}
99-
console.log('Wrote %s to %s', template, outputFile)
100108

101-
!--pending && ready(null)
102-
})
109+
var output = handlebars.compile(txt)(ctx)
110+
111+
fs.writeFile('output/' + outputFile, output, function(err) {
112+
if(err) {
113+
return ready(err)
114+
}
115+
console.log('Wrote %s to %s', template, outputFile)
116+
117+
!--pending && ready(null)
118+
})
119+
}
120+
})
121+
}
122+
}
123+
124+
function add_helpers(ready) {
125+
var helpers = [
126+
'base'
127+
, 'wrap'
128+
]
129+
130+
var pending = helpers.length
131+
132+
helpers.forEach(function(helper) {
133+
var dir = path.join(__dirname, '..', 'helpers', helper) + '.hbs'
134+
135+
fs.readFile(dir, 'utf8', function(err, txt) {
136+
if(err) {
137+
return ready(err)
138+
}
139+
140+
wrapperify(helper, txt)
141+
!--pending && ready(null)
103142
})
104143
})
105144
}
106145

146+
function wrapperify(name, txt) {
147+
var tpl = handlebars.compile(txt)
148+
149+
handlebars.registerHelper(name, function(options) {
150+
var content = options.fn(this)
151+
, ctx = {}
152+
153+
options.hash = options.hash || {}
154+
155+
for(var key in options.hash) {
156+
this[key] = options.hash[key]
157+
}
158+
159+
this.content = new handlebars.SafeString(content)
160+
161+
return tpl(this)
162+
})
163+
}
164+
107165
if(require.main === module) {
108166
compile(function(err) {
109167
if(err) {

bin/install.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ var meetups = require('knode-meetups')
1313
var base_dir = path.join(__dirname, '..', 'output')
1414

1515
var targets = {
16-
'stylesheets': path.join(__dirname, '..', 'stylesheets')
17-
, 'javascripts': path.join(__dirname, '..', 'javascripts')
18-
, 'images': path.join(__dirname, '..', 'images')
16+
'javascripts': path.join(__dirname, '..', 'javascripts')
1917
, 'style': path.join(__dirname, '..', 'node_modules', 'knode-style')
2018
}
2119

bin/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function main(ready) {
2323
return ready(err)
2424
}
2525

26-
var server = ecstatic({root: dir, defaultExt: true})
26+
var server = ecstatic({root: dir, defaultExt: true, cache: 0})
2727
, compiling = false
2828
, timeout
2929

helpers/base.hbs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8' />
5+
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
6+
<meta name="description" content="Meetups: A place to put info about your local meetup. Anything node-flavored JS welcome!" />
7+
8+
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/1.4.1/css/ionicons.min.css" />
9+
<link rel="stylesheet" href="/style/assets/css/ostrich-sans/stylesheet.css" />
10+
<link rel="stylesheet" href="/style/assets/css/main.css" />
11+
12+
<title>{{#if title}}{{ title }}{{else}}KNODE{{/if}}</title>
13+
</head>
14+
15+
<body id="{{body_id}}" class="{{body_class}}">
16+
<div id="hero" style="">
17+
{{#if logo}}
18+
<div>
19+
<h1 class="logo">KNODE</h1>
20+
<h2><span>Help us</span> build a resource for all things <span>node</span>.</h2>
21+
<a class="call-to-action" href="#">Find out how.</a>
22+
</div>
23+
{{/if}}
24+
<nav>
25+
<a class="nav-home" href="/">KNODE.IO</a>
26+
<a class="nav-speakers" href="/speakers">Speakers</a>
27+
<a class="nav-meetups" href="/meetups">Meetups</a>
28+
<a class="nav-cfp" href="#">CFP</a>
29+
<a href="http://nodemeatspace.com/">Events</a>
30+
<a href="https://github.com/knode/questions/issues">Q &amp; A</a>
31+
</nav>
32+
</div>
33+
34+
{{./content}}
35+
36+
<div id="footer_wrap" class="outer">
37+
<footer class="inner">
38+
<p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
39+
</footer>
40+
</div>
41+
</body>
42+
</html>

helpers/wrap.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div id="main_content_wrap" class="centered">
2+
<div id="main_content" class="row">
3+
{{content}}
4+
</div>
5+
</div>

images/bg_hr.png

-943 Bytes
Binary file not shown.

images/blacktocat.png

-1.39 KB
Binary file not shown.

images/github_icon.png

-1.28 KB
Binary file not shown.

images/icon_download.png

-1.13 KB
Binary file not shown.

images/sprite_download.png

-16.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)