Components: Difference between revisions

From Lifeguide Wiki
Jump to navigation Jump to search
(New page: =Developing with Components= ==Read Me First!== Please note that the following features are currently in development, and may not be available in your version of LifeGuide. ==Introducti...)
(No difference)

Revision as of 18:46, 20 April 2011

Developing with Components

Read Me First!

Please note that the following features are currently in development, and may not be available in your version of LifeGuide.

Introduction

This guide introduces a selection of new additions to the LifeGuide authoring tool designed to help you structure and organise your LifeGuide interventions and Logic code.

With these extensions, you can separate your code into manageable pieces, share files between interventions to maintain consistency, and even construct interventions from other, smaller interventions that can be built and tested separately.

These extensions have no additional system requirements, and should not affect any of your existing interventions.

Modules and Inclusion

What is a Module?

A module is a text file containing sections of LifeGuide Logic code. You can use modules to help you organise large amounts of code. On its own, a module is useless – it must be ‘included’ somewhere in the main intervention, or in another module. This is done with the ‘include’ command.

Note: An intervention can have only one main logic file, but it can have any number of modules.

Creating a New Module

In order to create a module, click the 'New Module' icon in the toolbar.

File:Example.jpg

This will trigger the ‘New Module’ wizard.

File:Example.jpg

Choose a name for your new module. You can choose to have simple start-up instructions at the top of the file, and the editor can also prepare the file as a Begin-End Section, if you want to organise the code structure for use with a Goto statement.

Click ‘Finish’, and you will then be presented with a text editor view of your new module.

NOTE: The main logic file name always ends with ‘.lgil’, and module file names always end with ‘.lgim’

Including a Module

The ‘include’ command takes the name of a module, and inserts the code from that module at that point. The resulting code is used to create the final intervention.

File:Example.jpg

Note that this command only accepts a module name in “quotation marks”.

Project References

You can create ‘references’ between LifeGuide projects in order to combine them and share their files. For example, if Project A creates a reference to Project B, all of Project B’s files will be copied into Project A and updated on every change, including its main intervention code, modules, pages, templates and images. The reference is one-way: Project B can now be seen as a ‘component’ of Project A.

Creating Project References

Follow these steps to view and change a project’s references:

  • Right-click on the project and click ‘Properties’
  • Click ‘Project References’
  • This project will have access to the files of any projects that are checked in this list. Check/uncheck projects in this list to create/remove references.
  • Click ‘OK’ when finished

Using Referenced Projects

Files from another project will be prefixed by the name of their project. For example, if Project1 creates a reference to Project2, Project2’s files will appear like this:

Project2_Page

They can be accessed using their full name.

show Project2_Page

This applies to pages, images, and even modules of logic code.

You can even treat a referenced project as a single unit, inserting the entire intervention in one go, using the ‘import’ command:

import “Project2”

This is the same as the command:

include “Project2_intervention”

Remote files will be updated every time a change is made in their project. If you want to stop this from happening and create a detached ‘local copy’ of a file, simply give it a new, unique name.

Example

Project1 contains files Page1.lgpl and intervention.lgil

Project2 contains files Page2.lgpl and intervention.lgil

Project1 creates a reference to Project2

Project1 now contains Page1.lgpl, intervention.lgil, Project2_Page2.lgpl and Project2_intervention.lgim

Remember, interventions can have only one main logic file, so Project2_intervention becomes a module, and can be treated as a module.

Project2_Page2.lgpl and Project2_intervention.lgim will be updated every time Project2 is modified.

Troubleshooting

This is a stub - only a few questions have been added. This section should be expanded as new questions arise.

Q: I’ve created a module and given it some code, but I’m not seeing any change to the intervention.

A: Each intervention is controlled by the code in its main intervention logic file. Therefore, any modules must be included by the main intervention logic file, or by another module that is included in the main intervention logic file. Make sure that your module has been included, and at the desired point.

Q: Is it possible to include a module more than once?

A: Possibly. Remember that the ‘show’ command cannot be used to declare a page more than once. Modules are not intended to be reusable, but rather to help you as a developer understand and organise large volumes of LifeGuide Logic code.