skellyjs v0.1.12
skellyjs
skellyjs framework
Table of Contents
- Quick Start
- Creating Pages (Controllers)
- Models
- HTML Views
- Client-side Javascript Files
- CSS Files
- Logging
- Custom Installation
- Node.js Style Guide
- License
Quick Start
Install the Generator
$ npm install -g generator-skellyjs
Create the app:
$ skelly /tmp/project && cd /tmp/project
Install dependencies:
$ npm install
Start the app
$ npm start
Creating Pages (Controllers)
The built in router will automatically look for a controller named the same as the url path. The index controller is used for /. To create a /help page, just create a controller named help.js. Index and 404 controller examples are in /controllers.
Models
To connect to your MongoDB, make sure to set process.env.DB_HOST
, process.env.DB_NAME
, process.env.DB_USER
, and process.env.DB_PASSWORD
. DotEnv is built into skelly, so if you create a .env file in your application's root, you should set these values there. A .env example file is in the root.
/* /.env */
# Database host(s) comma separated (10.0.0.1,10.0.0.2)
DB_HOST=localhost
# Database Name
DB_NAME=skelly
# Database user
DB_USER=user
# Database password
DB_PASSWORD=pass
Mongoose models will be included automatically in the skelly object. To access them, use the skelly.models.<filename>
method. An index model example is in /models.
The model itself is constructed just like all other Mongoose models, but using the skelly.mongoose object (instead of including the mongoose library)
/* /models/index.js */
module.exports = function(skelly) {
return skelly.mongoose.model(
// name of your model (http://mongoosejs.com/docs/models.html)
'Test',
// schema (http://mongoosejs.com/docs/schematypes.html)
{
title : {
type: String,
required: true
}
}
);
};
In your controller, access the index model using skelly.models.index
.
/* /controllers/index.js */
skelly.models.index.findOne({}, function(err, index) {
if (err) {
skelly.log.error(err);
res.end(err);
} else {
// if no entry, just pass a static title
if (!index) {
skelly.render(req, res, viewFile, {title:"Hello, my name is Shelby!"});
// if there's an entry, pass it to use as the title
} else {
skelly.render(req, res, viewFile, index);
}
}
});
HTML Views
The built in templating engine is swig. Your views should go into the /views folder. Javascript (/javascripts )and CSS (/stylesheets) includes will be read into memory. You can hash javascript, css, or images using a skelly swig filter. Index and 404 views, plus a main layout, examples are in /views (and /views/layouts).
<script src="/javascripts/{{'index.min.js'|hash}}"></script>
<link rel="stylesheet" href="/stylesheets/{{'index.min.css'|hash}}" />
<img src="/images/{{'shelby.jpg'|hash}}" />
Example output:
<script src="/javascripts/index.min.e0df532694.js"></script>
<link rel="stylesheet" href="/stylesheets/index.min.e0df532694.css" />
<img src="/images/shelby.e0df532694.jpg'" />
The system will automatically return the current file for any hash.
Client-side Javascript Files
The javascript files are read into memory on load. Required files are not combined into a single file, but that feature is coming. They are, however, minified using Uglify-JS. An index javascript example file is located in /javascripts
CSS Files
The built in CSS precompiler is LESS. I suggest you create a single less file for each view (/stylesheets), and include global less files (/stylesheets/includes) as needed. An index less file, and several includes, are located in /stylesheets (and /styplesheets/includes)
/* index.less */
@import 'global';
Logging
To log something to stdout, there's a built in method (using bunyan). You can simply call skelly.log.<level>('Hello!')
.
level
can be (from most severe to least):
- fatal
- error
- warn
- info
- debug
- trace
By default (development mode), debug and higher are output, while trace is ignored. In production (NODE_ENV=production
), info and higher are output, while debug and trace are ignored. You can set the log level LOGLEVEL=trace
in your .env file.
Custom Installation
If you'd like to install the framework into your own app:
$ npm install skellyjs --save
In your main script:
/* /app.js */
var http = require('http'); // http server
var skelly = require('skellyjs'); // skellyjs framework
// generate the css
skelly.generateCss();
// generate the javascript
skelly.generateJs();
// create the server
var server = http.createServer(function(req, res) {
skelly.router(req,res);
});
// accept incoming traffic
server.listen(process.env.PORT || 4000);
skelly.log.debug('Listening on port:', server.address().port);
skelly.log.debug("Hash:",skelly.hash);
Node.js Style Guide
License
8 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago