Plugins #38

Closed
shimaore opened this Issue Sep 3, 2012 · 2 comments

Comments

Projects
None yet
1 participant
@shimaore
Owner

shimaore commented Sep 3, 2012

I'm going to add experimental support for plugins to Zappa. These would be e.g. like Validator in #36.
Hopefully people will find interesting uses for plugins as well.

Objectives

My first target will be a plugin or multiple plugins for CSS; this would also allow to remove things like @stylus, @less, etc. out of core Zappa, and move them into plugins; which would eliminate the css option to Zappa.run(). This could also automate dependencies -- stylus would be a dependency of zappajs-stylus, etc.

require('zappajs') ->
  @plugin `zappajs-stylus`

  @stylus '/index.css': ...

I guess a generic solution (equivalent to the current css option) would be:

require('zappajs') ->
  @plugin 'zappajs-css', 'stylus'

(in which case the developer still needs to provide the stylus package).

Plugin structure

A plugin will be anything that can be required, whether it's a package in node_modules or a file. They'll work kinda like @include, but have access to some Zappa internals:

# zappajs-validator.coffee
@plugin ->
  @helper 'assert' -> ...

A plugin will receive at least one argument, an object containing context (same as @) and (for now) route (allows to add a native Zappa route -- I need this to do the CSS plugin thing). Extra arguments provide by the developer are also provided.

@shimaore

This comment has been minimized.

Show comment Hide comment
@shimaore

shimaore Sep 3, 2012

Owner

On second thought @require might be a better name than @plugin.

Owner

shimaore commented Sep 3, 2012

On second thought @require might be a better name than @plugin.

@shimaore

This comment has been minimized.

Show comment Hide comment
@shimaore

shimaore Apr 20, 2016

Owner

ZappaJS 4.0 now has plugins, using the @with syntax. Plugins are by default in the zappajs-plugin-* namespace, and get access to context, route, browserify, and require. (This probably needs to be documented in the main reference document.)

Owner

shimaore commented Apr 20, 2016

ZappaJS 4.0 now has plugins, using the @with syntax. Plugins are by default in the zappajs-plugin-* namespace, and get access to context, route, browserify, and require. (This probably needs to be documented in the main reference document.)

@shimaore shimaore closed this Apr 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment