Merge branch 'master' of github.com:benweet/stackedit

This commit is contained in:
benweet 2013-12-03 00:30:39 +00:00
commit d9fbdb49ac
2 changed files with 254 additions and 47 deletions

View File

@ -9,7 +9,7 @@ StackEdit is a free, open-source Markdown editor based on PageDown, the Markdown
> - Full access to Dropbox or Google Drive is required to be able to import any document in StackEdit. Imported documents are downloaded in your browser and are not transmitted to a server.
### StackEdit can:
- Manage multiple Markdown documents online or offline
- Export your documents in Markdown, HTML or PDF and format it using a template
- Synchronize your Markdown documents in the Cloud
@ -47,7 +47,7 @@ StackEdit is a free, open-source Markdown editor based on PageDown, the Markdown
[1]: https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Storage#localStorage
[2]: https://github.com/benweet/stackedit/blob/master/WELCOME.md#welcome-to-stackedit---welcome "Welcome document"
[2]: https://github.com/benweet/stackedit/blob/master/public/res/WELCOME.md#welcome-to-stackedit---welcome "Welcome document"
[3]: https://github.com/benweet/stackedit/blob/master/doc/developer-guide.md#developer-guide "Developer guide"
[4]: https://github.com/benweet/stackedit/blob/master/doc/theming.md#stackedit-theming-guide "Theming guide"
[5]: https://stackedit.io/ "StackEdit"

View File

@ -62,19 +62,27 @@ Getting started
docker build -t my-stackedit-image .
docker run -p 3000 my-stackedit-image
> **NOTE:** OAuth authorizations work out of the box for address http://localhost/ except for WordPress. To allow an other address, you have to add specific keys at the end of `constants.js` and eventually to set up specific proxies with the corresponding key/secret pairs ([WordPress Proxy][9], [Tumblr Proxy][10] and [Gatekeeper][11]).
> **NOTE:** OAuth authorizations work out of the box for address `http://localhost/` except for WordPress. To allow an other address, you have to add specific keys at the end of `constants.js` and eventually to set up specific proxies with the corresponding key/secret pairs ([WordPress Proxy][9], [Tumblr Proxy][10] and [Gatekeeper][11]).
Architecture
------------
![Architecture diagram][13]
![Architecture diagram][12]
The modules are loaded in the following order:
The modules are loaded by RequireJS in the following order:
1. 3rd party libraries (jQuery, underscore.js...)
2. `Extension` class and objects
3.
1. The 3rd party libraries (jQuery, underscore.js...)
2. The `Extension` objects
3. The `EventMgr` module
4. The `core` module
5. The `fileMgr` module and the `helpers` modules
6. The `provider` modules
7. The `publisher` and `synchronizer` modules
This is important to notice in order to avoid circular dependencies. For instance, if an `Extension` is declared with the `core` module as a dependency, RequireJS will inject `undefined` instead of the actual module.
Any module though can access any dependencies by implementing the proper [injection listener][13] provided by the `eventMgr`.
----------
@ -96,7 +104,7 @@ The `core` module is responsible for:
**Methods:**
- `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()`][17] because it ensures that all AMD modules are loaded by [RequireJS][18]).
> **NOTE:** This is preferred over [jQuery's `.ready()`][17] because it ensures that all AMD modules are loaded by [RequireJS][18].
- `runPeriodically(callback)`: sets a callback to be called every second.
> **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).
@ -212,10 +220,34 @@ A `publishAttributes` object is an object that describes a publish location. Att
### eventMgr
The `eventMgr` module is responsible for receiving and dispatching events in **StackEdit**. The following functions of the `eventMgr` module will trigger events of the same name. Extensions can listen to these events by implementing functions with the same name. The function `addListener(eventName, callback)` of the `eventMgr` module can be used by any other module to listen to these events.
The `eventMgr` module is responsible for receiving and dispatching events. Below is the list of all events signatures.
Most events (those that are triggered outside the `eventMgr` module) can be triggered by calling methods of the same name in the `eventMgr` module. For example:
```js
eventMgr.onMessage('StackEdit is awesome!');
```
The method `addListener(eventName, callback)` of the `eventMgr` module can be used to listen to these events (except those that can only be handled by `Extension` objects). For example:
```js
eventMgr.addListener('onMessage', function(message) {
alert(message);
});
```
`Extension` objects have the possibility to listen to those events by implementing methods of the same name. For example:
```js
userCustom.onMessage = function(message) {
alert(message);
};
```
#### Core events:
----------
#### Core events
- **`onReady()`**
@ -223,7 +255,7 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
> Triggered by the `core` module.
> This is preferred over [jQuery's `.ready()`][39] because it ensures that all modules are loaded by [RequireJS][40].
> This is preferred over [jQuery's `.ready()`][39] because it ensures that all modules have been loaded by RequireJS.
- **`onMessage(message)`**
@ -248,12 +280,12 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
> Triggered by the `core` module.
- **`onAsyncRunning()`**
- **`onAsyncRunning(isRunning)`**
Some asynchronous tasks have just started or stopped.
- `isRunning`: true if started, false if stopped.
> Triggered by the `AsyncTask` module.
> Triggered by the `AsyncTask` module.
- **`onPeriodicRun()`**
@ -280,9 +312,13 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
A hook allowing enabled extensions to initialize.
> Triggered by the `eventMgr` module. Only `Extension` objects can handle this event.
> This event is triggered before `onReady` event and just after the `config` and `enabled` extensions properties have been set by the `eventMgr`.
#### Module creation events:
----------
#### Module injection
- **`onFileMgrCreated(fileMgr)`**
@ -314,7 +350,9 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
> Triggered by the `eventMgr` module.
#### Operations on files:
----------
#### Operations on files
- **`onFileCreated(fileDesc)`**
@ -354,46 +392,207 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
- **`onContentChanged(fileDesc)`**
The content of a [`FileDescriptor`][51] object has been modified.
- `fileDesc`: the [`FileDescriptor`][52] object.
- **`onTitleChanged()`**
- **`onTitleChanged(fileDesc)`**
The content of a [`FileDescriptor`][52] object has been modified.
The content of a [`FileDescriptor`][53] object has been modified.
- `fileDesc`: the [`FileDescriptor`][54] object.
- **`onFoldersChanged()`**
The folders structure has changed.
----------
#### Sync events
- **`onSyncRunning(isRunning)`**
A synchronization job has just started or stopped.
- `isRunning`: true if started, false if stopped.
> Triggered by the `synchronizer` module.
> A synchronization job is the action to download and upload all detected changes for all sync locations of all documents.
- **`onSyncSuccess()`**
A synchronization job has successfully finished.
> Triggered by the `synchronizer` module.
> A synchronization job is the action to download and upload all detected changes for all sync locations of all documents.
- **`onSyncImportSuccess(fileDescList, provider)`**
The import of documents has successfully finished.
- `fileDescList`: the list of [`FileDescriptor`][55] objects that have been created.
- `provider`: the [`provider`][56] module that handled the import.
> Triggered by the [`provider`][57] module that handled the import.
> An import is the action to download multiple files and to create, for each, one [`FileDescriptor`][55] objects with one sync location.
- **`onSyncExportSuccess(fileDesc, syncAttributes)`**
The export of one document has successfully finished.
- `fileDesc`: the [`FileDescriptor`][58] object that has been exported.
- `syncAttributes`: the descriptor object of the new sync location.
> Triggered by the `synchronizer` module.
> An export is the action to upload one file and to create one new sync location associated with one existing `FileDescriptor`][55] object.
- **`onSyncRemoved(fileDesc, syncAttributes)`**
A sync location has been removed from a [`FileDescriptor`][59] object.
- `fileDesc`: the [`FileDescriptor`][60] object.
- `syncAttributes`: the descriptor object of the removed sync location.
----------
#### Operations on folders:
- `onFoldersChanged()`:
#### Publish events
#### Sync events:
- `onSyncRunning()`:
- `onSyncSuccess()`:
- `onSyncImportSuccess()`:
- `onSyncExportSuccess()`:
- `onSyncRemoved()`:
- **`onPublishRunning(isRunning)`**
#### Publish events:
- `onPublishRunning()`:
- `onPublishSuccess()`:
- `onNewPublishSuccess()`:
- `onPublishRemoved()`:
A document publication job has just started or stopped.
- `isRunning`: true if started, false if stopped.
> Triggered by the `publisher` module.
> A publication job is the action to upload changes on multiple publish locations associated with one `FileDescriptor`][55] object.
#### Operations on Layout:
- `onLayoutConfigure()`:
- `onLayoutCreated()`:
- `onLayoutResize()`:
- `onCreateButton()`:
- `onCreateEditorButton()`:
- `onCreatePreviewButton()`:
- **`onPublishSuccess(fileDesc)`**
#### Operations on PageDown:
- `onPagedownConfigure()`:
- `onSectionsCreated()`:
- `onMarkdownTrim()`:
A document publication job has successfully finished.
- `fileDesc`: the [`FileDescriptor`][60] object that has been published.
> Triggered by the `publisher` module.
> A publication job is the action to upload changes on multiple publish locations associated with one `FileDescriptor`][55] object.
- **`onNewPublishSuccess(fileDesc, publishAttributes)`**
#### Operation on ACE:
- `onAceCreated()`:
A new publish location has been successfully created.
- `fileDesc`: the [`FileDescriptor`][60] object that has been published.
- `publishAttributes`: the descriptor object of the new publish location.
> Triggered by the `publisher` module.
- **`onPublishRemoved(fileDesc, publishAttributes)`**
A publish location has been removed from a [`FileDescriptor`][59] object.
- `fileDesc`: the [`FileDescriptor`][60] object.
- `publishAttributes`: the descriptor object of the removed publish location.
> Triggered by the `publisher` module.
----------
#### Operations on UI Layout
- **`onLayoutConfigure(layoutConfig)`**
The layout is about to be configured.
- `layoutConfig`: the configuration object of the UI Layout library.
> Triggered by the `core` module.
- **`onLayoutCreated(layout)`**
The layout has just been created.
- `layout`: the layout object of the UI Layout library.
> Triggered by the `core` module.
- **`onLayoutResize(paneName)`**
One pane of the layout has been resized.
- `paneName`: the name of the resized layout pane.
> Triggered by the `core` module.
- **`onCreateButton()`**
Allows extensions to add their own buttons in the navigation bar. Implemented listeners have to return an HTML button element. For example:
userCustom.onCreateButton = function() {
var button = $('<button class="btn btn-success"><i class="icon-rocket"></i></button>');
button.click(function() {
eventMgr.onMessage('Booom!');
});
return button[0];
};
> Triggered by the `eventMgr` module. Only `Extension` objects can handle this event.
- **`onCreateEditorButton()`**
Allows extensions to add their own buttons in the side bar. Implemented listeners have to return an HTML button element. See `onCreateButton` for a concrete example.
> Triggered by the `eventMgr` module. Only `Extension` objects can handle this event.
- **`onCreatePreviewButton()`**
Allows extensions to add their own buttons over the preview. Implemented listeners have to return an HTML button element. See `onCreateButton` for a concrete example.
> Triggered by the `eventMgr` module. Only `Extension` objects can handle this event.
----------
#### Operations on PageDown
- **`onPagedownConfigure(editor)`**
The Pagedown editor is about to be created.
- `editor`: the Pagedown editor object before `run` has been called.
> Triggered by the `core` module.
- **`onAsyncPreview(callback)`**
Called after Pagedown's synchronous rendering to trigger extra asynchronous rendering (such as MathJax). Implemented listeners have to call the callback parameter after processing in order other `onAsyncPreview` listeners to run.
- `callback`: the callback to call at the end of the asynchronous processing.
> Triggered by the `eventMgr` module. Only `Extension` objects can handle this event.
- **`onPreviewFinished(html)`**
Called after every `onAsyncPreview` listeners have been called.
- `html`: the finally rendered HTML.
- **`onSectionsCreated(sectionList)`**
The Markdown has been split into sections before rendering.
- `sectionList`: the list of section objects. Each section object contains:
- `text`: the markdown substring contained in the section.
- `textWithDelimiter`: the text with an added delimiter.
> Triggered by the `markdownSectionParser` extension.
- **`onMarkdownTrim(offset)`**
The Markdown has been left trimmed by a certain number of character.
- `offset`: the number of characters that have been removed.
> Triggered by the `yamlFrontMatterParser` extension.
----------
#### Operation on ACE
- **`onAceCreated(aceEditor)`**
The ACE editor has just been created.
- `aceEditor`: the ACE editor object.
> Triggered by the `core` module.
@ -411,8 +610,8 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
[9]: https://github.com/benweet/stackedit-wordpress-proxy
[10]: https://github.com/benweet/stackedit-tumblr-proxy
[11]: https://github.com/prose/gatekeeper
[12]: http://benweet.github.io/stackedit/doc/img/architecture.png "Architecture diagram"
[13]: https://lh6.googleusercontent.com/-sr6zRtyaoUk/Un5qSakOzPI/AAAAAAAAFC0/oI5If5fI9Gw/s0/StackEdit%252520architecture%252520-%252520New%252520Page%252520%2525283%252529.png "StackEdit architecture"
[12]: https://lh6.googleusercontent.com/-sr6zRtyaoUk/Un5qSakOzPI/AAAAAAAAFC0/oI5If5fI9Gw/s0/StackEdit%252520architecture%252520-%252520New%252520Page%252520%2525283%252529.png "StackEdit architecture"
[13]: #module-injection
[14]: http://layout.jquery-dev.net/ "UI Layout"
[15]: http://ace.c9.io
[16]: https://code.google.com/p/pagedown/ "PageDown"
@ -451,4 +650,12 @@ The `eventMgr` module is responsible for receiving and dispatching events in **S
[49]: #filedescriptor
[50]: #filedescriptor
[51]: #filedescriptor
[52]: #filedescriptor
[52]: #filedescriptor
[53]: #filedescriptor
[54]: #filedescriptor
[55]: #filedescriptor
[56]: #provider
[57]: #provider
[58]: #filedescriptor
[59]: #filedescriptor
[60]: #filedescriptor