Introduction
Supernova is a V8 engine based framework to work with classes, inheritance and encapsulation of modules for the web. Every instance of a supernova class can be rendered with a view-enigne (default: jade) and has its own template. The built in router and webserver stack gives you a full stack for writing webapplications with supernova!
Example App
app.js
var nova = ; var Person = nova; var foo = 'bar' 10;var baz = 'foo' 39; var router = nova;var server = nova; router; server;
Example page view
page.jade
doctype 5 head title= Users body block users
Example module view
person.jade
extends page block users if users && userslength > 0 ul each user in users li= #username Age #userage else p No users avaible!
Class Basics
Creation
With supernova you can easily create classes with properties, methods and constructors.
They're provided with getters, setters, special methods and even an event-system,
which you can disable by passing a second boolean parameter true
to the method.
However, you can also inherit multiple times in a tree below, which is shown in
the chapter Advanced Inheritance, but let's start with
the basic example;
1. Include
var nova = ;
2. Create
var MyClass = nova;
Well, you now got a class, which has no content but the basic methods of the
supernova.Base
class. So, let's change the class creation a little
bit and add some properties and methods;
var MyClass = nova;
So, we've created a basic class with a name property in it, and a method to greet somebody - called hellow. Let's see it in action!
3. Instanciate
var test = ;test; // > 'Hellow, I'm <anonym>!'
Now, we can instanciate the class with a value, any name or number or whatever you like to insert. Let's try it with 'Foo';
var test2 = 'Foo';test; // // > 'Hellow, I'm Foo!'
And that's the magic!
Advanced Inheritance
You basically can inherit classes from another class created with supernova. It will
be stored in a prototype chain with references to the super class. Everything is
implemented correctly, so that even the instanceof
method will return
true if you test it on the parent! Here's an example below;
var MySuper = nova; var MyChild = MySuper; var You = 'Max';// > 'Hellow, I'm Max!'
Events
Basics
Every class created with supernova will automatically inherit properties and
methods from the EventEmitter
, a class from nodes built-in events
module. So, every instance can use the classic event handling system, like
in the example below.
var nova = ; var Test = nova; var app = 10; app; app; // > 'Calculated number 20!'
View Basics
The view engine in this framework is jade but if you'd like to, you can write your own view engine. For this path, take a look at custom view-engine.
Engine
The view engine or renderer is exported under .render
and takes two
arguments; an instance and an object - which contains additional options. This
method returns the compiled jade HTML as string.
var nova = ; var person = nova; var bill = ;billname = 'Bill'; var html = nova;
And now it's time to write the jade HTML template, this is a simple template and if you want to learn more about jade, visit their Language Reference documentation.
!!!5 html head title Supernova App include styles body h1 Hey there, I'm #{bill.name}!
Custom Engine
tbd.
Server basics
Create
Supernova has an integrated server which allows you to build webapplications rapidly and without requiring other node modules. It's a simple HTTP server with a lot of customization, but let us have a look at that;
var router = nova;var server = nova; router; server;
Run
You need to call the .listen
method on the server to get him up and
running. It will take the port you've set in the options in the server or
alternatively you can also define the port for the server which he will listen to
via the listen function (arg#1). Default port is 7007
!
server; // http://localhost:7000
Custom server
tbd.
Router
Supernova contains a basic router for creating RESTful webapplications with ease. If you don't want to use the built-in router but want to write your app with express or another webapplication framework, you can use them and make the rest with supernova. So you stay fully flexibel with it and you can change it anytime you'd like to. Here is a short example of how to use the router;
var server = nova;var router = nova; // on HTTP GET requestsrouter; // on HTTP PUT requestsrouter; // connect your router and take-offserver;
Framework Information
Author
This framework was created by Jan Biasi in 2015 and is licensed under the MIT License.
Versions
Version | Description | Updatable? |
---|---|---|
1.0.17 | Readme file updates and fixes in example code | yes |
1.0.16 | Readme file updates and fixes in example code | yes |
1.0.15 | Minor bugfixes in server stack | yes |
1.0.14 | Adding a basic router inspired by expressjs | no |
1.0.13 | Bugfixes in server, updated architecture and prepare for router | yes |
1.0.12 | Adding example application | yes |
1.0.11 | Updated documentation for 10.0.01+ | yes |
1.0.10 | Updated readme and update npm package | yes |
1.0.09 | Server-stack bugfixes | yes |
1.0.08 | Server-stack bugfixes | yes |
1.0.07 | Server-stack bugfixes | yes |
1.0.06 | Add the server-stack for webapps | yes |
1.0.05 | Templates can now be defined in classes | yes |
1.0.04 | Jade can work with files now | yes |
1.0.03 | Partial view support for Jade | yes |
1.0.02 | Including dependencies; jade, chalk, pathregexp & co. | yes |
1.0.01 | Repair bugs in subclass creation and add prototype chaining | yes |
1.0.00 | Basic version without view engine and server | yes |
0.0.x-beta | Local work | - |
0.0.x-alpha | Local work | - |