Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge branch 'docs_remove_init_controllers' into HEAD
Browse files Browse the repository at this point in the history
Conflicts:
	docs/dev_guide/api_overview/mojito_addons.rst
	docs/dev_guide/code_exs/adding_assets.rst
	docs/dev_guide/code_exs/binding_events.rst
	docs/dev_guide/code_exs/route_config.rst
	docs/dev_guide/getting_started/index.rst
	docs/dev_guide/getting_started/mojito_getting_started_tutorial.rst
	docs/dev_guide/intro/mojito_configuring.rst
	docs/dev_guide/intro/mojito_mvc.rst
	docs/dev_guide/topics/index.rst
	docs/dev_guide/topics/mojito_assets.rst
	docs/dev_guide/topics/mojito_composite_mojits.rst
	docs/dev_guide/topics/mojito_data.rst
	docs/dev_guide/topics/mojito_extensions.rst
	docs/dev_guide/topics/mojito_framework_mojits.rst
	docs/dev_guide/topics/mojito_logging.rst
	docs/dev_guide/topics/mojito_resource_store.rst
	docs/dev_guide/topics/mojito_run_dyn_defined_mojits.rst
  • Loading branch information
Joe Catera committed Nov 13, 2012
2 parents 97f5a62 + 3447b5a commit df58c4f
Show file tree
Hide file tree
Showing 43 changed files with 998 additions and 1,085 deletions.
3 changes: 0 additions & 3 deletions docs/dev_guide/api_overview/mojito_action_context.rst
Expand Up @@ -29,9 +29,6 @@ One of the most common methods used from an instance of the ``ActionContext`` cl
* @constructor
*/
Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
},
/**
* Method corresponding to the 'index' action.
*
Expand Down
20 changes: 13 additions & 7 deletions docs/dev_guide/api_overview/mojito_addons.rst
Expand Up @@ -2,13 +2,15 @@
Action Context Addons
=====================

<<<<<<< HEAD
The Action Context uses a mechanism called addons to provide functionality that lives both
on the server and client. Each addon provides additional functions through a namespacing
object, which is appended to the ``ActionContext`` object that is available in every
controller function. See the `ActionContext Class <../../api/classes/ActionContext.html>`_
for the addon classes.

The Action Context addons allow you to do the following:
=======

- access assets, such as CSS and JavaScript files
- get configuration information
Expand All @@ -18,10 +20,11 @@ The Action Context addons allow you to do the following:
- get and set HTTP headers
- create URLs

.. _addons-syntax:

.. _mojito_addons-syntax:

Syntax
######
======

Using the ``ActionContext`` object ``ac``, you would call a ``{method}`` from an
``{addon}`` with the following syntax:
Expand All @@ -33,10 +36,11 @@ with the ``url`` method as seen here:

``ac.params.url()``


.. _addons-requiring:

Requiring Addons
################
================

Prior to version 0.5.0, Mojito attached addons to the ``ActionContext`` object for
every HTTP request and mojit instance. As a result, you were able to use
Expand Down Expand Up @@ -79,10 +83,11 @@ The list below shows what strings are used to require addons.
and Assets.


.. _addons-exs:

.. _mojito_addons-exs:

Addon Examples
##############
==============

The following code examples use the addons in parentheses:

Expand All @@ -93,10 +98,11 @@ The following code examples use the addons in parentheses:
- `Internationalizing Your Application <../code_exs/i18n_apps.html>`_ (``Intl``)
- `Using Multiple Mojits <../code_exs/multiple_mojits.html>`_ (``Composite``)

.. _addons-creating:

.. _mojito_addons-create:

Creating Addons
###############
===============

Because customized addons are not part of the standard API, but an extension of the API, the
instructions for creating addons can be found in
Expand Down
10 changes: 6 additions & 4 deletions docs/dev_guide/api_overview/mojito_client_obj.rst
@@ -1,5 +1,3 @@


=============
Client Object
=============
Expand All @@ -9,17 +7,21 @@ created. The ``client`` object can be used to pause and resume mojits running wi
See `Class Y.mojito.Client <../../api/classes/Y.mojito.Client.html>`_ in the
`Mojito API Reference <../../api/>`_ for more details.

.. _mojito_client_obj-pause:

Pausing Mojits
##############
==============

From the ``client`` object, you call the ``pause`` method as seen below to prevent any code from
executing outside of the individual binders (within the Mojito framework) and to call ``onPause()``
on all binders.

``Y.mojito.client.pause()``

.. _mojito_client_obj-resume:

Resuming Mojits
###############
===============

From the ``client`` object, you call the ``resume`` method as seen below to immediately execute all
cached operations and notify all of the binders through the ``onResume`` function.
Expand Down
14 changes: 7 additions & 7 deletions docs/dev_guide/api_overview/mojito_rest_lib.rst
@@ -1,5 +1,3 @@


============
REST Library
============
Expand All @@ -8,8 +6,10 @@ Mojito has a library to make it easier to make a REST calls to Web services from
implementation details, see `Class Y.mojito.lib.REST <../../api/classes/Y.mojito.lib.REST.html>`_
in the Mojito API documentation.

.. _mojito_rest_lib-incl:

Including Library
#################
=================

To use the REST library, include the string 'mojito-rest-lib' in the ``requires`` array, which
instructs YUI to load the library. Once the library is loaded, you can use
Expand All @@ -25,8 +25,11 @@ instructs YUI to load the library. Once the library is loaded, you can use
// Ask YUI to load the library w/ 'mojito-rest-lib'.
}, '0.0.1', {requires: ['mojito', 'mojito-rest-lib']});
.. _mojito_rest_lib-ex:

Example
#######
=======

In the model for the ``recipeSearch`` mojit below, the REST library is used to make a GET call to
the Recipe Puppy API.
Expand All @@ -35,9 +38,6 @@ the Recipe Puppy API.
YUI.add('ProductSearchModel', function(Y, NAME) {
Y.namespace('mojito.models')[NAME] = {
init: function(config) {
this.config = config;
},
recipeSearch: function(count, cb) {
var url = 'http://www.recipepuppy.com/api/';
var params = {
Expand Down
14 changes: 6 additions & 8 deletions docs/dev_guide/code_exs/adding_assets.rst
Expand Up @@ -199,14 +199,12 @@ To create and run ``simple_assets``:
* @constructor
*/
Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
},
/**
* Method corresponding to the 'index' action.
* @param ac {Object} The action context that
* provides access to the Mojito API.
*/
/**
* Method corresponding to the 'index' action.
* @param ac {Object} The action context that
* provides access to the Mojito API.
*/
index: function(ac) {
var data = {
title: "Simple Assets",
Expand Down
133 changes: 67 additions & 66 deletions docs/dev_guide/code_exs/binding_events.rst
Expand Up @@ -11,9 +11,11 @@ Binding Events
Summary
=======

This example shows how to bind events to a mojit, configure code to run on the client, and
make AJAX calls to the YQL Web service. The application listens for events and then makes
AJAX calls to YQL to get Flickr photo information.

This example shows how to bind events to a mojit, configure code to run
on the client, and make AJAX calls to the YQL Web service. The application
listens for events and then makes AJAX calls to YQL to get Flickr photo
information.

The following topics will be covered:

Expand All @@ -40,12 +42,13 @@ Implementation Notes
Configuring the Application to Run on the Client
------------------------------------------------

Mojito lets you configure applications to run on either the server or client side. This
example uses binders that are deployed to the client, so we need to configure Mojito to
deploy the application to the client, where it will be executed by the browser.
Mojito lets you configure applications to run on either the server or client
side. This example uses binders that are deployed to the client, so we need
to configure Mojito to deploy the application to the client, where it will
be executed by the browser.

To configure Mojito to run on the client, you simply set the ``"deploy"`` property to
``true`` in ``application.json`` as seen below.
To configure Mojito to run on the client, you simply set the ``"deploy"``
property to ``true`` in ``application.json`` as seen below.

.. code-block:: javascript
Expand All @@ -72,8 +75,8 @@ Getting Data with YQL in the Model
----------------------------------

In the mojit model, the `YUI YQL Query Utility <http://developer.yahoo.com/yui/3/yql/>`_
is used to get Flickr photo information. To access the utility in your model, specify
``'yql'`` in the ``requires`` array as seen in the code snippet below:
is used to get Flickr photo information. To access the utility in your model,
specify ``'yql'`` in the ``requires`` array as seen in the code snippet below:

.. code-block:: javascript
Expand All @@ -83,10 +86,10 @@ is used to get Flickr photo information. To access the utility in your model, sp
...
}, '0.0.1', {requires: ['yql']});
This code example uses the ``flickr.photos.search`` table to get information for photos
that have a title, description, or tags containing a string. For example, the YQL
statement below returns Flickr photo information for those photos that have a title,
description, or tags containing the string "Manhattan".
This code example uses the ``flickr.photos.search`` table to get information
for photos that have a title, description, or tags containing a string. For
example, the YQL statement below returns Flickr photo information for those
photos that have a title, description, or tags containing the string "Manhattan".

Copy the query below into the `YQL Console <http://developer.yahoo.com/yql/console/>`_,
replace ``{your_flickr_api_key}`` with your own Flickr API key, and then click **TEST**
Expand All @@ -100,11 +103,13 @@ the photo URI as seen here:

``http://farm + {farm} + static.flickr.com/ + {server} + / + {id} + _ + {secret} + .jpg``


In the ``model.server.js`` of ``PagerMojit`` shown below, the ``YQL`` function uses the YQL
statement above to get photo data, then parses the returned response to create the photo
URIs. The model then wraps the photo information in an object and stores those objects in
the ``images`` array that is sent to the controller through the ``callback`` function.


.. code-block:: javascript
YUI.add('PagerMojitModel', function(Y, NAME) {
Expand Down Expand Up @@ -428,6 +433,7 @@ the ``requires`` array.
};
}, '0.0.1', {requires: ['yql', 'io', 'dump']});
.. _events_notes-paging:
Using Paging
Expand Down Expand Up @@ -565,9 +571,7 @@ create URLs for the **next** and **prev** links.
* @constructor
*/
Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
},
index: function(actionContext) {
var page = actionContext.params.getFromMerged('page');
var start;
Expand Down Expand Up @@ -684,56 +688,55 @@ To set up and run ``binding_events``:
* @class Controller
* @constructor
*/
Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
},
index: function(actionContext) {
var page = actionContext.params.getFromMerged('page');
var start;
page = parseInt(page) || 1;
if ((!page) || (page<1)) {
page = 1;
}
// Page param is 1 based, but the model is 0 based
start = (page - 1) * PAGE_SIZE;
var model = actionContext.models.PagerMojit;
// Data is an array of images
model.getData('mojito', start, PAGE_SIZE, function(data) {
Y.log('DATA: ' + Y.dump(data));
var theData = {
data: data, // images
hasLink: false,
prev: {
title: "prev" // opportunity to localize
},
next: {
link: createLink(actionContext, {page: page+1}),
title: "next"
},
query: 'mojito'
};
if (page > 1) {
theData.prev.link = createLink(actionContext, {page: page-1});
theData.hasLink = true;
Y.namespace('mojito.controllers')[NAME] = {
index: function(actionContext) {
var page = actionContext.params.getFromMerged('page');
var start;
page = parseInt(page) || 1;
if ((!page) || (page<1)) {
page = 1;
}
actionContext.done(theData);
});
}
};
// Generate the link to the next page based on:
// - mojit id
// - action
// - params
function createLink(actionContext, params) {
var mergedParams = Y.mojito.util.copy(actionContext.params.getFromMerged());
for (var k in params) {
mergedParams[k] = params[k];
// Page param is 1 based, but the model is 0 based
start = (page - 1) * PAGE_SIZE;
var model = actionContext.models.PagerMojit;
// Data is an array of images
model.getData('mojito', start, PAGE_SIZE, function(data) {
Y.log('DATA: ' + Y.dump(data));
var theData = {
data: data, // images
hasLink: false,
prev: {
title: "prev" // opportunity to localize
},
next: {
link: createLink(actionContext, {page: page+1}),
title: "next"
},
query: 'mojito'
};
if (page > 1) {
theData.prev.link = createLink(actionContext, {page: page-1});
theData.hasLink = true;
}
actionContext.done(theData);
});
}
};
// Generate the link to the next page based on:
// - mojit id
// - action
// - params
function createLink(actionContext, params) {
var mergedParams = Y.mojito.util.copy(actionContext.params.getFromMerged());
for (var k in params) {
mergedParams[k] = params[k];
}
return actionContext.url.make('frame', 'index', Y.QueryString.stringify(mergedParams));
}
return actionContext.url.make('frame', 'index', Y.QueryString.stringify(mergedParams));
}
}, '0.0.1', {requires: ['dump', 'mojito-url-addon', 'mojito-params-addon']});
#. To get Flickr photo information using YQL, create the file ``models/model.server.js`` with
the code below. Be sure to replace the ``'{your_flickr_api_key}'`` with your own
Flickr API key.
Expand All @@ -752,9 +755,7 @@ To set up and run ``binding_events``:
* @constructor
*/
Y.namespace('mojito.models')[NAME] = {
init: function(config) {
this.config = config;
},
getData: function(query, start, count, callback) {
var q = null;
// Get Flickr API key: http://www.flickr.com/services/api/keys/apply/
Expand Down

0 comments on commit df58c4f

Please sign in to comment.