Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[docs] Updated example for reporting errors, the section on file naming conventions for templates, and fixed a typo. #825

Merged
merged 3 commits into from

1 participant

Joe Catera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 22 deletions.
  1. +28 −22 docs/dev_guide/intro/mojito_mvc.rst
50 docs/dev_guide/intro/mojito_mvc.rst
View
@@ -294,11 +294,10 @@ Example
-------
The example controller below shows you how the components are used. The
-``status`` mojit is registered with ``YUI.add`` and the ``init`` function
-stores the date so it can be used by other functions, and the ``this``
-reference allows the ``index`` function to call ``create_status``. Lastly,
-the ``requires`` array loads the addons ``Intl``, ``Params``, and ``Url``
-that are needed by the controller.
+``status`` mojit is registered with ``YUI.add``, and the ``index`` function
+uses the ``this`` reference to call the function ``create_status``. Lastly, the
+``requires`` array loads the addons ``Intl``, ``Params``, and ``Url``that are
+needed by the controller.
.. code-block:: javascript
@@ -320,7 +319,7 @@ that are needed by the controller.
return user + ': ' + status + ' - ' + time;
}
};
- }, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-params-addon', mojito-url-addon']});
+ }, '0.0.1', {requires: ['mojito-intl-addon', 'mojito-params-addon', 'mojito-url-addon']});
.. _mvc-controllers-actions:
@@ -554,23 +553,26 @@ object as a parameter. The ``Error`` object is just the standard JavaScript
code that will be used if the error bubbles to the top of the
page (i.e., not caught by a parent mojit).
-In the code snippet below from ``controller.server.js``, the model is asked
-to get a blog post. The ``try-catch`` clause will catch any errors made calling
-``getPost``, and the ``error`` method will display the error message.
+In the code snippet below from ``controller.server.js``, the ``index``
+method uses the query string parameter ``company`` to fetch company information
+stored in a configuration file. The ``if-else`` clause either sends
+the company information to the ``index`` template or reports
+an error that information for the specified company could not be found.
.. code-block:: javascript
...
index: function(ac) {
- try {
- var post = ac.models.get('BlogModel').getPost();
- ac.done({ "post": post });
- } catch(e) {
- console.log(e);
- ac.error(e);
+ var company = ac.params.url('company'),
+ company_info = ac.config.get(company);
+ if (company_info) {
+ ac.done({ "company_info": company_info });
+ } else {
+ ac.error("Could not find info for " + company);
}
}
...
+ }, '0.0.1', {requires: ['mojito-params-addon', 'mojito-config-addon']});
.. _mvc-controllers-save_state:
@@ -590,15 +592,19 @@ have substituted values for the template tags.
Naming Convention
-----------------
-The naming convention of the templates is based on the controller function (action)
-that supplies data, the engine that renders the templates, and the device
-requesting the page. If the calling device is determined not to be a portable
-device such as a cell phone, the ``{device}`` element of the syntax below
-is omitted.
+Template files have the following naming convention:
-**File Naming Convention for Templates:**
+``{controller_function}.[{selector}].{rendering_engine}.html``
+
+The following list describes the elements of the template file name:
+
+- ``{controller_function}`` - the controller function (action)
+ that supplies data.
+- ``{selector}`` - an arbitrary string used to select
+ a specific template. For example, you could use the selector
+ ``iphone`` for the iPhone template.
+- ``{rendering_engine}`` - the engine that renders the templates.
-``{controller_function}.[{device}].{rendering_engine}.html``
For example, if the template is receiving data from the ``index`` function
of the controller and has Handlebars expressions that need to be rendered,
Something went wrong with that request. Please try again.