Inject.plugin(name, ruleSet, functions?);
- converting CSS into an object that can be
- converting Dust templates into their executable JS equivalent
- loading JSON into a local variable
Defining a Plugin
Plugins are defined using
Inject.plugin and are given at the very least a name and a ruleSet. The ruleSet is identical to an Inject.addrule rule, except the
options.matches is inferred by the
name parameter. All plugins match the syntax:
name! is the plugin keyword, where “name” matches the name parameter from the plugin call. In fact, you can accomplish 99% of the plugin command using addRule. However, using
plugin is a clear indicator to other developers that you intend for your code to be modular and used in multiple scenarios.
The 3rd Param: Functions
The third parameter
functions is an object literal. All items found in this object are copied over to
Inject.plugins[name]. This allows custom functionality from within a pointcut to access global functionality. The CSS Plugin is a great example of making global functions available in order to create CSS “objects” which can then be returned as exports.