Keystone JS

Node.js CMS & Web Application Platform

Vorgestellt von Matthias Gutjahr / @mattsches

## About me * Matthias Gutjahr, selbständiger Web-Entwickler aus Wiesbaden * Orga [RheinMainJS](http://rheinmainjs.de/), [PHPUG Rheinhessen](http://www.phpug-rheinhessen.de/) * [@mattsches](https://twitter.com/mattsches) (fast überall)
Screenshot der KeystoneJS Webseite
## Was ist KeystoneJS? * Ein Node.js CMS und Web Application (MVC) Framework * Entwickelt in Sydney, Australien, u.a. für [SydJS](http://www.sydjs.com/) * Veröffentlicht unter der [MIT Lizenz](http://opensource.org/licenses/MIT)
### Warum Keystone? Es gibt ja noch andere JS-Frameworks und -CMSe
### [Apostrophe](http://apostrophenow.org/) * Reines CMS * Früher ein PHP-MySQL-Projekt (Symfony), jetzt Node.js und MongoDB * Inhalte können direkt im Frontend bearbeitet werden
### [Ghost](https://ghost.org/) * "Just a blogging platform" mit vielen Themes * Markdown-Editor * SQLite oder MySQL
### [Calipso](http://www.calip.so/) * CMS based on NodeJS, MongoDB * not much documentation
### [Hatch.js](http://hatchjs.com/) * CMS auf NodeJS und Redis * Demo site broken * Kaum Doku
### et cetera …
## Komponenten / Building Blocks * [express.js](http://expressjs.com/) Web Server Framework * [MongoDB](http://www.mongodb.org/) (via [mongoose](http://mongoosejs.com/))
## Komponenten / Building Blocks * *LESS* oder *SCSS* als Stylesheet-Sprache * *Gulp* oder *Grunt* für den Build-Prozess * [*dotenv*](https://www.npmjs.com/package/dotenv) für Umgebungsvariablen
## Komponenten / Building Blocks * Templating Engines: * [Jade](http://jade-lang.com/) * [Handlebars](http://handlebarsjs.com/) * [Swig](https://paularmstrong.github.io/swig/) * [Nunjucks](https://mozilla.github.io/nunjucks/)
## Features * Kickstart/Scaffolding mit dem [Yeoman](http://yeoman.io/) Generator: * Automatisch generiertes [Backend](http://rheinmainjs.de/keystone) * Flash Messages * Authentication & Session- und User-Management eingebaut
## Externe Dienste * [Mandrill](https://mandrill.com/) (E-Mail-Infrastrukturdienst von Mailchimp) * [Cloudinary](http://cloudinary.com/) (Bilderdienst in der Cloud, CDN) * [Embed.ly](http://embed.ly/) (Einbetten von Inhalten via oEmbed)
## Erweiterbarkeit * Einfach Modul XY der `package.json` hinzufügen * installieren * und `require('xy')`
## Yeoman Generator ```bash $ (sudo) npm install -g generator-keystone $ mkdir rheinmainjs $ cd rheinmainjs $ yo keystone ... einige Angaben ... fertig! ```
## Project Structure ``` |--lib (Custom libraries and other code) |--models (Your applications database models) |--public (Static files (css, js, images, etc.)) |--routes | |--api (Your application's api controllers) | |--views (Your application's view controllers) | |--index.js (Initialises your application's routes and views) | |--middleware.js (Custom middleware for your routes) |--templates | |--includes (Common .jade includes go in here) | |--layouts (Base .jade layouts go in here) | |--mixins (Common .jade mixins go in here) | |--views (Your application's view templates) |--updates (Data population and migration scripts) |--package.json (Project configuration for npm) |--web.js (Main script that starts your application) ```

Models


// models/users.js

var keystone = require('keystone'),
    Types = keystone.Field.Types;

var User = new keystone.List('User');

User.add({
    name: { type: Types.Name, required: true, index: true },
    email: { type: Types.Email, initial: true, required: true, index: true },
    password: { type: Types.Password, initial: true },
    isOrganiser: { type: Boolean, initial: false }
});

User.register();
					
### Interne Feldtypen Boolean, Text, Textarea, Email, Url, Html, Color, Date, Datetime, Number, Money, Select, Markdown, Name, Password, Location, CloudinaryImage, LocalFile, S3File, Embedly, …
### Route Controllers ```js var keystone = require('keystone'); exports = module.exports = function (req, res) { var view = new keystone.View(req, res), locals = res.locals; locals.section = 'about'; locals.data = { organizers: [] }; view.on('init', function (next) { keystone.list('User').model.find() .where('isOrganiser', true) .sort('name') .exec(function (err, result) { locals.data.organizers = result; next(err); }); }); view.render('views/about'); }; ```
http://dan232323.deviantart.com/
### Thanks! * [http://keystonejs.com/](http://keystonejs.com/) * [https://github.com/rheinmainjs/rmjs-keystone](https://github.com/rheinmainjs/rmjs-keystone) * [http://rheinmainjs.de/](http://rheinmainjs.de/)