1
.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
2
.. use this file except in compliance with the License. You may obtain a copy of
5
.. http://www.apache.org/licenses/LICENSE-2.0
7
.. Unless required by applicable law or agreed to in writing, software
8
.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
.. License for the specific language governing permissions and limitations under
20
Addons allow you to extend Fauxton for a specific use case. Usually, they
21
have the following structure::
24
| ---+ assets [optional]
26
| \ ---- my_addon.less
28
| \ ---- my_addon.html - underscore template fragments
29
| ---- resources.js - models and collections of the addon
30
| ---- routes.js - URL routing for the addon
31
| ---- views.js - views that the model provides
37
We have a `grunt-init` template that lets you create a skeleton addon,
38
including all the boiler plate code. Run ``grunt-init tasks/addon`` and answer
39
the questions it asks to create an addon::
41
± grunt-init tasks/addon
42
path.existsSync is now called `fs.existsSync`.
45
Please answer the following:
46
[?] Add on Name (WickedCool) SuperAddon
47
[?] Location of add ons (app/addons)
48
[?] Do you need an assets folder?(for .less) (y/N)
49
[?] Do you need to make any changes to the above before continuing? (y/N)
51
Created addon SuperAddon in app/addons
55
Once the addon is created add the name to the settings.json file to get it
56
compiled and added on the next install.
61
An addon can insert itself into Fauxton in two ways; via a route or via a hook.
66
An addon will override an existing route should one exist, but in all other
67
ways is just a normal backbone `route/view`. This is how you would add a whole
73
Hooks let you modify/extend an existing feature. They modify a DOM element by
74
selector for a named set of routes, for example:
76
.. code-block:: javascript
78
var Search = new FauxtonAPI.addon();
80
// Render additional content into the sidebar
83
"database/:database/_design/:ddoc/_search/:search",
84
"database/:database/_design/:ddoc/_view/:view",
85
"database/:database/_:handler"],
86
callback: searchSidebar
91
adds the `searchSidebar` callback to `#sidebar-content` for three routes.
96
First create the addon skeleton::
99
path.existsSync is now called `fs.existsSync`.
102
Please answer the following:
103
[?] Add on Name (WickedCool) Hello
104
[?] Location of add ons (app/addons)
105
[?] Do you need to make any changes to the above before continuing? (y/N)
107
Created addon Hello in app/addons
109
Done, without errors.
111
In `app/addons/hello/templates/hello.html` place:
117
Next, we'll defined a simple view in `resources.js` (for more complex addons
118
you may want to have a views.js) that renders that template:
120
.. code-block:: javascript
127
function (app, FauxtonAPI) {
130
Resources.Hello = FauxtonAPI.View.extend({
131
template: "addons/hello/templates/hello"
138
Then define a route in `routes.js` that the addon is accessible at:
140
.. code-block:: javascript
145
"addons/hello/resources"
148
function(app, FauxtonAPI, Resources) {
149
var helloRoute = function () {
150
console.log('helloRoute callback yo');
154
{"name": "Hello","link": "_hello"}
157
"#dashboard-content": new Resources.Hello({})
171
Then wire it all together in base.js:
173
.. code-block:: javascript
178
"addons/hello/routes"
181
function(app, FauxtonAPI, HelloRoutes) {
182
var Hello = new FauxtonAPI.addon();
183
console.log('hello from hello');
185
Hello.initialize = function() {
186
FauxtonAPI.addHeaderLink({title: "Hello", href: "#_hello"});
189
Hello.Routes = HelloRoutes;
194
Once the code is in place include the add on in your `settings.json` so that it
195
gets included by the `require` task. Your addon is included in one of three
196
ways; a local path, a git URL or a name. Named plugins assume the plugin is in
197
the Fauxton base directory, addons with a git URL will be cloned into the
198
application, local paths will be copied. Addons included from a local path will
199
be cleaned out by the clean task, others are left alone.