|
| 1 | +# Contributing |
| 2 | + |
| 3 | +**Note:** This guide is a work in progress. Feel free to [submit an issue](https://github.com/SoapBox/jQuery-linkify/issues/new) if anything is confusing or unclear. |
| 4 | + |
| 5 | +## How linkify works |
| 6 | + |
| 7 | +_TODO: Insert diagram here_ |
| 8 | + |
| 9 | +Linkify uses a two stage lexicographical analysis to detect patterns in plain text. |
| 10 | + |
| 11 | +The first stage, called the scanner, takes the input string and generates encompassing tokens that aggregate different types of components like domain names and TLDs. For example, substings like `http:` or `com` are converted into tokens named `PROTOCOL` and `TLD`, respectively. |
| 12 | + |
| 13 | +The second stage, the parser, takes this array of tokens and aggregates them into complete entities that are either become links or do not. For example, the tokens `PROTOCOL`, `SLASH`, `SLASH`, `DOMAIN`, `TLD` (appearing in that order) are grouped into a `URL` entity. These groups are called multitokens. |
| 14 | + |
| 15 | +A multi token is either a link or not a link. Basic linkify comes with these multitokens |
| 16 | + |
| 17 | +* **`TEXT`** is plain text (that contains no linkable entities) |
| 18 | +* **`NL`** represents a single newline character |
| 19 | +* **`EMAIL`** email address |
| 20 | +* **`URL`** |
| 21 | + |
| 22 | +The latter two are converted to links. `NL` is in some cases converted to a `<br>` HTML tag. |
| 23 | + |
| 24 | +You can use the Token class system to [create plugins](#building-plugins). |
| 25 | + |
| 26 | +## Style |
| 27 | + |
| 28 | +* ES6 Syntax (except tests for now) |
| 29 | +* Hard tabs with a width of 4 characters |
| 30 | + |
| 31 | +As usualy, try to keep it consistent with what's already there. |
| 32 | + |
| 33 | +## Development |
| 34 | + |
| 35 | +### Setup |
| 36 | + |
| 37 | +1. Install the latest version of [Node.js](https://nodejs.org/) |
| 38 | +2. Install the [gulp.js](http://gulpjs.com/) build system from the Terminal |
| 39 | + * `npm install -g gulp` |
| 40 | + |
| 41 | +### Building |
| 42 | + |
| 43 | +Linkify is built and tested in the command line. Build tasks have the following format. |
| 44 | + |
| 45 | +``` |
| 46 | +gulp <task> |
| 47 | +``` |
| 48 | + |
| 49 | +Here are the primary build tasks used for development. See [gulpfile.js](https://github.com/SoapBox/jQuery-linkify/blob/master/gulpfile.js) for the complete list. |
| 50 | + |
| 51 | +* **`build`** transpiles ES6 to ES5 (via [Babel](http://babeljs.io/)) from `src/` into `lib/`. The lib folder will be published to [NPM](https://www.npmjs.com/). Also generates browser-ready scripts (globals and [AMD](http://requirejs.org/docs/whyamd.html)) into the `build/` folder. |
| 52 | +* **`dist`** copies and compresses the contents of `build/` into `dist/`. The contents of the dist folder will be published to [Bower](http://bower.io/). |
| 53 | +* **default** (run `gulp` without arguments) runs `build` and begins watching files for changes (rebuilding when they do) |
| 54 | + |
| 55 | +### Running tests |
| 56 | + |
| 57 | +Here are the tools used for testing linkify: |
| 58 | + |
| 59 | +* [Mocha](http://mochajs.org/) is our primary test case framework |
| 60 | +* [JSHint](http://jshint.com/) for code linting |
| 61 | +* [Istanbul](https://gotwarlost.github.io/istanbul/) for code coverage analysis |
| 62 | +* [Karma](http://karma-runner.github.io/0.12/index.html) is our browser test runner |
| 63 | +* [Sauce Labs](https://saucelabs.com/) for cross-browser testing |
| 64 | + |
| 65 | +These are all configured to run on gulp. Tasks `mocha` and `jshint` are the most basic you can run. Other tasks include: |
| 66 | + |
| 67 | +* `test` transpiles the code and runs JSHint and Mocha |
| 68 | +* `coverage` runs Istanbul code coverage on the Mocha tests |
| 69 | +* Karma has a number of tasks that allow you to run Mocha tests on different browsers (via [Browserify](http://browserify.org/)) |
| 70 | + * `karma` runs tests on the [PhantomJS](http://phantomjs.org/) headless browser |
| 71 | + * `karma-chrome` runs tests on [Google Chrome](http://www.google.com/chrome/) |
| 72 | + * `karma-ci` (or `test-ci`) runs Sauce Labs cross-browser tests (Sauce Labs environment configuration required) |
| 73 | + |
| 74 | +### Building plugins |
| 75 | + |
| 76 | +**Caution:** The plugin development API is in its very early stages and only supports very basic plugins. Updated features, APIs, and docs are in the works. |
| 77 | + |
| 78 | +Check out the sample [Hashtag plugin](https://github.com/SoapBox/jQuery-linkify/blob/2.0/src/linkify/plugins/hashtag.js) for an idea of how plugins are made. You have access to all the previously described tokens from the `linkify` variable. And should be able to extend them as necessary. |
| 79 | + |
| 80 | +If you decide that your plugin can be used by many people, you can add them to `src/linkify/plugins/`. Make sure you also create build templates for your plugin inside `templates/linkify/plugins/`. Follow the format of the existing files. |
| 81 | + |
| 82 | +Any plugin you add to `src/linkify/plugins/` will automatically be added to the build system. |
0 commit comments