npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

risotto

v0.0.2

Published

Risotto is a VC framework based on koajs. it makes heavy use of es6 harmony features and thus requires node´s **--harmony** flag

Downloads

2

Readme

#Risotto Risotto is a VC framework based on koajs.

##Install Risotto requires redis to run

$ npm install risotto

#Scaffolding Risotto needs a special project structure to run:

app/
	controllers/
	filters/
	modules/
	public/
	views/
	application.js

config/
	production.js
	development.js
	routes.yml

Require Risotto where ever you want and pass the those folders to the initialize method like this: it makes heavy use of es6 harmony features and thus requires node´s --harmony flag

require('risotto').initialize(__dirname);

After calling initialize Risotto will boot up and look up all controllers in /app/controllers. It will bind all routes configured in the /config/routes.yml file for you. Be Aware Risotto will register a global variable named "Risotto".

##Controllers Controllers take the main part in handling incoming requests and processing them.

A controller consists of a group of methods which handle one type of request defined in the route. Example:

module.exports = Risotto.Controller.extend({
	index : function*(params){
		yield this.render("dashboard/index", {user : user });
	}
});

The params object passed to each method contains every parameter that might be passed to the server. In the methods you have access to the following methods:

this.render(pathToView, options = {})

Generator Function which renders and returns a html template at path. Everything into the options object will be available as variable in the template.

this.body =

setter/getter for the response body

###this.status = setter/getter for the response status code

###this.redirect(path) Redirects the Request to path

###this.error(code [, message]) Returns an http error with the given code and optional with the message.

###this.attachment access to the koa attachment method

###this.json access to the koa method json

###this.type access to the koa attribute type

###this.session access to the koa attribute session

###this.request access to the koa request object

###this.response access to the koa response object

##Routes The routes file in the config directory contains all the individual routes to the controllers. It has the following syntax:

routes:
 GET /:username/: Profile.show

###namespacing Routes can be namespaced in the following way:

routes:
 project:
  GET :id-(.+): Project.show

##Application.js

module.exports = Risotto.Application.extend({
	
	// process title
	title: "My Risotto App",
	
	onAuthorizationError : function*(koaContext, next){
		//do something onAuthorizationError
	},

	onNotFoundError : function*(koaContext, next){
		// do something onNotFoundError
	},

	onError : function*(koaContext, next){
		// do something onError
	}
});

##Modules …

##Filters Filters are a way to reuse common controller functionality. We differentiate between beforeFilter which run before the controller and the afterFilter which run after the actual controller. ###Using Filters

Risotto.Controller.extend({
	// calls the `user` and the `authorize` filter before
	beforeFilter: ['user', 'authorize']
})

Risotto.Controller.extend({
	beforeFilter: {
		/* 
		 * calls `user` filter before 
		 * all controller methods
		 */
		user: '*', 

		/*
		 * calls `authorize` filter only 
		 * before protectedMethod
		 */
		authorize: 'protectedMethod',

		/*
		 * calls `foo` filter only 
		 * before protectedMethod and show
		 */
		foo: ['show', 'protectedMethod']
	}
});

###Defining Filters Create a new file in app/filters and call Risotto.before to register a beforeFilter and Risotto.after to register a afterFilter.

Risotto.before('user', function*(){
	if( !this.session || !this.session.user_id ){
		return;
	}
	
	//`this` referes to the controller context
	this.user = yield User.findOne({ id: this.session.user_id });
});