-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 97109f5
Showing
15 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.git | ||
*.log | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
var express = require('express') | ||
var port = process.env.PORT || 8080; | ||
var app = express(); | ||
|
||
// var handlebars = require('express3-handlebars').create({defaultLayout: 'main'}); | ||
|
||
// 添加helper方法 | ||
var handlebars = require('express3-handlebars').create( | ||
{ | ||
defaultLayout: 'main', | ||
helpers: { | ||
section: function (name, options) { | ||
if(!this._sections) this._sections = {}; | ||
this._sections[name] = options.fn(this); | ||
return null; | ||
} | ||
} | ||
}); | ||
|
||
app.engine('handlebars', handlebars.engine); | ||
app.set('view engine', 'handlebars'); | ||
app.set('view cache', true); | ||
|
||
app.use(express.static(__dirname + '/public')); | ||
|
||
|
||
app.listen(port); | ||
|
||
console.log('imooc started on port ' + port); | ||
|
||
app.get('/', function (req, res) { | ||
res.render('home') | ||
}) | ||
|
||
app.get('/nolayout', function (req, res) { | ||
res.render('noLayout', { layout: null }) | ||
}) | ||
|
||
app.get('/custom', function (req, res) { | ||
res.render('customLayout', { layout: 'custom' }) | ||
}) | ||
|
||
app.get('/partialsTest', function (req, res) { | ||
res.render('partialsTest') | ||
}) | ||
|
||
app.get('/sectionTest', function (req, res) { | ||
res.render('sectionTest', { | ||
layout: 'sectionLayout' | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "lingermarket_express", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "kuntang", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.14.1", | ||
"express3-handlebars": "^0.5.2" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>about page</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<span>this is custom layout page</span> | ||
<a href="/">back</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>home page</h1> | ||
<a href="/nolayout">nolayout</a> | ||
<a href="/custom">customLayout</a> | ||
<a href="/partialsTest">partials test</a> | ||
<a href="/sectionTest">sections test</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
<style> | ||
body{ | ||
font-size: 22px; | ||
color: blue; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
{{{_sections.head}}} | ||
</head> | ||
<body> | ||
This is sectionLayout | ||
{{{body}}} | ||
<script src="/jquery-3.1.1.min.js"></script> | ||
{{{_sections.jquery}}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
this is no layout page | ||
<a href="/">back</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="panelCon"> | ||
this is partial panel inside | ||
|
||
<a href="/">back</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>panel partials page</h1> | ||
{{> panel}} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{#section 'head'}} | ||
<meta name="root" content="noindex"> | ||
{{/section}} | ||
|
||
<h1>Test Page</h1> | ||
<p>We're testing some jQuery stuff</p> | ||
<a href="/">back</a> | ||
|
||
{{#section 'jquery'}} | ||
<script> | ||
$('document').ready(function () { | ||
$('h1').html('jQuery Works'); | ||
}); | ||
</script> | ||
{{/section}} |