Demo Apps and App Developer Tutorial

Introduction

What can I build with this platform?

The webLurch architecture has three tiers, applications at the top, built on the Lurch Web Platform, which in turn is built on the WYSIWYG editor TinyMCE.

What are groups?

The crux of the user interface for the desktop version of Lurch is the ability for the user to mark portions of a document as meaningful with groups.

Groups are represented on screen as "bubbles," as in the images below. Thus the terms "group" and "bubble" are sometimes used interchangeably, but technically "group" is the term for the object in memory, and "bubble" its representation on screen.

Examples:

Read about about the importance of this user interface paradigm in a blog post about the desktop version of Lurch.

Demo Apps

The content of this section got large enough to deserve its own page.

Tutorial

Build a Lurch Web Application as follows.

This section gives step-by-step instructions for creating your own Lurch Web Application. By the end of this section, you will have completed Phases 1 and 2 on the list, and will know where to go to explore Phase 3.

Phase 1: A first app (and a very simple one)

  1. Get a copy of this repository set up on your local machine. See instructions here. You may be able to forge ahead even if you've never tried to learn literate CoffeeScript, because the language is extremely readable. But you can learn its basics at that link before proceeding if you prefer.
  2. Ensure that you can build and run the Simple Example app, as follows:
    • Compile the app and start a local web server by following the repository setup instructions in the previous bullet point.
    • Visit http://localhost:8000/app/simple-example.html to see the simple example app in action.
  3. Make a copy of that app to use as the basis for your own.
    • In the app/ subfolder, make copies of the files simple-example.html and simple-example-solo.litcoffee, naming them something like myapp.html and myapp-solo.litcoffee.
    • Re-run cake app from the terminal to compile your new .litcoffee file. (You will need to do this after each change to the source.) This should create several files that start with app/myapp-solo.
    • Change the last <script> tag in the .html file you just created so that it imports myapp-solo.min.js file rather than simple-example-solo.min.js.
    • Visit http://localhost:8000/app/myapp.html to ensure that this worked. It should look exactly like the simple app you already saw.
  4. Edit myapp-solo.min.js.
    • The file begins with a lot of documentation, and then the first line of code is setAppName 'ExampleApp'. Change the contents of the string to your app's name.
    • Rebuild using cake app and revisit the page to ensure that the app name in the browser's tab has changed to your app's name.

You've created a (very simple) app! And you know how to change your app's code, rebuild, and visit your updated app. So what kinds of code changes are possible? Let's see.

Phase 2: Changing or adding group types

The individual bubbles you see in the document are the visual representation of what, under the hood, are called "groups." Each app has a different set of group types that the user may insert in the document, depending on the needs of the application. Examples:

If we look at the code in your app that defines group types, stripping away all the documentation, it looks like the following.

window.groupTypes = [
    name : 'reporter'
    text : 'Simple Event Reporter'
    imageHTML : '[ ]'
    openImageHTML : '['
    closeImageHTML : ']'
    tagContents : ( group ) ->
        "#{group.contentAsText()?.length} characters"
    contentsChanged : ( group, firstTime ) ->
        console.log 'This group just changed:', group.contentAsText()
]

All of this is fully documented in the original file, so I do not repeat here what any of it means. But note that this is simply the assignment to a global variable of an array of group type data. You could extend it to add another group type as follows.

window.groupTypes = [
    #
    # This code is the same as before:
    #
    name : 'reporter'
    text : 'Simple Event Reporter'
    imageHTML : '[ ]'
    openImageHTML : '['
    closeImageHTML : ']'
    tagContents : ( group ) ->
        "#{group.contentAsText()?.length} characters"
    contentsChanged : ( group, firstTime ) ->
        console.log 'This group just changed:', group.contentAsText()
    #
    # Here begins the new code:
    #
,
    name : 'myNewGroupType'
    text : 'My New Group Type'
    imageHTML : '{}'
    openImageHTML : '{'
    closeImageHTML : '}'
    tagContents : ( group ) -> 'every tag has this content'
    # no event handler for changes to group contents
]

Rebuilding your app and reloading it in the browser should then let you insert either of the two kinds of groups. Each type should have its own button on the toolbar.

By simply extending the list above, you can define any set of group types you see fit in your application. Note that the open and close HTML can be arbitrary HTML, including (small) images and font colors and styles.

The only question that remains is how to make your groups do something useful.

Phase 3: Adding interactivity to your groups

What else can your app do? Here are many examples, each with a link to where you can read more information and see example code.

Report information about the group on the bubble's tag

Customize a group's color

Store and retrieve custom data in a Group object

Find what groups are in the document

Pushing complex computations into the background

Extending the menus that appear when users right-click a group or click its bubble tag

Adding new buttons to the editor toolbar

Adding new menu items to the editor's menus

Showing dialog boxes

Adding decorations to group boundaries

Other functionality

In this section I document other configuration possibilities beyond those mentioned above, things that didn't fit neatly into the above categories.

To run any code after the editor has been set up, assign a function to the global variable window.afterEditorReady. Your function should accept a single parameter, editor, which will be the editor object that was just initialized. Your function will be called at the end of the TinyMCE editor "init" event.


This tutorial was written by Nathan Carter. Feel free to contact me with questions. I would love to know how we can help get you started coding on the Lurch Web Platform.