Skip to content

Commit 7d86477

Browse files
committed
Add capitalize filter; fix page.layoutWas and page.contentWas
1 parent 7fd1aec commit 7d86477

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

lib/liquid/index.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ Liquid.Template.registerTag "include", do ->
130130
@included.then (i) -> i.render context
131131

132132
Liquid.Template.registerFilter
133+
capitalize: (input) ->
134+
input && input.replace(/^([a-z])/, (m, chr) -> chr.toUpperCase())
135+
133136
date: formatDate
134137

135138
date_to_xmlschema: (input) ->

lib/liquid/index.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/writers/templated.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ function markup(page) {
3737
}
3838

3939
var _layouts = {}
40-
var _layout
41-
42-
function layout(post) {
43-
if (!post.layoutWas) post.layoutWas = post.layout
44-
if (!post.layout || _layout === post.layout) {
45-
// Finished layout renderring, restore the original layout of current post
46-
post.layout = post.layoutWas
47-
return post
40+
41+
function layout(page) {
42+
if (!page.layoutWas) page.layoutWas = page.layout
43+
if (page.layout_ == page.layout) {
44+
// Finished layout renderring, restore the original layout of current page
45+
page.layout = page.layoutWas
46+
page.layout_ = ''
47+
return page
4848
}
49-
_layout = post.layout
49+
page.layout_ = page.layout
5050

51-
var site = post.site
51+
var site = page.site
5252
// support .html layouts only, for now.
53-
var lpath = path.join(site.cwd, '_layouts', post.layout) + '.html'
53+
var lpath = path.join(site.cwd, '_layouts', page.layout) + '.html'
5454
var lcache = _layouts[lpath]
5555

5656
if (!lcache) {
@@ -73,15 +73,15 @@ function layout(post) {
7373
.then(function(template) {
7474
return template.render({
7575
site: site,
76-
page: post,
77-
content: post.output
76+
page: page,
77+
content: page.output
7878
})
7979
})
8080
.then(function(res) {
81-
post.output = res
82-
if (lcache.matter) _.extend(post, lcache.matter)
81+
page.output = res
82+
if (lcache.matter) _.extend(page, lcache.matter)
8383

84-
return layout(post)
84+
return layout(page)
8585
})
8686
}
8787

@@ -106,12 +106,16 @@ module.exports = function writeTemplated(page) {
106106
})
107107
})
108108
.then(function(res) {
109+
page.contentWas = page.content
109110
page.content = res
110111
return page
111112
})
112113
.then(markup)
113114
.then(layout)
114115
.then(render)
116+
.then(function() {
117+
page.content = page.contentWas
118+
})
115119
.fail(function(err) {
116120
util.error('Failed to generate ' + page.path + ' because of ')
117121
util.error(err.message)

0 commit comments

Comments
 (0)