Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove old incomplete blog example

  • Loading branch information...
commit 36629ca73d6982cd1a93fc2388358188f8fe19e4 1 parent 39ba4e0
TJ Holowaychuk tj authored
Showing with 0 additions and 157 deletions.
  1. +0 −102 examples/blog/index.html
  2. +0 −55 examples/blog/index.js
102 examples/blog/index.html
View
@@ -1,102 +0,0 @@
-
-<style>
- body {
- font: 14px "Helvetica Neue", Helvetica, arial, sans-serif;
- padding: 60px;
- }
- p {
- margin: 5px;
- }
- input[type='text'] {
- padding: 5px 10px;
- border-width: 1px;
- -webkit-border-radius: 2px;
- }
-</style>
-
-<script src="build.js"></script>
-
-<script>
- var domify = require('component-domify');
-
- // TODO: remove all this, real example..
-
- function errorHTML(Model) {
- Model.prototype.errorHTML = function(){
- return '<ul class=errors>\n' + this.errors.map(function(err){
- return ' <li>' + err.attr + ' ' + err.message + '</li>';
- }).join('\n') + '\n</ul>';
- };
- }
-
- function formHTML(Model) {
- Model.prototype.form = function(){
- var model = this.model;
- var attrs = model.attrs;
- var save = this.isNew() ? 'Save' : 'Update';
- var url = this.isNew() ? model.url() : this.url();
- var html = '';
- var attr;
-
- html += '<form action="' + url + '">\n';
-
- for (var name in attrs) {
- attr = attrs[name];
- if (attr.primaryKey) continue;
- if (false === attr.show) continue;
- html += ' <p>\n';
- html += ' <input type="text" placeholder="' + name + '" name="' + name + '" />\n';
- html += ' </p>\n\n';
- }
-
- html += ' <div class=actions>\n';
- html += ' <input type="submit" value="' + save + '"></input>\n';
- html += ' </div>\n';
- html += '</form>\n';
-
- return html;
- };
- }
-
- function required(attr) {
- return function(Model){
- Model.validate(function(model){
- if (!model.has(attr)) model.error(attr, 'field required');
- });
- }
- }
-
- function lengthAbove(attr, len) {
- return function(Model){
- Model.validate(function(model){
- if (!model.has(attr)) return;
- var str = model.get(attr);
- if (str.length <= len) model.error(attr, 'must be longer than ' + len + ' characters');
- });
- }
- }
-
- var model = require('model');
-
- var Post = model('Post')
- .attr('id', { type: 'number' })
- .attr('title', { type: 'string' })
- .attr('body', { type: 'string' })
- .attr('create_at', { type: 'date', show: false })
- .attr('update_at', { type: 'date', show: false })
- .use(errorHTML)
- .use(formHTML)
- .use(required('title'))
- .use(required('body'))
- .use(lengthAbove('title', 3))
- .use(lengthAbove('body', 20))
-
- var post = new Post({ title: 'Something', body: 'Some other thing here' });
-
- post.save(function(err){
- Post.get(post.id(), function(err, post){
- console.log(post);
- })
- });
-
-</script>
55 examples/blog/index.js
View
@@ -1,55 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var express = require('express');
-var app = express();
-var posts = [];
-
-app.use(express.logger('dev'));
-app.use(express.bodyParser());
-
-app.get('/', function(req, res){
- res.sendfile(__dirname + '/index.html');
-});
-
-app.get('/build.js', function(req, res){
- res.sendfile('build.js', { root: __dirname + '/../../build' });
-});
-
-app.get('/posts', function(req, res){
- res.send(posts);
-});
-
-app.get('/post/:id', function(req, res){
- var post = posts[req.params.id];
- if (post) {
- res.send(post);
- } else {
- res.send(404);
- }
-});
-
-app.post('/post', function(req, res){
- console.log('add post %j', req.body);
- var id = posts.push(req.body) - 1;
- res.send({ id: id }, 201);
-});
-
-app.put('/post/:id', function(req, res){
- var id = req.params.id;
- console.log('update post %s %j', id, req.body);
- posts[id] = req.body;
- res.send(201);
-});
-
-app.del('/post/:id', function(req, res){
- var id = req.params.id;
- console.log('delete post %s', id);
- posts.splice(id, 1);
- res.send(200);
-});
-
-app.listen(3000);
-console.log('Application listening on port 3000');
Please sign in to comment.
Something went wrong with that request. Please try again.