Permalink
Browse files

introduction for application development

  • Loading branch information...
1 parent f8865b4 commit 284ba92549c61b91103af1e17afa9369b0a00bf9 @yssk22 committed May 22, 2011
Showing with 67 additions and 2 deletions.
  1. +67 −2 doc/source/tutorial/introduction.rst
@@ -28,17 +28,82 @@ This chapter shows brief introduction for these steps.
Create a template site.
--------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
At first, you need to a container site for your application to be installed for testing. As described at :doc:`../getting_started`, use ``sunrise:create`` command.
::
$ sunrise\:create -s sunrise-site
-
+ $ cd sunrise-site
Then your site directory is as follows.
::
+ $ tree -L 1
+ .
+ ├── _attachments
+ ├── app.js
+ ├── apps
+ ├── conf
+ └── node_modules
+
+Now we call this root directory as ``SITE_ROOT``. ``{SITE_ROOT}/apps`` directory is the directory that contains your original applications.
+
+Create a template application
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+To make a applicatin, use ``sunrise:create`` command with ``-a`` option, that generate a template application on the given path.
+
+::
+
+ $ sunrise\:create -a apps/myapp
+ /Users/yssk22/tmp/sunrise-site/apps/myapp has been created successfully
+
+Install the template application
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+And you need to install your ``myapp`` in your site. To do this, modify ``init`` function in ``{SITE_ROOT}/app.js`` (NOT ``{SITE_ROOT}/apps/myapp/app.js``), adding ``site.install('myapp', '/myapp/')``.
+
+.. code-block:: javascript
+
+ ddoc.init = function(site){
+ // ...
+ // install system application
+ site.install('system', '/system/');
+
+ // install my application from local apps directory
+ site.install('myapp', '/myapp/');
+
+ }
+
+``site.install('app', '/approot/', options)`` is a function that install a sunrise application in to the site. On installing the application, ``init`` function in ``{SITE_ROOT}/apps/myapp/app.js`` is also invoked by sunrise.
+
+In the default template,
+
+.. code-block:: javascript
+
+ ddoc.init = function(app){
+ app.get('/',
+ function(req, res, next){
+ res.render('index.ejs');
+ });
+
+ app.helpers(ddoc.helpers(app));
+ app.dynamicHelpers(ddoc.dynamicHelpers(app));
+ };
+
+
+Launch the site to confirm the template application
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+Then launch your site, visit go to http://localhost:8888/, you can see the link to myapp in the menu bar. And you can visit the application root URL, http://localhost:8888/myapp/.
+
+``init`` function in your ``{SITE_ROOT}/apps/myapp/app.js`` is a entry point for your application. You can add some paths for your web services, booting scripts for setup your database, ... etc, acorrding to the manner of sunrise.
+
+And ``app.js`` is a design document on CouchDB. You can define MapReduce views, list, show functions, and also add attachements for static file hosting.
+
+.. warning:: The feature of static file hosting is provided by Node engine, not by CouchDB currently. So you can define attachments for future use.

0 comments on commit 284ba92

Please sign in to comment.