Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example views written using EJS #51

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/defaultSetupEjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var
express = require('express'),
app = express(),
// All default options
poet = require('../lib/poet')(app);

poet.init().then(function () {
// initialized
});

app.set('view engine', 'ejs');
app.set('views', __dirname + '/views/ejs');
app.use(express.static(__dirname + '/public'));
app.use(app.router);

app.get('/', function (req, res) { res.render('index'); });

app.listen(3000);
9 changes: 9 additions & 0 deletions examples/views/ejs/category.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% include header.ejs %>

<h3><a href="<%- categoryUrl(category) %>">posts in category * <%= category %></a></h3>

<% posts.forEach(function(post){ %>
<% include postSnippet.ejs %>
<% }) %>

<% include footer.ejs %>
23 changes: 23 additions & 0 deletions examples/views/ejs/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
</div>

<div class="span4">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">categories</li>
<% getCategories().forEach(function(cat) { %>
<li><a href="<% categoryURL(cat) %>"><%= cat %></a></li>
<% }) %>

<li class="nav-header">tags</li>
<% getTags().forEach(function(tag) { %>
<li><a href="<% tagURL(tag) %>"><%= tag %></a></li>
<% }) %>
</ul>
</div>
</div>

</div>
</div>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions examples/views/ejs/header.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Poet Demo</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/bootstrap.css">
</head>
<body>

<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a href="/" class="brand">Poet Demos</a>
</div>
</div>
</div>

<div class="wrap">
<div class="container">
<div class="row">

<div class="span8">
12 changes: 12 additions & 0 deletions examples/views/ejs/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% include header.ejs %>

<% var posts = getPosts(0,5) %>
<% var page = 1 %>

<% posts.forEach(function(post){ %>
<% include postSnippet.ejs %>
<% }) %>

<% include pagination.ejs %>

<% include footer.ejs %>
9 changes: 9 additions & 0 deletions examples/views/ejs/page.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% include header.ejs %>

<% posts.forEach(function(post){ %>
<% include postSnippet.ejs %>
<% }) %>

<% include pagination.ejs %>

<% include footer.ejs %>
13 changes: 13 additions & 0 deletions examples/views/ejs/pagination.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ul class="pagination">

<% var i = 1 %>
<% var pageCount = getPageCount() %>
<% var cssClass %>

<% while (i <= pageCount) { %>
<% cssClass = (page == i) ? 'class="active"' : '' %>
<%- '<li ' + cssClass + '><a href="/pagination/' + i + '"> ' + i + '</a></li>' %>
<% i++ %>
<% } %>

</ul>
23 changes: 23 additions & 0 deletions examples/views/ejs/post.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% include header.ejs %>

<div class="post">
<h1><a href="<%= post.url %>"><%= post.title %></a></h1>

<span class="date">
<%= (post.date.getMonth() + 1) + '.' + post.date.getDate() + '.' + post.date.getFullYear() %>
</span>

<div class="post content">
<%- post.content %>
</div>

<div class="tags">
<% post.tags.forEach(function(tag){ %>
<a href='<%= tagUrl(tag) %>'>
<span class="label label-info"><%= tag %></span>
</a>
<% }) %>
</div>
</div>

<% include footer.ejs %>
21 changes: 21 additions & 0 deletions examples/views/ejs/postSnippet.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="post">

<h1><a href=<%= post.url %>><%= post.title %></a></h1>

<span class="date">
<%= (post.date.getMonth() + 1) + '.' + post.date.getDate() + '.' + post.date.getFullYear() %>
</span>

<div class="post content">
<%- post.preview %>
</div>

<div class="tags">
<% post.tags.forEach(function(tag){ %>
<a href='<%= tagUrl(tag) %>'>
<span class="label label-info"><%= tag %></span>
</a>
<% }) %>
</div>

</div>
9 changes: 9 additions & 0 deletions examples/views/ejs/tag.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% include header.ejs %>

<h3><a href="<%- tagUrl(tag) %>">posts tagged * <%= tag %></a></h3>

<% posts.forEach(function(post){ %>
<% include postSnippet.ejs %>
<% }) %>

<% include footer.ejs %>