Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B5EAE8C2 for ; Mon, 11 Feb 2013 11:12:28 +0000 (UTC) Received: (qmail 53494 invoked by uid 500); 11 Feb 2013 11:12:27 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 53397 invoked by uid 500); 11 Feb 2013 11:12:26 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 48423 invoked by uid 99); 11 Feb 2013 11:12:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2013 11:12:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DDD953C74E; Mon, 11 Feb 2013 11:12:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: jan@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [27/50] [abbrv] git commit: Add hello world example to writing_addons.md consistently refer to FauxtonAPI in generated files Message-Id: <20130211111214.DDD953C74E@tyr.zones.apache.org> Date: Mon, 11 Feb 2013 11:12:14 +0000 (UTC) Add hello world example to writing_addons.md consistently refer to FauxtonAPI in generated files Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/fbca1d9d Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fbca1d9d Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fbca1d9d Branch: refs/heads/fauxton Commit: fbca1d9dac80fd452f45e2213806aa9d566d6e25 Parents: 139d4a1 Author: Simon Metson Authored: Sun Jan 27 17:13:39 2013 +0100 Committer: Simon Metson Committed: Sun Jan 27 17:13:39 2013 +0100 ---------------------------------------------------------------------- src/fauxton/tasks/fauxton.js | 2 +- src/fauxton/writing_addons.md | 93 +++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbca1d9d/src/fauxton/tasks/fauxton.js ---------------------------------------------------------------------- diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js index eb464a6..c15c906 100644 --- a/src/fauxton/tasks/fauxton.js +++ b/src/fauxton/tasks/fauxton.js @@ -25,7 +25,7 @@ module.exports = function(grunt) { { name: 'resources', filename: 'resources.js', - template: 'define([\n "app",\n "backbone",\n "modules/fauxton/base"\n],\n\nfunction (app, backbone, Fauxton) {\n\tvar <%= module %> = {};\n\treturn <%= module %>;\n});\n' + template: 'define([\n "app",\n "backbone",\n "modules/fauxton/base"\n],\n\nfunction (app, backbone, FauxtonAPI) {\n\tvar <%= module %> = {};\n\treturn <%= module %>;\n});\n' }, { name: 'routes', http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbca1d9d/src/fauxton/writing_addons.md ---------------------------------------------------------------------- diff --git a/src/fauxton/writing_addons.md b/src/fauxton/writing_addons.md index b435566..6e83966 100644 --- a/src/fauxton/writing_addons.md +++ b/src/fauxton/writing_addons.md @@ -52,4 +52,95 @@ selector for a named set of routes, for example: }; return Search; -adds the `searchSidebar` callback to `#sidebar-content` for three routes. \ No newline at end of file +adds the `searchSidebar` callback to `#sidebar-content` for three routes. + +## Hello world addon +First create the addon skeleton: + + ± bbb addon + path.existsSync is now called `fs.existsSync`. + Running "addon" task + + Please answer the following: + [?] Add on Name (WickedCool) Hello + [?] Location of add ons (app/addons) + [?] Do you need to make any changes to the above before continuing? (y/N) + + Created addon Hello in app/addons + + Done, without errors. + +In `app/addons/hello/templates/hello.html` place: + +

Hello!

+ +Next, we'll defined a simple view in `resources.js` (for more complex addons +you may want to have a views.js) that renders that template: + + define([ + "app", + "api" + ], + + function (app, FauxtonAPI) { + var Resources = {}; + + Resources.Hello = FauxtonAPI.View.extend({ + template: "addons/hello/templates/hello" + }); + + return Resources; + }); + + +Then define a route in `routes.js` that the addon is accessible at: + + define([ + "app", + "api", + "addons/hello/resources" + ], + + function(app, FauxtonAPI, Resources) { + var helloRoute = function () { + console.log('helloRoute callback yo'); + return { + layout: "one_pane", + crumbs: [ + {"name": "Hello","link": "_hello"} + ], + views: { + "#dashboard-content": new Resources.Hello({}) + }, + apiUrl: 'hello' + }; + }; + + Routes = { + "_hello": helloRoute + }; + + return Routes; + }); + + +Then wire it all together in base.js: + + define([ + "app", + "api", + "addons/hello/routes" + ], + + function(app, FauxtonAPI, HelloRoutes) { + var Hello = new FauxtonAPI.addon(); + console.log('hello from hello'); + + Hello.initialize = function() { + FauxtonAPI.addHeaderLink({title: "Hello", href: "#_hello"}); + }; + + Hello.Routes = HelloRoutes; + console.log(Hello); + return Hello; + });