Skip to content

Commit

Permalink
release template error
Browse files Browse the repository at this point in the history
  • Loading branch information
leeluolee committed Oct 29, 2015
1 parent 5131053 commit 6dce957
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var puer = module.exports = function ( options ){
app.use( folder( options ) );
app.use( express.static( options.dir ) );
app.use(function(err, req, res, next) {
helper.log(err.message, 'error');
helper.log(err.message || err, 'error');
res.status(500).send('Something is broken!');
});
server.on('error', function (e) {
Expand Down
42 changes: 35 additions & 7 deletions test/fixtures/mock_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


module.exports = {
"POST /path/to": "http://127.0.0.1:8002" ,
"POST /path/*": "http://127.0.0.1:8002" ,
"GET /hogan.html": "http://127.0.0.1:8002" ,
"ALL /posts/:id": function( req, res ){
posts.push({id:posts.length, name: 'post' + posts.length});
Expand Down Expand Up @@ -37,16 +37,44 @@ module.exports = {
"GET /raw": {code: 100, result: 200},
'GET /ftl': function(req, res){
res.render('ftl/index.ftl', {
name: 'zhenghaibo',
"data":{
user1: JSON.stringify({
"nickname": "caijf",
"theme": 0,
"onlineStatus": 1,
"password": "e10adc3949ba59abbe56e057f20f883e",
"portrait": "",
"id": 415,
"username": "caijf123456",
"role": 0,
"realname": "caijf",
"pinyin": "caijf",
"mobile": ""
}),
"user": {
"nickname": "caijf",
"theme": 0,
"onlineStatus": 1,
"password": "e10adc3949ba59abbe56e057f20f883e",
"portrait": "",
"id": 415,
"username": "caijf123456",
"role": 0,
"realname": "caijf",
"pinyin": "caijf",
"mobile": ""
},
"yunxin": {
"token": "afb7a94ae16746709a9db0529aa9e0e3",
"account": "ad60bc4cc82bea43541c5f55902e@kf@",
"appKey": "044865c94981c048609d5c94c1ae9c6d"
}
},
flowers: [
["zhenghaibo", 'hello' ,100],
["zhenghaibo2", 'hello2' ,200]
['1','2','3','4']
]
})
},
"GET /ftl": function(req, res){
res.json({code:1})
},
'ALL /p/(.*)': 'http://nec.netease.com/plugin/{0}',
"GET /blog": "./index.html",
"GET /(framework|standard|library)": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/view/ftl/inc.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dajdklajsdklajldks

${name}
${name!}

<#include "../common.ftl" >

Expand Down
48 changes: 48 additions & 0 deletions test/fixtures/view/ftl/index.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
<#function stringify obj>
<#if !obj??>
<#return 'undefined'>
</#if>
<#if obj?is_string>
<#return '"' + obj?js_string + '"'>
</#if>
<#if obj?is_date>
<#return '"' + obj?string("yyyy-MM-dd HH:mm:ss") + '"'>
</#if>
<#if obj?is_boolean || obj?is_number>
<#return obj?string>
</#if>
<#if obj?is_enumerable>
<#local str = '['>
<#list obj as x>
<#local str = str + stringify(x)>
<#if x_has_next>
<#local str = str + ','>
</#if>
</#list>
<#return str + ']'>
</#if>

<#if obj?is_hash || obj?is_hash_ex>
<#local str = '{'>
<#local arr = [] >
<#local keys = obj?keys>
<#list keys as x>
<#if x!='class' && obj[x]?? && !obj[x]?is_method>
<#local arr = arr + [x]>
</#if>
</#list>
<#list arr as x>
<#local str = str + x + ':' + stringify(obj[x])>
<#if x_has_next>
<#local str = str + ','>
</#if>
</#list>
<#return str + '}'>
</#if>
<#return ''>
</#function>
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -7,6 +50,11 @@
<body>

<#include "./inc.ftl" >

<script >
var js = ${ stringify(data.user) }
</script>

</body>
</html>

0 comments on commit 6dce957

Please sign in to comment.