2013-06-10 17:54:41 +00:00
Developer guide
===============
2013-09-03 15:00:12 +00:00
Getting started
---------------
2013-06-10 17:54:41 +00:00
2013-09-03 15:00:12 +00:00
#### Pre-requisites
2013-06-12 22:58:58 +00:00
2013-09-03 15:00:12 +00:00
- [Git][1]
- [node.js/npm][2]
- [Grunt][3]
- [Bower][4]
2013-06-12 22:58:58 +00:00
2013-09-03 15:00:12 +00:00
#### Before debugging
2013-09-15 23:14:58 +00:00
- Download development tools:
npm install
- Download dependencies:
2013-09-03 15:00:12 +00:00
bower install
- To serve **StackEdit** in http://localhost/stackedit, add something like this in `httpd.conf` :
Alias /stackedit /Users/benweet/workspace/stackedit
< Directory / Users / benweet / workspace / stackedit >
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
< / Directory >
- Open Chrome without application cache:
chrome --disable-application-cache
- Run **StackEdit** in debug mode (serve original files instead of minified):
http://localhost/stackedit/?debug
#### Add new dependencies
**NOTE:** StackEdit uses [RequireJS][6] for asynchronous module definition ([AMD][7]).
- Install new dependencies using [Bower][4]:
2013-06-10 17:54:41 +00:00
2013-09-03 15:00:12 +00:00
bower install < library > --save
2013-06-10 17:54:41 +00:00
2013-09-03 15:00:12 +00:00
- Add the new dependency to [RequireJS][6] configuration file (`main.js`):
2013-06-10 17:54:41 +00:00
2013-09-03 15:00:12 +00:00
grunt bower
#### Build/minify
grunt
Architecture
------------
![Architecture diagram][5]
2013-06-10 17:54:41 +00:00
2013-06-12 22:58:58 +00:00
----------
2013-06-11 23:03:58 +00:00
### core
2013-06-10 17:54:41 +00:00
2013-06-11 23:03:58 +00:00
The `core` module is responsible for:
2013-06-10 17:54:41 +00:00
2013-09-03 15:00:12 +00:00
- creating the [UI Layout][10],
- creating the [PageDown][11] editor,
2013-06-18 22:43:52 +00:00
- loading/saving the settings,
- running periodic tasks,
- detecting the user activity,
- checking the offline status.
2013-06-18 22:55:17 +00:00
**Attributes:**
2013-06-18 22:43:52 +00:00
2013-09-03 15:00:12 +00:00
- `isOffline` : indicates the offline status of the application.
2013-06-18 22:43:52 +00:00
2013-06-18 22:55:17 +00:00
**Methods:**
2013-06-18 22:43:52 +00:00
2013-09-03 15:00:12 +00:00
- `onReady(callback)` : sets a callback to be called when all modules have been loaded and the DOM is ready.
> **NOTE:** This is preferred over [jQuery's `.ready()`][12] because it ensures that all AMD modules are loaded by [RequireJS][13]).
2013-06-18 22:43:52 +00:00
2013-09-03 15:00:12 +00:00
- `runPeriodically(callback)` : sets a callback to be called every second.
2013-06-18 22:43:52 +00:00
> **NOTE:** The callback will not run if the user is inactive or in StackEdit Viewer. User is considered inactive after 5 minutes of inactivity (mouse or keyboard).
2013-09-03 15:00:12 +00:00
- `setOffline()` : can be called by any other modules when a network timeout occurs for instance.
2013-06-18 22:55:17 +00:00
> **NOTE:** the offline status is also set by detecting the window `offline` event. `core.isOffline` is automatically set to `false` when the network is recovered.
2013-06-18 22:43:52 +00:00
2013-09-03 15:00:12 +00:00
- `initEditor(fileDesc)` : creates or refreshes the [PageDown][14] editor with a given [`FileDescriptor`][15] object.
2013-06-11 23:03:58 +00:00
2013-06-12 22:58:58 +00:00
----------
2013-06-11 23:03:58 +00:00
### fileMgr
The `fileMgr` module is responsible for:
2013-06-16 23:12:13 +00:00
- creating and deleting local files
2013-06-11 23:03:58 +00:00
- switching from one file to another
2013-06-16 23:12:13 +00:00
2013-09-03 15:00:12 +00:00
**Attributes:**
- `currentFile` : the [`FileDescriptor`][16] object that is currently edited.
**Methods:**
- `createFile(title, content)` : creates a [`FileDescriptor`][17] object, add it in the [`fileSystem`][18] map and returns it.
- `deleteFile(fileDesc)` : deletes a [`FileDescriptor`][19] object from the [`fileSystem`][20] map.
- `selectFile(fileDesc)` : selects a [`FileDescriptor`][21] object for editing.
2013-06-16 23:12:13 +00:00
#### FileDescriptor
The `FileDescriptor` class represents a local file. A `FileDescriptor` object has the following properties:
- `fileIndex` : the unique string index of the file in the file system
- `title` : the title of the document
- `content` : the content of the document
2013-09-03 15:00:12 +00:00
- `syncLocations` : a map containing all the associated [`syncAttributes`][22] objects with their `syncIndex` as a key
- `publishLocations` : a map containing all the associated [`publishAttributes`][23] objects with their `publishIndex` as a key
2013-06-16 23:12:13 +00:00
And the following methods:
2013-09-03 15:00:12 +00:00
- `addSyncLocation(syncAttributes)` : associates a [`syncAttributes`][24] object with the file
- `removeSyncLocation(syncAttributes)` : unassociates a [`syncAttributes`][25] object with the file
- `addPublishLocation(publishAttributes)` : associates a [`publishAttributes`][26] object with the file
- `removePublishLocation(publishAttributes)` : unassociates a [`publishAttributes`][27] object with the file
2013-06-16 23:12:13 +00:00
#### fileSystem
2013-09-03 15:00:12 +00:00
The `fileSystem` module is a map containing all the [`FileDescriptor`][28] objects with their `fileIndex` as a key.
2013-06-11 23:03:58 +00:00
2013-06-12 22:58:58 +00:00
----------
2013-06-11 23:03:58 +00:00
### synchronizer
2013-06-10 17:54:41 +00:00
The `synchronizer` module is responsible for:
- creating a new local file from a sync location (import)
- creating a new sync location from a local file (export)
- running 2 ways synchronization (upload and download) for all sync locations
2013-06-16 23:12:13 +00:00
#### synchronizer's providers
2013-09-03 15:00:12 +00:00
A [`provider`][29] module can be associated with the `synchronizer` module if it implements the following functions:
2013-06-16 23:12:13 +00:00
- `importFiles()` : downloads one or multiple files and create local files associated with the sync locations
- `exportFile()` : uploads a local file to a new sync location
- `syncDown()` : performs a download of all the changes operated on all sync locations
- `syncUp()` : performs an upload of a change to a sync location
#### syncAttributes
A `syncAttributes` object is an object that describes a sync location. Attributes differ from one provider to another except for the following:
- `syncIndex` : the unique string index of the publish location
2013-09-03 15:00:12 +00:00
- `provider` : the [`provider`][30] module that handles the sync location
2013-06-16 23:12:13 +00:00
2013-06-12 22:58:58 +00:00
----------
2013-06-11 23:03:58 +00:00
### publisher
2013-06-10 17:54:41 +00:00
The `publisher` module is responsible for:
- creating new publish locations
- updating existing publish locations
2013-06-11 23:03:58 +00:00
#### publisher's providers
2013-09-03 15:00:12 +00:00
A [`provider`][31] module can be associated with the `publisher` module if it implements the following functions:
2013-06-16 17:28:51 +00:00
2013-09-03 15:00:12 +00:00
- `newPublishAttributes()` : returns a new [`publishAttributes`][32] object in order to create a new publish location
2013-06-11 23:03:58 +00:00
- `publish()` : performs publishing of one publish location
2013-06-10 17:54:41 +00:00
#### publishAttributes
2013-06-16 23:12:13 +00:00
A `publishAttributes` object is an object that describes a publish location. Attributes differ from one provider to another except for the following:
2013-06-11 23:03:58 +00:00
2013-06-16 23:12:13 +00:00
- `publishIndex` : the unique string index of the publish location
2013-09-03 15:00:12 +00:00
- `provider` : the [`provider`][33] module that handles the publish location
2013-06-11 23:03:58 +00:00
- `format` : the publishing format for the publish location. It can be:
- `markdown` for Markdown format
- `html` for HTML format
- `template` for template format
2013-06-16 17:28:51 +00:00
----------
2013-06-11 23:03:58 +00:00
2013-06-10 17:54:41 +00:00
2013-06-16 17:28:51 +00:00
### provider
2013-06-10 17:54:41 +00:00
2013-05-29 21:45:40 +00:00
2013-05-29 22:10:25 +00:00
2013-05-29 20:01:33 +00:00
> Written with [StackEdit](http://benweet.github.io/stackedit/).
2013-09-03 15:00:12 +00:00
[1]: http://git-scm.com/
[2]: http://nodejs.org/
[3]: http://gruntjs.com/
[4]: http://bower.io/
[5]: http://benweet.github.io/stackedit/doc/img/architecture.png "Architecture diagram"
[6]: http://requirejs.org/ "RequireJS"
[7]: http://en.wikipedia.org/wiki/Asynchronous_module_definition "Asynchronous module definition"
[8]: http://jquery.com/
[9]: http://underscorejs.org/
[10]: http://layout.jquery-dev.net/ "UI Layout"
[11]: https://code.google.com/p/pagedown/ "PageDown"
[12]: http://api.jquery.com/ready/
[13]: http://requirejs.org/ "RequireJS"
[14]: https://code.google.com/p/pagedown/ "PageDown"
[15]: #filedescriptor
[16]: #filedescriptor
[17]: #filedescriptor
[18]: #filesystem
[19]: #filedescriptor
[20]: #filesystem
[21]: #filedescriptor
[22]: #syncattributes
[23]: #publishattributes
[24]: #syncattributes
[25]: #syncattributes
[26]: #publishattributes
[27]: #publishattributes
[28]: #filedescriptor
[29]: #provider
[30]: #provider
[31]: #provider
[32]: #publishattributes
[33]: #provider