Skip to content

How to contribute to Fabric

Juriy Zaytsev edited this page Feb 19, 2015 · 17 revisions

Filing bugs

If you think you found a bug in Fabric, please create a jsfiddle with a minimal test case, demonstrating the bug. In jsfiddle please link to the latest version of Fabric.js file - add the url to external resources (please use "rawgithub.com/" instead of "raw.github.com/". Why?). You can then create an issue with the link to jsfiddle. If you're unsure about something, it's best to create a post on Fabric's google group where someone might clarify some of the things.

Patching a bug or adding feature

If you're definitely certain about a bug or feature, please open a pull request (see "Using pull requests") with a fix/addition.

For any new features, please account for:

  1. JSON serialization
  2. SVG import
  3. SVG export

For example, let's say you wish to add another property to fabric.Text. This means that this new property needs to be present in at least fabric.Text#toObject, fabric.Text#toJSON outputs, and possibly in fabric.Text#toSVG output, as well as be accounted for in fabric.Text.fromElement (if there's analogous SVG feature).

Architecture and gotchas

Before filing a bug or adding a patch, you might want to get familiar with Fabric's architecture:

gotchas:

or just general notes:

Code style, notes

  • 2 spaces, no tabs
  • semicolons required
  • explicit blocks
  • camelCase
  • fabric.document/fabric.window (not just document/window)

Documentation

Fabric uses JSDoc 3 for documentation. An example of documenting a method:

/**
 * Capitalizes a string
 * @memberOf fabric.util.string
 * @param {String} string String to capitalize
 * @return {String} Capitalized version of a string
 */
function capitalize(string) {
  return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}

Building fabric

  1. Install Node.js
  2. Build distribution file
node build.js modules=ALL exclude=gestures

Testing fabric

When fixing bugs or adding new features, it's highly advisable to add a corresponding unit test (under /test/unit, and under corresponding module). Fabric uses QUnit for unit tests. You can run entire test suite like so (from within Fabric's root directory):

> npm test

Adding documentation

Fabric uses JSDoc-style documentation, right in the code. After adding or updating certain documentation, please open a pull request. You can also add or update a page on Fabric's github wiki.

Clone this wiki locally