Skip to content

Commit

Permalink
init the project
Browse files Browse the repository at this point in the history
  • Loading branch information
kunkuntang committed Mar 1, 2017
0 parents commit 97109f5
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.git
*.log
.idea
52 changes: 52 additions & 0 deletions main.js
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'
})
})
15 changes: 15 additions & 0 deletions package.json
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"
}
}
4 changes: 4 additions & 0 deletions public/jquery-3.1.1.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions views/about.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>about page</h1>
2 changes: 2 additions & 0 deletions views/customLayout.handlebars
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>
5 changes: 5 additions & 0 deletions views/home.handlebars
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>
16 changes: 16 additions & 0 deletions views/layouts/custom.handlebars
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>
10 changes: 10 additions & 0 deletions views/layouts/main.handlebars
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>
14 changes: 14 additions & 0 deletions views/layouts/sectionLayout.handlebars
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>
11 changes: 11 additions & 0 deletions views/noLayout.handlebars
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>
5 changes: 5 additions & 0 deletions views/partials/panel.handlebars
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>
2 changes: 2 additions & 0 deletions views/partialsTest.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>panel partials page</h1>
{{> panel}}
Empty file added views/sectionContent.handlebars
Empty file.
15 changes: 15 additions & 0 deletions views/sectionTest.handlebars
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}}

0 comments on commit 97109f5

Please sign in to comment.