Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Commit

Permalink
Moves code generation docs up the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
devraj committed Apr 3, 2015
1 parent 6f13d23 commit ef24b5d
Showing 1 changed file with 45 additions and 43 deletions.
88 changes: 45 additions & 43 deletions source/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,51 @@ Prestans then provides the following additional methods:
* ``getJSONObject`` returns an ``Object``
* ``getJSONString`` returns a ``String``


Attribute Change Events
-----------------------

Models generated by Prestans raise the ``prestans.types.Model.EventType.ATTRIBUTE_CHANGED`` event whenever a mutator is fired. You can listen for this event on any instance of a Prestans Model subclass:

.. code-block:: javascript
var album_ = new pdemo.data.model.Album();
// Use the Event Handler provided by a Google Closure Component
this.getHandler().listen(album_, prestans.types.Model.EventType.ATTRIBUTE_CHANGED, function(event){
if(event.getIdentifier() == "name") {
// name changed, I might update the user interface
}
});
``event.getIdentifier()`` provides you a camel cased representation of the attribute that changed.

Generating Model Code
---------------------

Based on the server model definition Prestans can generate JavaScript versions of your models. You can use this in tandem with the Xhr client to ensure the data you receive from is intact and matches the business rules (hence ensuring nothing went wrong on the way), and that the data you send to the server will pass the validation test.

The generated model code centralizes references to JSON keys allowing you to access the data via accessors and mutators (which also validate the data) allowing `Closure Compiler <http://github.com/google/closure-compiler>`_ to optimise your code.

Prestans provides a utility called pride (Prestans Integrated Development Environment) which resides in `/usr/local/bin` and is responsible for generating the Model stubs. You provide it a reference to the Python file that contains your Model definitions along with target name spaces and paths and for each server Model definition it produces a JavaScript Model or Attribute Filter.

To generate models using pride use the following command:

.. code-block:: bash
pride gen --template closure.model --model pdemo/rest/models.py --namespace pdemo.data.model --output client/pdemo/data/model
Prestans assumes that your filters files live in the same level as models i.e ``pdemo.data.model`` corresponds to ``pdemo.data.filter``, you can optionally provide a ``--filter-namespace`` to override the default filter namespace

To generate filters using pride use the following command:

.. code-block:: bash
pride gen --template closure.filter --model pdemo/rest/models.py --namespace pdemo.data.filter --output client/pdemo/data/filter
REST Client
===========

Expand Down Expand Up @@ -293,46 +338,3 @@ Reading a Response
* ``responseBody`` JSON Object (Optional)


Generating Model Code
=====================

Based on the server model definition Prestans can generate JavaScript versions of your models. You can use this in tandem with the Xhr client to ensure the data you receive from is intact and matches the business rules (hence ensuring nothing went wrong on the way), and that the data you send to the server will pass the validation test.

The generated model code centralizes references to JSON keys allowing you to access the data via accessors and mutators (which also validate the data) allowing `Closure Compiler <http://github.com/google/closure-compiler>`_ to optimise your code.

Prestans provides a utility called pride (Prestans Integrated Development Environment) which resides in `/usr/local/bin` and is responsible for generating the Model stubs. You provide it a reference to the Python file that contains your Model definitions along with target name spaces and paths and for each server Model definition it produces a JavaScript Model or Attribute Filter.

To generate models using pride use the following command:

.. code-block:: bash
pride gen --template closure.model --model pdemo/rest/models.py --namespace pdemo.data.model --output client/pdemo/data/model
Prestans assumes that your filters files live in the same level as models i.e ``pdemo.data.model`` corresponds to ``pdemo.data.filter``, you can optionally provide a ``--filter-namespace`` to override the default filter namespace

To generate filters using pride use the following command:

.. code-block:: bash
pride gen --template closure.filter --model pdemo/rest/models.py --namespace pdemo.data.filter --output client/pdemo/data/filter
Attribute Change Events
-----------------------

Models generated by Prestans raise the ``prestans.types.Model.EventType.ATTRIBUTE_CHANGED`` event whenever a mutator is fired. You can listen for this event on any instance of a Prestans Model subclass:

.. code-block:: javascript
var album_ = new pdemo.data.model.Album();
// Use the Event Handler provided by a Google Closure Component
this.getHandler().listen(album_, prestans.types.Model.EventType.ATTRIBUTE_CHANGED, function(event){
if(event.getIdentifier() == "name") {
// name changed, I might update the user interface
}
});
``event.getIdentifier()`` provides you a camel cased representation of the attribute that changed.

0 comments on commit ef24b5d

Please sign in to comment.