Wrap any JavaScript file in an Aria Templates class definition.
It allows to create either plain classes or a singleton.
Getting Started
This plugin requires Grunt ~0.4.4.
Install the plugin with npm install grunt-at-class
or put it in your package.json
and add the following line to your Gruntfile.js
grunt;
The "at_class" task
at_class
is a multitask that generates a JavaScript file with a class definition from a source file.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Overview
In your project's Grunfile.js
add a section named at_class
to the object passed to grunt.initConfig()
.
at_class: myLibrary: src: 'path/to/the/library/to/wrap.js' dest: 'target/wrappedLibrary.js' options: singleton: true exports: "myLibrary" classpath: "wrapped.Library" license: "path/to/library/license"
Options
classpath
Classpath of the generated Aria Templates class.
singleton
Wheter the generated class should be a singleton. Defaults to true
.
exports
Name of the variable exported by the wrapped script.
If the generated class is a singleton, this variable will be accessible at the specified classpath, otherwise it'll be used as a constructor when an instance of that classpath is created.
license
Optional license header to include along with the source code.
Usage Examples
singleton
Given the following library
var trivial = { return { return 1; } };
The following configuration
at_class: myLibrary: src: 'somewhere/trivial.js' dest: 'target/trivial.js' options: exports: "trivial" classpath: "wrapped.TrivialLibrary"
generates a class that can be used like this
Aria
simple class
The task can be used also to generate plain classes, consider the following example
var { thisname = name;}; Uselessprototype { return thisname;};
The following configuration
at_class: myLibrary: src: 'somewhere/useless.js' dest: 'target/useless.js' options: exports: "Useless" classpath: "wrapped.UselessLibrary" singleton: false
generates a class that can be used like this
Aria
Release History
0.1.0
- Creation of the project
- Support singleton and plain class
- Include license information
License
This project is licensed under the Apache License v2.0. Read the license here.