Skip to content

Commit

Permalink
chore(project): initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStamm committed Jun 9, 2015
0 parents commit 24e8afb
Show file tree
Hide file tree
Showing 22 changed files with 1,773 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
bower_components/
node_modules/
docs/api/
dist/
.idea/
test/test_old
.DS_Store
18 changes: 18 additions & 0 deletions .jshintrc
@@ -0,0 +1,18 @@
{
"browser": true,
"node": true,
"maxlen": 120,
"unused": "vars",
"strict": true,
"expr": true,
"globals": {
"describe": false,
"it": false,
"expect": true,
"beforeEach": true,
"afterEach": true,
"console": true,
"spyOn": true,
"jasmine": true
}
}
48 changes: 48 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,48 @@
# How to contribute

We love you to contribute to this project by filing bugs, helping others on the [issue tracker](https://github.com/dmn-io/table-js/issues) or by contributing features/bug fixes through pull requests.

## How to start with diagram-js


mkdir dmn.io
cd dmn.io

git clone git@github.com:dmn-io/table-js.git
(cd table-js && npm i)

// Run the test suite
grunt

// Running the test suite with every file change
TEST_BROWSERS=(Chrome|Firefox|IE) grunt auto-test

## Working with issues

We use our [issue tracker](https://github.com/dmn-io/table-js/issues) for project communication.
When using the issue tracker,

* Be descriptive when creating an issue (what, where, when and how does a problem pop up)?
* Attach steps to reproduce (if applicable)
* Attach code samples, configuration options or stack traces that may indicate a problem
* Be helpful and respect others when commenting

Create a pull request if you would like to have an in-depth discussion about some piece of code.

## Creating pull requests

We use pull requests for feature discussion and bug fixes. If you are not yet familiar on how to create a pull request, [read this great guide](https://gun.io/blog/how-to-github-fork-branch-and-pull-request).

Some things that make it easier for us to accept your pull requests

* The code adheres to our conventions
* spaces instead of tabs
* single-quotes
* ...
* The code is tested
* The `grunt` build passes (executes tests + linting)
* The work is combined into a single commit
* The commit messages adhere to our [guideline](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y)


We'd be glad to assist you if you do not get these things right in the first place.
81 changes: 81 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,81 @@
module.exports = function(grunt) {

require('load-grunt-tasks')(grunt);

/* global process */

// configures browsers to run test against
// any of [ 'PhantomJS', 'Chrome', 'Firefox', 'IE']
var TEST_BROWSERS = ((process.env.TEST_BROWSERS || '').replace(/^\s+|\s+$/, '') || 'PhantomJS').split(/\s*,\s*/g);


// project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

config: {
sources: 'lib',
tests: 'test',
dist: 'dist',
fonts: 'bower_components/font-awesome',
samples: 'example'
},

release: {
options: {
tagName: 'v<%= version %>',
commitMessage: 'chore(project): release v<%= version %>',
tagMessage: 'chore(project): tag v<%= version %>'
}
},

jshint: {
src: ['<%= config.sources %>'],

options: {
jshintrc: true,
ignores: [ '<%= config.sources %>/util/EventEmitter.js' ]
}
},

karma: {
options: {
configFile: '<%= config.tests %>/config/karma.unit.js',
},
single: {
singleRun: true,
autoWatch: false,

browsers: TEST_BROWSERS,

browserify: {
watch: false,
debug: true,
transform: [ 'brfs' ]
}
},
unit: {
browsers: TEST_BROWSERS,
debug: true
}
},

jsdoc: {
dist: {
src: [ '<%= config.sources %>/**/*.js' ],
options: {
destination: 'docs/api',
plugins: [ 'plugins/markdown' ]
}
}
}
});

// tasks

grunt.registerTask('test', [ 'karma:single' ]);

grunt.registerTask('auto-test', [ 'karma:unit' ]);

grunt.registerTask('default', [ 'jshint', 'test', 'jsdoc' ]);
};
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 camunda Services GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
@@ -0,0 +1,35 @@
> The project is in an early development stage.
> For the time being, please refer to our [comprehensive test suite](https://github.com/dmn-io/table-js/tree/master/test/spec) for usage examples.

# table-js

A toolbox for displaying and modifying tables on the web.


## Hacking the Project

To get the development setup ready execute

```
npm install
```


### Testing

Execute `grunt auto-test` to run the test suite in watch mode.

Expose an environment variable `TEST_BROWSERS=(Chrome|Firefox|IE)` to execute the tests in a non-headless browser.


### Package

Execute `grunt` to lint and test the project and to generate (preliminary) documentation.

We do not generate any build artifacts. Required parts of the library should be bundled by modelers / viewers as needed instead.


## License

MIT
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
module.exports = require('./lib/Table');
163 changes: 163 additions & 0 deletions lib/Table.js
@@ -0,0 +1,163 @@
'use strict';

var di = require('didi');


/**
* Bootstrap an injector from a list of modules, instantiating a number of default components
*
* @ignore
* @param {Array<didi.Module>} bootstrapModules
*
* @return {didi.Injector} a injector to use to access the components
*/
function bootstrap(bootstrapModules) {

var modules = [],
components = [];

function hasModule(m) {
return modules.indexOf(m) >= 0;
}

function addModule(m) {
modules.push(m);
}

function visit(m) {
if (hasModule(m)) {
return;
}

(m.__depends__ || []).forEach(visit);

if (hasModule(m)) {
return;
}

addModule(m);
(m.__init__ || []).forEach(function(c) {
components.push(c);
});
}

bootstrapModules.forEach(visit);

var injector = new di.Injector(modules);

components.forEach(function(c) {

try {
// eagerly resolve component (fn or string)
injector[typeof c === 'string' ? 'get' : 'invoke'](c);
} catch (e) {
console.error('Failed to instantiate component');
console.error(e.stack);

throw e;
}
});

return injector;
}

/**
* Creates an injector from passed options.
*
* @ignore
* @param {Object} options
* @return {didi.Injector}
*/
function createInjector(options) {

options = options || {};

var configModule = {
'config': ['value', options]
};

var coreModule = require('./core');

var modules = [ configModule, coreModule ].concat(options.modules || []);

return bootstrap(modules);
}


/**
* The main table-js entry point that bootstraps the table with the given
* configuration.
*
* To register extensions with the table, pass them as Array<didi.Module> to the constructor.
*
* @class tjs.Table
* @memberOf tjs
* @constructor
*
* @param {Object} options
* @param {Array<didi.Module>} [options.modules] external modules to instantiate with the table
* @param {didi.Injector} [injector] an (optional) injector to bootstrap the table with
*/
function Table(options, injector) {

// create injector unless explicitly specified
this.injector = injector = injector || createInjector(options);

// API

/**
* Resolves a table service
*
* @method Table#get
*
* @param {String} name the name of the table service to be retrieved
* @param {Object} [locals] a number of locals to use to resolve certain dependencies
*/
this.get = injector.get;

/**
* Executes a function into which table services are injected
*
* @method Table#invoke
*
* @param {Function|Object[]} fn the function to resolve
* @param {Object} locals a number of locals to use to resolve certain dependencies
*/
this.invoke = injector.invoke;

// init

// indicate via event


/**
* An event indicating that all plug-ins are loaded.
*
* Use this event to fire other events to interested plug-ins
*
* @memberOf Table
*
* @event table.init
*
* @example
*
* eventBus.on('table.init', function() {
* eventBus.fire('my-custom-event', { foo: 'BAR' });
* });
*
* @type {Object}
*/
this.get('eventBus').fire('table.init');
}

module.exports = Table;


/**
* Destroys the table
*
* @method Table#destroy
*/
Table.prototype.destroy = function() {
this.get('eventBus').fire('table.destroy');
};

0 comments on commit 24e8afb

Please sign in to comment.