<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life As An Evangelist &#187; blogs</title>
	<atom:link href="http://lifeasanevangelist.com/category/blogs/feed/" rel="self" type="application/rss+xml" />
	<link>http://lifeasanevangelist.com</link>
	<description>Keep up to date with Adobe's Platform Evangelists</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:13:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Run Grails on the Cloud with Heroku</title>
		<link>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=run-grails-on-the-cloud-with-heroku</link>
		<comments>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=run-grails-on-the-cloud-with-heroku#comments</comments>
		<pubDate>Tue, 07 Feb 2012 23:27:17 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3038</guid>
		<description><![CDATA[Support for Grails on Heroku was recently announced and I&#8217;d like to walk you through the steps to create a simple Grails app and then deploy it on the cloud with Heroku. Before you get started install Grails 2.0.0, install the Heroku toolbelt, install git, and signup for a Heroku.com account. Don&#8217;t worry, you won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Support for <a href="http://blog.heroku.com/archives/2011/12/15/grails/">Grails on Heroku was recently announced</a> and I&#8217;d like to walk you through the steps to create a simple Grails app and then deploy it on the cloud with Heroku.  Before you get started <a href="http://grails.org/">install Grails 2.0.0</a>, <a href="http://toolbelt.heroku.com">install the Heroku toolbelt</a>, <a href="http://git-scm.com/">install git</a>, and <a href="http://heroku.com/signup">signup for a Heroku.com account</a>.  Don&#8217;t worry, you won&#8217;t need to enter a credit card to give this a try because Heroku gives you <a href="http://devcenter.heroku.com/articles/how-much-does-a-dyno-cost">750 free dyno hours per application, per month</a>.  (Wondering what a &#8220;dyno&#8221; is?  Check out: <a href="http://www.heroku.com/how">How Heroku Works</a>)  Let&#8217;s get started.</p>
<p><strong>Step 1)</strong> Create the app:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-app grailbars</pre></div></div>

<p>You&#8217;ll need to do the rest of this from inside the newly created &#8220;grailbars&#8221; directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> grailbars</pre></div></div>

<p><strong>Step 2)</strong> Create a new domain object:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-domain-class com.jamesward.grailbars.Bar</pre></div></div>

<p><strong>Step 3)</strong> Edit the <em>grails-app/domain/com/jamesward/grailbars/Bar.groovy</em> file so it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #a1a100;">com.jamesward.grailbars</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bar <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">String</span> name
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Step 4)</strong> Create a controller for the Bar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails create-controller com.jamesward.grailbars.Bar</pre></div></div>

<p><strong>Step 5)</strong> Edit the <em>grails-app/controllers/com/jamesward/grailbars/BarController.groovy</em> file so it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #a1a100;">com.jamesward.grailbars</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BarController <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">def</span> scaffold <span style="color: #66cc66;">=</span> Bar
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Step 6)</strong> Run the app locally to test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails run-app</pre></div></div>

<p>Now open it in your browser: <a href="http://localhost:8080/grailbars">http://localhost:8080/grailbars</a></p>
<p><strong>Step 7)</strong> Update the data source configuration to use the free Postgres database on Heroku.  First edit the <em>grails-app/conf/DataSource.groovy</em> file and replace the &#8220;production&#8221; section with:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">production <span style="color: #66cc66;">&#123;</span>
    dataSource <span style="color: #66cc66;">&#123;</span>
        dbCreate <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;update&quot;</span>
        driverClassName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;org.postgresql.Driver&quot;</span>
        dialect <span style="color: #66cc66;">=</span> org.<span style="color: #006600;">hibernate</span>.<span style="color: #006600;">dialect</span>.<span style="color: #006600;">PostgreSQLDialect</span>    
        uri <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">env</span>.<span style="color: #006600;">DATABASE_URL</span><span style="color: #66cc66;">?</span>:<span style="color: #ff0000;">&quot;postgres://test:test@localhost/test&quot;</span><span style="color: #66cc66;">&#41;</span>
        url <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;jdbc:postgresql://&quot;</span><span style="color: #66cc66;">+</span>uri.<span style="color: #006600;">host</span><span style="color: #66cc66;">+</span>uri.<span style="color: #006600;">path</span>
        username <span style="color: #66cc66;">=</span> uri.<span style="color: #006600;">userInfo</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>
        password <span style="color: #66cc66;">=</span> uri.<span style="color: #006600;">userInfo</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now add the Postgres JDBC driver as a dependency by adding the following to the &#8220;dependencies&#8221; section of the <em>grails-app/conf/BuildConfig.groovy</em> file:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">runtime <span style="color: #ff0000;">'postgresql:postgresql:9.1-901-1.jdbc4'</span></pre></div></div>

<p><strong>Step 8)</strong> Setup a git repository for the project which will be used for transferring the files to Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails integrate-with <span style="color: #660033;">--git</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> init
<span style="color: #c20cb9; font-weight: bold;">git</span> add application.properties grails-app <span style="color: #7a0874; font-weight: bold;">test</span> web-app
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-m</span> init</pre></div></div>

<p><strong>Step 9)</strong> Login with the Heroku CLI:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

<p><strong>Step 10)</strong> Ceate a new application using the &#8220;cedar&#8221; stack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">-s</span> cedar</pre></div></div>

<p><strong>Step 11)</strong> Upload your application to Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

<p>Now open the application running on Heroku in your browser (the URL was in the &#8220;heroku create&#8221; and &#8220;git push&#8221; output).  Verify that it works.  Awesome!  You just built a Grails app and deployed it on the Cloud with Heroku!  For more details on using Grails on Heroku, visit the <a href="http://devcenter.heroku.com/articles/grails">Heroku Dev Center</a>.  Let me know if you have any questions.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/02/07/run-grails-on-the-cloud-with-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uberity is now live!  Free WhitePaper on Mobile Strategy</title>
		<link>http://technoracle.blogspot.com/2012/02/uberity-is-now-live-free-whitepaper-on.html</link>
		<comments>http://technoracle.blogspot.com/2012/02/uberity-is-now-live-free-whitepaper-on.html#comments</comments>
		<pubDate>Tue, 07 Feb 2012 17:43:00 +0000</pubDate>
		<dc:creator>Duane Nickull</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Today Uberity Technology Corporation officially opened the doors for business and launched it's website. Since leaving Adobe, I have been blessed to get back together with the best developers and engineering staff I have ever worked with and start buil...]]></description>
			<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;" trbidi="on">Today <a href="http://uberity.com/">Uberity Technology Corporation</a> officially opened the doors for business and launched it's website. Since leaving Adobe, I have been blessed to get back together with the best developers and engineering staff I have ever worked with and start building the technology we think will help enterprises transition to extend their IT systems to the mobile space. &nbsp;<b>Uberity's mission</b> is to <i><b>help's it's customers to define, develop, deploy and support the technology that can make or break their business.</b></i><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.uberity.com/"><img border="0" height="208" src="http://4.bp.blogspot.com/-0xuveiqsOSo/TzFicL8leHI/AAAAAAAABHo/cVnoZwBNyu8/s320/Screen+Shot+2012-02-07+at+9.41.34+AM.png" width="320" /></a></div><br /><br />One of the first offerings we are releasing is a free White Paper on <a href="http://uberity.com/whitepapers/Mobile-Application-Development-Strategy_FINAL.pdf">Enterprise Mobile Application &nbsp;Development Strategies</a>. &nbsp;This is a pragmatic look at the challenges facing executives and managers who are responsible for their companies long term mobile development strategies. &nbsp;Most of the content of this white paper comes from learning the hard way what does and does not work for mobile application development strategies. &nbsp;There are plenty of options from cross compiling to running through an intermediate interpretation layer to developing natively for each stack. &nbsp;This White Paper explores the key considerations along with the strengths and benefits of each approach. &nbsp;More will be written on this topic later.<br /><br />Another area we are working within is Adobe LiveCycle ES and Data Services. &nbsp;Uberity employs several former Senior Adobe Engineering staff who worked on the core LiveCycle platform. &nbsp;Along with myself, we feel we have a team that is skilled and capable to take on any LiveCycle work. &nbsp;Uberity has recently successfully completed some LiveCycle Professional Services work and is open for business to hear your needs. &nbsp;With a combined experience of over 32 years of LiveCycle expertise, our team is ready to take on new challenges. &nbsp;If interested, contact duane at uberity dot com.<br /><br />Another area we are building out is a health care solution based on using Neo4J as a graphDB back end to integrate mobile functionality. &nbsp;This project is built using our modular approach to enterprise architecture and the core patterns we have implemented can be used for other verticals as well.<br /><br />On a personal note, this is the most exciting thing I have done in technology for years. We've already closed a lot of business and are hungry for more.<br /><br /></div><div class="blogger-post-footer">Original post at <a href="http://technoracle.blogspot.com">http://technoracle.blogspot.com</a><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17460203-744159004873403223?l=technoracle.blogspot.com' alt='' /></div>]]></content:encoded>
			<wfw:commentRss>http://technoracle.blogspot.com/feeds/744159004873403223/comments/default</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Sample Mobile App with Backbone.js, PhoneGap, and a Local Database</title>
		<link>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-phonegap-and-a-local-database/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-mobile-app-with-backbone-js-phonegap-and-a-local-database</link>
		<comments>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-phonegap-and-a-local-database/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-mobile-app-with-backbone-js-phonegap-and-a-local-database#comments</comments>
		<pubDate>Tue, 07 Feb 2012 16:29:39 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=3044</guid>
		<description><![CDATA[In my previous post, I shared a simple Wine Cellar application built with Backbone.js and packaged as a mobile app with PhoneGap. That version of the application gets its data from a set of RESTful services, which means that you can only use it while online. In this post, we explore an offline version of [...]
	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Mobile%20App%20with%20Backbone.js,%20PhoneGap,%20and%20a%20Local%20Database%20http://coenraets.org/blog/?p=3044" target="_blank">Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-phonegap-and-a-local-database/" target="_blank">Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/">previous post</a>, I shared a simple Wine Cellar application built with <a href="http://documentcloud.github.com/backbone/">Backbone.js</a> and packaged as a mobile app with <a href="http://phonegap.com/">PhoneGap</a>. That version of the application gets its data from a set of RESTful services, which means that you can only use it while online.</p>
<p>In this post, we explore an offline version of the same application: this new version gets its data from your device&#8217;s local database using the PhoneGap SQL database API. </p>
<p>By default, Backbone.js Models access their data using RESTful services defined by the Models &#8220;url&#8221; and &#8220;urlRoot&#8221; attributes. But Backbone.js also makes it easy and elegant to change your Models data access mechanism: All you have to do is override the Backbone.sync method. From the Backbone.js <a href="http://documentcloud.github.com/backbone/#Sync">documentation</a>:</p>
<blockquote><p>Backbone.sync is the function that Backbone calls every time it attempts to read or save a model to the server. By default, it uses (jQuery/Zepto).ajax to make a RESTful JSON request. You can override it in order to use a different persistence strategy, such as WebSockets, XML transport, or Local Storage.</p></blockquote>
<p>The documentation includes a <a href="http://documentcloud.github.com/backbone/docs/backbone-localstorage.html">useful example</a> that shows how to replace the default Backbone.sync implementation with localStorage-based persistence where models are saved into JSON objects.  </p>
<p>In our application, we will replace the default Backbone.sync implementation with SQL-based persistence using the device&#8217;s local database.<br />
<span id="more-3044"></span><br />
First, we create a data access object that encapsulates the logic to read (find), create, update, and delete wines. This simple application is read-only and only needs to retrieve collections. So, I only implemented the findAll() method and stubbed the other methods (find, create, update, destroy). WineDAO also has a &#8220;populate&#8221; function to populate the wine table with sample data. </p>
<pre class="brush: jscript; title: ; notranslate">
window.WineDAO = function (db) {
    this.db = db;
};

_.extend(window.WineDAO.prototype, {

    findAll:function (callback) {
        this.db.transaction(
            function (tx) {
                var sql = &quot;SELECT * FROM wine ORDER BY name&quot;;
                tx.executeSql(sql, [], function (tx, results) {
                    var len = results.rows.length;
                    var wines = [];
                    for (var i = 0; i &lt; len; i++) {
                        wines[i] = results.rows.item(i);
                    }
                    callback(wines);
                });
            },
            function (tx, error) {
                alert(&quot;Transaction Error: &quot; + error);
            }
        );
    },

    create:function (model, callback) {
//        TODO: Implement
    },

    update:function (model, callback) {
//        TODO: Implement
    },

    destroy:function (model, callback) {
//        TODO: Implement
    },

    find:function (model, callback) {
//        TODO: Implement
    },

//  Populate Wine table with sample data
    populate:function (callback) {
        this.db.transaction(
            function (tx) {
                console.log('Dropping WINE table');
                tx.executeSql('DROP TABLE IF EXISTS wine');
                var sql =
                    &quot;CREATE TABLE IF NOT EXISTS wine ( &quot; +
                        &quot;id INTEGER PRIMARY KEY AUTOINCREMENT, &quot; +
                        &quot;name VARCHAR(50), &quot; +
                        &quot;year VARCHAR(50), &quot; +
                        &quot;grapes VARCHAR(50), &quot; +
                        &quot;country VARCHAR(50), &quot; +
                        &quot;region VARCHAR(50), &quot; +
                        &quot;description TEXT, &quot; +
                        &quot;picture VARCHAR(200))&quot;;
                console.log('Creating WINE table');
                tx.executeSql(sql);
                console.log('Inserting wines');
                tx.executeSql(&quot;INSERT INTO wine VALUES (1,'CHATEAU DE SAINT COSME','2009','Grenache / Syrah','France','Southern Rhone / Gigondas','The aromas of fruit and spice give one a hint of the light drinkability of this lovely wine, which makes an excellent complement to fish dishes.','saint_cosme.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (2,'LAN RIOJA CRIANZA','2006','Tempranillo','Spain','Rioja','A resurgence of interest in boutique vineyards has opened the door for this excellent foray into the dessert wine market. Light and bouncy, with a hint of black truffle, this wine will not fail to tickle the taste buds.','lan_rioja.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (3,'MARGERUM SYBARITE','2010','Sauvignon Blanc','USA','California Central Cosat','The cache of a fine Cabernet in ones wine cellar can now be replaced with a childishly playful wine bubbling over with tempting tastes of black cherry and licorice. This is a taste sure to transport you back in time.','margerum.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (4,'OWEN ROE \&quot;EX UMBRIS\&quot;','2009','Syrah','USA','Washington','A one-two punch of black pepper and jalapeno will send your senses reeling, as the orange essence snaps you back to reality. Do not miss this award-winning taste sensation.','ex_umbris.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (5,'REX HILL','2009','Pinot Noir','USA','Oregon','One cannot doubt that this will be the wine served at the Hollywood award shows, because it has undeniable star power. Be the first to catch the debut that everyone will be talking about tomorrow.','rex_hill.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (6,'VITICCIO CLASSICO RISERVA','2007','Sangiovese Merlot','Italy','Tuscany','Though soft and rounded in texture, the body of this wine is full and rich and oh-so-appealing. This delivery is even more impressive when one takes note of the tender tannins that leave the taste buds wholly satisfied.','viticcio.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (7,'CHATEAU LE DOYENNE','2005','Merlot','France','Bordeaux','Though dense and chewy, this wine does not overpower with its finely balanced depth and structure. It is a truly luxurious experience for the senses.','le_doyenne.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (8,'DOMAINE DU BOUSCAT','2009','Merlot','France','Bordeaux','The light golden color of this wine belies the bright flavor it holds. A true summer wine, it begs for a picnic lunch in a sun-soaked vineyard.','bouscat.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (9,'BLOCK NINE','2009','Pinot Noir','USA','California','With hints of ginger and spice, this wine makes an excellent complement to light appetizer and dessert fare for a holiday gathering.','block_nine.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (10,'DOMAINE SERENE','2007','Pinot Noir','USA','Oregon','Though subtle in its complexities, this wine is sure to please a wide range of enthusiasts. Notes of pomegranate will delight as the nutty finish completes the picture of a fine sipping experience.','domaine_serene.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (11,'BODEGA LURTON','2011','Pinot Gris','Argentina','Mendoza','Solid notes of black currant blended with a light citrus make this wine an easy pour for varied palates.','bodega_lurton.jpg')&quot;);
                tx.executeSql(&quot;INSERT INTO wine VALUES (12,'LES MORIZOTTES','2009','Chardonnay','France','Burgundy','Breaking the mold of the classics, this offering will surprise and undoubtedly get tongues wagging with the hints of coffee and tobacco in perfect alignment with more traditional notes. Breaking the mold of the classics, this offering will surprise and undoubtedly get tongues wagging with the hints of coffee and tobacco in perfect alignment with more traditional notes. Sure to please the late-night crowd with the slight jolt of adrenaline it brings.','morizottes.jpg')&quot;);
            },
            function (tx, error) {
                alert('Transaction error ' + error);
            },
            function (tx) {
                callback();
            }
        );
    }
});
</pre>
<p>I then added a &#8220;dao&#8221; attribute to the Models to specify which data object should be used to access their underlying data.</p>
<pre class="brush: jscript; title: ; notranslate">
window.Wine = Backbone.Model.extend({
	urlRoot: &quot;http://coenraets.org/backbone-cellar/part1/api/wines&quot;,
    dao: WineDAO
});

window.WineCollection = Backbone.Collection.extend({
	model: Wine,
	url: &quot;http://coenraets.org/backbone-cellar/part1/api/wines&quot;,
    dao: WineDAO
});
</pre>
<p>NOTE: The application doesn&#8217;t need the url and urlRoot attributes anymore, but you can imagine a more sophisticated version of the app that would work with the RESTful services while online and fall back to the local database while offline. </p>
<p>With that infrastructure in place, we can now override Backbone.sync as follows:</p>
<pre class="brush: jscript; title: ; notranslate">
Backbone.sync = function (method, model, options) {

    var dao = new model.dao(window.db);

    switch (method) {
        case &quot;read&quot;:
            if (model.id)
                dao.find(model, function (data) {
                    options.success(data);
                });
            else
                dao.findAll(function (data) {
                    options.success(data);
                });
            break;
        case &quot;create&quot;:
            dao.create(model, function (data) {
                options.success(data);
            });
            break;
        case &quot;update&quot;:
            dao.update(model, function (data) {
                options.success(data);
            });
            break;
        case &quot;delete&quot;:
            dao.destroy(model, function (data) {
                options.success(data);
            });
            break;
    }

};
</pre>
<p>And finally, we need to open the database (and populate it with sample data) at startup:</p>
<pre class="brush: jscript; title: ; notranslate">
window.startApp = function () {
    var self = this;
    window.db = window.openDatabase(&quot;WineCellar&quot;, &quot;1.0&quot;, &quot;WineCellar Demo DB&quot;, 200000);
    var wineDAO = new WineDAO(self.db);
    wineDAO.populate(function () {
        this.templateLoader.load(['wine-list', 'wine-details', 'wine-list-item'], function () {
            self.app = new AppRouter();
            Backbone.history.start();
        });
    })
}
</pre>
<h4>Download</h4>
<p>I added this version of the application to the backbone-cellar GitHub repository <a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/offline">here</a>. </p>
<p>NOTE: You will have to create a PhoneGap project (see <a href="http://phonegap.com/start">documentation</a> here) or use the <a href="https://build.phonegap.com/">hosted build service</a> to package the code as a native app for different mobile platforms.</p>

	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Mobile%20App%20with%20Backbone.js,%20PhoneGap,%20and%20a%20Local%20Database%20http://coenraets.org/blog/?p=3044" >Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-phonegap-and-a-local-database/" >Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-phonegap-and-a-local-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Transfer Number, String, int/uint and Boolean with AIR Native Extensions for iOS back and forth</title>
		<link>http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/</link>
		<comments>http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 16:24:54 +0000</pubDate>
		<dc:creator>Tom Krcha</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.flashrealtime.com/?p=2567</guid>
		<description><![CDATA[Casting basic types from ActionScript 3 to C Your probably first and immediate question when programming ANE for iOS is: &#8220;How to transfer data from AS3 to C and back to AS3?&#8221;. Once you break through this essential stage you enter the world of endless possibilities in Adobe AIR with native extensions. There has been [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<h3>Casting basic types from ActionScript 3 to C</h3>
<p>Your probably first and immediate question when programming ANE for iOS is: &#8220;How to transfer data from AS3 to C and back to AS3?&#8221;. Once you break through this essential stage you enter the world of endless possibilities in Adobe AIR with native extensions.</p>
<p>There has been already <a href="http://www.adobe.com/devnet/air/native-extensions-for-air.html">plenty of articles</a> on how to begin writing your native extensions, I am not going to explain that, just share the source code needed for that.<br />
I am using Adobe Flash Builder 4.6 with ANE support for AS3 and Apple Xcode for coding the C part + packaging the static library (*.a file).<br />
But let me quickly remind you the workflow. You need 3 projects, one is Flex Library project in FB (AS3 interface for C as *.swc), second is native library in Xcode (C interface and implementation as static library *.a), third is the actual test project in FB to run the native extension (*.ane).</p>
<p>Fig: Native Extension Creation Process<br />
<img src="http://www.flashrealtime.com/wp-content/uploads/2012/02/NativeExtensionProcess.png" alt="" title="NativeExtensionProcess" width="480" height="425" class="alignnone size-full wp-image-2592" /></p>
<p>In this tutorial I want to illustrate how to transfer some basic types like Number, String, int/uint and Boolean from AS3 to C, process them and return back to AS3. In the next tutorial, we will look into more complex data types like Array, ByteArray and BitmapData.</p>
<p>Good starting point: <a href="http://help.adobe.com/en_US/air/extensions/WSb464b1207c184b14-62b8e11f12937b86be4-8000.html">Native C API Reference</a> for Adobe AIR extensions. There is also a good page <a href="http://help.adobe.com/en_US/air/extensions/WS460ee381960520ad-866f9c112aa6e1ad46-8000.html">Coding native side with C</a> for AIR.</p>
<p>But there is nothing better than samples. Let&#8217;s dig into some real code:</p>
<h3>Number (AS3->C->AS3) Sum function</h3>
<p>AS3 part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sum<span style="color: #66cc66;">&#40;</span>number1:<span style="color: #0066CC;">Number</span>,number2:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#123;</span>
       <span style="color: #808080; font-style: italic;">// call C function sum with 2 arguments, number 1 and number2 and return a value</span>
	<span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">Number</span> = context.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;sum&quot;</span>,number1,number2<span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Number</span>;
	<span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>C part:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">FREObject sum<span style="color: #009900;">&#40;</span>FREContext ctx<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> funcData<span style="color: #339933;">,</span> uint32_t argc<span style="color: #339933;">,</span> FREObject argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// argc ... argument count, uint</span>
    <span style="color: #666666; font-style: italic;">// argv ... argument values, Array</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// retrieve first argument and write it to a variable</span>
    <span style="color: #993333;">double</span> number1<span style="color: #339933;">;</span>
    FREGetObjectAsDouble<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>number1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// retrieve second argument and write it to a variable</span>
    <span style="color: #993333;">double</span> number2<span style="color: #339933;">;</span>
    FREGetObjectAsDouble<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>number2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add first and second number together</span>
    <span style="color: #993333;">double</span> sum <span style="color: #339933;">=</span> number1 <span style="color: #339933;">+</span> number2<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// write computed sum to FREObject that will be returned back to AS3</span>
    FREObject sumToReturn <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span>
    FRENewObjectFromDouble<span style="color: #009900;">&#40;</span>sum<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>sumToReturn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> sumToReturn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>int (AS3->C->AS3) Subtract function</h3>
<p>AS3 part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> subtract<span style="color: #66cc66;">&#40;</span>int1:<span style="color: #0066CC;">int</span>,int2:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">Number</span> = context.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;subtract&quot;</span>,int1,int2<span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">int</span>;
	<span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>C part:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">FREObject subtract<span style="color: #009900;">&#40;</span>FREContext ctx<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> funcData<span style="color: #339933;">,</span> uint32_t argc<span style="color: #339933;">,</span> FREObject argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    int32_t int1<span style="color: #339933;">;</span>
    FREGetObjectAsInt32<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>int1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    int32_t int2<span style="color: #339933;">;</span>
    FREGetObjectAsInt32<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>int2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    int32_t sum <span style="color: #339933;">=</span> int1 <span style="color: #339933;">-</span> int2<span style="color: #339933;">;</span>
&nbsp;
    NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;%d-%d=%d&quot;</span><span style="color: #339933;">,</span>int1<span style="color: #339933;">,</span>int2<span style="color: #339933;">,</span>sum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    FREObject sumToReturn <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span>
    FRENewObjectFromInt32<span style="color: #009900;">&#40;</span>sum<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>sumToReturn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> sumToReturn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>uint (AS3->C->AS3) Multiply function</h3>
<p>AS3 part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> multiply<span style="color: #66cc66;">&#40;</span>uint1:uint,uint2:uint<span style="color: #66cc66;">&#41;</span>:uint<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">Number</span> = context.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;multiply&quot;</span>,uint1,uint2<span style="color: #66cc66;">&#41;</span> as uint;
	<span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>C part:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">FREObject multiply<span style="color: #009900;">&#40;</span>FREContext ctx<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> funcData<span style="color: #339933;">,</span> uint32_t argc<span style="color: #339933;">,</span> FREObject argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    uint32_t uint1<span style="color: #339933;">;</span>
    FREGetObjectAsUint32<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>uint1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    uint32_t uint2<span style="color: #339933;">;</span>
    FREGetObjectAsUint32<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>uint2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    uint32_t sum <span style="color: #339933;">=</span> uint1<span style="color: #339933;">*</span>uint2<span style="color: #339933;">;</span>
&nbsp;
    NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;%d*%d=%d&quot;</span><span style="color: #339933;">,</span>uint1<span style="color: #339933;">,</span>uint2<span style="color: #339933;">,</span>sum<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    FREObject sumToReturn <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span>
    FRENewObjectFromUint32<span style="color: #009900;">&#40;</span>sum<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>sumToReturn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> sumToReturn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>String (AS3->C->AS3) Concatenate function</h3>
<p>AS3 part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> concatenate<span style="color: #66cc66;">&#40;</span>str1:<span style="color: #0066CC;">String</span>,str2:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">String</span> = context.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;concatenate&quot;</span>,str1,str2<span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">String</span>;
	<span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>C/Obj-C part:<br />
// in this sample I wanted to go even further and utilize Obj-C function for concatenating strings and also demonstrate how to pass strings between C and Obj-C</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">FREObject concatenate<span style="color: #009900;">&#40;</span>FREContext ctx<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> funcData<span style="color: #339933;">,</span> uint32_t argc<span style="color: #339933;">,</span> FREObject argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// To be filled</span>
    uint32_t string1Length<span style="color: #339933;">;</span>
    <span style="color: #993333;">const</span> uint8_t <span style="color: #339933;">*</span>string1<span style="color: #339933;">;</span>
    FREGetObjectAsUTF8<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>string1Length<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>string1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    uint32_t string2Length<span style="color: #339933;">;</span>
    <span style="color: #993333;">const</span> uint8_t <span style="color: #339933;">*</span>string2<span style="color: #339933;">;</span>
    FREGetObjectAsUTF8<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>string2Length<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>string2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Convert C strings to Obj-C strings</span>
    NSString <span style="color: #339933;">*</span>string1ObjC <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSString stringWithUTF8String<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>string1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    NSString <span style="color: #339933;">*</span>string2ObjC <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSString stringWithUTF8String<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>string2<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Concat strings</span>
    NSString <span style="color: #339933;">*</span>returnString <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>string1ObjC stringByAppendingString<span style="color: #339933;">:</span>string2ObjC<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Convert Obj-C string to C UTF8String</span>
    <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>returnString UTF8String<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Prepare for AS3</span>
    FREObject retStr<span style="color: #339933;">;</span>
	FRENewObjectFromUTF8<span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> uint8_t<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>str<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>retStr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Return data back to ActionScript</span>
	<span style="color: #b1b100;">return</span> retStr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Boolean (AS3->C->AS3) Opposite function</h3>
<p>AS3 part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> opposite<span style="color: #66cc66;">&#40;</span>bool:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">Boolean</span> = context.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;opposite&quot;</span>,bool<span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Boolean</span>;
	<span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>C part:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">FREObject opposite<span style="color: #009900;">&#40;</span>FREContext ctx<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> funcData<span style="color: #339933;">,</span> uint32_t argc<span style="color: #339933;">,</span> FREObject argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    uint32_t boolean<span style="color: #339933;">;</span>
    FREGetObjectAsBool<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>boolean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    uint32_t oppositeValue <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>boolean<span style="color: #339933;">;</span>
&nbsp;
    FREObject retBool <span style="color: #339933;">=</span> nil<span style="color: #339933;">;</span>
    FRENewObjectFromBool<span style="color: #009900;">&#40;</span>oppositeValue<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>retBool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> retBool<span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Full C-part source code: <a href="http://www.flashrealtime.com/demos/ANEtutorial1/IOSExtension.m">IOSExtension.m</a><br />
Download <a href="http://www.flashrealtime.com/demos/ANEtutorial1/IOSExtension.zip">whole C-project</a> for Xcode</p>
<p>Complete AS3 SWC lib part: <a href="http://www.flashrealtime.com/demos/ANEtutorial1/IOSExtension.as">IOSExtension.as</a></p>
<p>Test project source (SWF/IPA): <a href="http://www.flashrealtime.com/demos/ANEtutorial1/IOSExtensionTest.as">IOSExtensionTest.as</a></p>
<p>For compiling native extension (*.ane) I use this command in Terminal.app. </p>
<p><b>compileExtension.sh</b> file/script</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">unzip <span style="color: #339933;">-</span>o IOSExtension.<span style="color: #202020;">swc</span>
&nbsp;
<span style="color: #339933;">/</span>PATH<span style="color: #339933;">/</span>TO<span style="color: #339933;">/</span>FLEX_AIR_SDK<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>adt <span style="color: #339933;">-</span>package <span style="color: #339933;">-</span>target ane IOSExtension.<span style="color: #202020;">ane</span> extension.<span style="color: #202020;">xml</span> <span style="color: #339933;">-</span>swc IOSExtension.<span style="color: #202020;">swc</span> <span style="color: #339933;">-</span>platform iPhone<span style="color: #339933;">-</span>ARM library.<span style="color: #202020;">swf</span> libIOSExtension.<span style="color: #202020;">a</span></pre></div></div>

<p><b>extension.xml</b> looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/extension/2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.krcha.IOSExtension<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platforms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platform</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;iPhone-ARM&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;applicationDeployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nativeLibrary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>libIOSExtension.a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nativeLibrary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ADBEExtInitializer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;finalizer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ADBEExtFinalizer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/finalizer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/applicationDeployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platforms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Christophe Coenraets On Backbone.js And PhoneGap</title>
		<link>http://feedproxy.google.com/~r/BenForta/~3/Xt88iYZHh4s/Christophe-Coenraets-On-Backbonejs-And-PhoneGap</link>
		<comments>http://feedproxy.google.com/~r/BenForta/~3/Xt88iYZHh4s/Christophe-Coenraets-On-Backbonejs-And-PhoneGap#comments</comments>
		<pubDate>Tue, 07 Feb 2012 01:57:00 +0000</pubDate>
		<dc:creator>Ben Forta</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://forta.com/blog/index.cfm/2012/2/6/Christophe-Coenraets-On-Backbonejs-And-PhoneGap</guid>
		<description><![CDATA[Fellow Adobe evangelist Christophe Coenraets recently posted a three part article on building a CRUD application using HTML and the Backbone.js framework. He has now followed it up with a post on building a mobile app using Backbone.js And PhoneGap.]]></description>
			<content:encoded><![CDATA[Fellow Adobe evangelist Christophe Coenraets recently <a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/">posted</a> a three part article on building a CRUD application using HTML and the Backbone.js framework. He has now followed it up with a <a href="http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/">post</a> on building a mobile app using Backbone.js And PhoneGap.<img src="http://feeds.feedburner.com/~r/BenForta/~4/Xt88iYZHh4s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://lifeasanevangelist.com/2012/02/07/christophe-coenraets-on-backbone-js-and-phonegap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Sample Mobile App with Backbone.js and PhoneGap</title>
		<link>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-mobile-app-with-backbone-js-and-phonegap</link>
		<comments>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-mobile-app-with-backbone-js-and-phonegap#comments</comments>
		<pubDate>Mon, 06 Feb 2012 17:27:53 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=2987</guid>
		<description><![CDATA[I recently blogged a tutorial (part 1, part 2, part 3, and postface) that takes you through the process of building a CRUD application using HTML and the Backbone.js framework. The application used in this tutorial is a Wine Cellar management app, and I thought it would be fun to create a Mobile version using [...]
	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Mobile%20App%20with%20Backbone.js%20and%20PhoneGap%20http://coenraets.org/blog/?p=2987" target="_blank">Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/" target="_blank">Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");]]></description>
			<content:encoded><![CDATA[<p>I recently blogged a tutorial (<a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/">part 1</a>, <a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-2-crud/">part 2</a>, <a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-3-deep-linking-and-application-states/">part 3</a>, and <a href="http://coenraets.org/blog/2012/01/backbone-js-lessons-learned-and-improved-sample-app/">postface</a>) that takes you through the process of building a CRUD application using HTML and the <a href="http://documentcloud.github.com/backbone/">Backbone.js</a> framework. The application used in this tutorial is a Wine Cellar management app, and I thought it would be fun to create a Mobile version using <a href="http://phonegap.com/">PhoneGap</a>.</p>
<p>PhoneGap &#8212; if you are not familiar with it &#8212; is an open source platform that allows you develop cross-platform Mobile applications using HTML and JavaScript. Specifically, it allows you to:</p>
<ol>
<li>Package an HTML application as a native app on all the key mobile platforms (iOS, Android, BlackBerry, Windows Phone, WebOS, Symbian, Bada).</li>
<li>Access your device capabilities (Camera, GPS, database, accelerometer, etc) using a cross-platform JavaScript API.</li>
</ol>
<p>Backbone.js is a great framework to give structure to your web application regardless of where it is running: in a traditional Web Browser, or as an app packaged with PhoneGap. </p>
<p>So, here is the app&#8230;<br />
<span id="more-2987"></span></p>
<p>
<img src="http://coenraets.org/blog/wp-content/uploads/2012/02/wine4.jpg" alt="" title="wine4" width="300" height="450" style="float: left;" /></p>
<p><img src="http://coenraets.org/blog/wp-content/uploads/2012/02/wine3.jpg" alt="" title="wine3" width="300" height="450" style="float: right;margin-top:-20px;"/>
</p>
<p style="clear: both;">&nbsp;</p>
<p>The UI is intentionally plain to keep the focus on the architectural framework. This is a simple &#8216;consumer&#8217; version of the application: It allows you to look for wines in your Wine Cellar. The tutorial application mentioned above is an &#8216;admin&#8217; version: You can create, update, delete wines in your Wine Cellar. Most of the code is shared between the Mobile &#8216;consumer&#8217; version and the browser-based &#8216;admin&#8217; version.</p>
<p>In this version, the application gets the data from RESTful services hosted on my server. In my next post, I will provide another version of the application that gets the data using a local database on your device.</p>
<h4>Download</h4>
<p>I added the source code for the mobile application to the <a href="https://github.com/ccoenraets/backbone-cellar">backbone-cellar GitHub repository</a>. You can download the zip file <a href="https://github.com/ccoenraets/backbone-cellar/zipball/master">here</a>. For your convenience, I created an <a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/ios">iOS directory</a> with the Xcode project and an <a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/android">Android directory</a> with the Eclipse project. The core application is in the www directory (<a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/ios/WineCellar/www">iOS</a> and <a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/android/BackboneCellarAndroid/assets/www">android</a>) and it is the same code for both iOS and Android.</p>
<p>If you want to run the application on your Android device without installing the project, you can also download the apk file available in the <a href="https://github.com/ccoenraets/backbone-cellar/tree/master/mobile/android/BackboneCellarAndroid/bin">bin directory</a>.</p>

	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Mobile%20App%20with%20Backbone.js%20and%20PhoneGap%20http://coenraets.org/blog/?p=2987" >Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/" >Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2012/02/sample-mobile-app-with-backbone-js-and-phonegap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next Gen Web Apps with Scala, BlueEyes, and MongoDB</title>
		<link>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=next-gen-web-apps-with-scala-blueeyes-and-mongodb</link>
		<comments>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=next-gen-web-apps-with-scala-blueeyes-and-mongodb#comments</comments>
		<pubDate>Mon, 06 Feb 2012 16:48:35 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=2998</guid>
		<description><![CDATA[Web application architecture is in the midst of a big paradigm shift. Since the inception of the web we&#8217;ve been treating the browser like a thin client. Apps just dump markup to the browser which is then rendered. Every interaction requires a request back to the server which then returns more logic-less markup to the [...]]]></description>
			<content:encoded><![CDATA[<p>Web application architecture is in the midst of a big paradigm shift.  Since the inception of the web we&#8217;ve been treating the browser like a thin client.  Apps just dump markup to the browser which is then rendered.  Every interaction requires a request back to the server which then returns more logic-less markup to the browser.  In this model our web applications are server applications.  There are certainly advantages to this model &#8211; especially when the markup consumers don&#8217;t have the capabilities to do anything more (or have inconsistent capabilities).</p>
<p>Web browser modernization has paved the way to move from the old &#8220;browser as a thin client&#8221; model to more of a Client/Server model where the client-side of the application actually runs in the browser.  There are a lot of names for this new model, Ajax being a step along the way, and perhaps HTML5 being the full realization of Client/Server web apps.</p>
<p>There are hundreds of new libraries, tools, programming languages, and services that support the creation of these next generation web (and mobile) apps.  One thing that is certainly lacking is one cohesive, end-to-end solution.  I have no doubt that we will be seeing those crop up soon, but in the mean time lets pick a few libraries and build a couple simple apps to get a better understanding of what this new model looks like.</p>
<p>I&#8217;ve decided to try this with a stack consisting of <a href="http://www.scala-lang.org/">Scala</a> for my back-end code, <a href="https://github.com/jdegoes/blueeyes">BlueEyes</a> for handling data access and serialization with transport over HTTP, <a href="http://mongodb.org">MongoDB</a> for data storage, and JavaScript with <a href="http://jquery.com/">jQuery</a> for the client-side.  I&#8217;m going to keep this very simple and not pull in anything else.  In future articles I&#8217;ll expand on this foundation.</p>
<p>So lets dive into some code.  All of the code is <a href="https://github.com/jamesward/helloblueeyes">on GitHub</a>.  If you want to get a local copy just do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jamesward<span style="color: #000000; font-weight: bold;">/</span>helloblueeyes.git</pre></div></div>

<p>This project uses the <a href="https://github.com/harrah/xsbt">Scala Build Tool (SBT)</a> for downloading dependencies, compiling, and packaging.  Follow the <a href="https://github.com/harrah/xsbt/wiki/Getting-Started-Setup">SBT setup instructions</a> if you want to be able to compile the code on your machine.  If you want to use IntelliJ or Eclipse then run one of the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt gen-idea</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt eclipse</pre></div></div>

<p>Lets start with some BlueEyes basics.  BlueEyes is a lightweight web framework built on Netty (a really high performance, NIO-based HTTP library).  BlueEyes makes it easy to define a tree of HTTP request handling patterns.  I chose BlueEyes because it&#8217;s really lightweight and utilizes some nice features of the Scala language to make the code very concise.  It&#8217;s kinda like a <a href="http://martinfowler.com/dsl.html">DSL</a> for HTTP request handling.</p>
<p>To get started with BlueEyes we first need to create an <strong>AppServer</strong> that provides a way to start the server and a place to plug services into.  Here is the code for the <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/AppServer.scala">AppServer</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">package</span> net.<span style="color: #000000;">interdoodle</span>.<span style="color: #000000;">example</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> AppServer <span style="color: #0000ff; font-weight: bold;">extends</span> EnvBlueEyesServer <span style="color: #0000ff; font-weight: bold;">with</span> HelloHtmlServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloJsonServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloStartupShutdownServices <span style="color: #0000ff; font-weight: bold;">with</span> HelloMongoServices</pre></div></div>

<p>My <strong>AppServer</strong> is an <strong>object</strong> which means it&#8217;s a singleton (that makes sense because I can&#8217;t have more than one of these in a single instance).  The <strong>AppServer</strong> extends <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/EnvBlueEyesServer.scala">EnvBlueEyesServer</a></strong> which is a wrapper around the base <strong>BlueEyesServer</strong> that provides a way to get the HTTP port via an environment variable (this is necessary for running on Heroku &#8211; which we will get to later).  The <strong>AppServer</strong> composes in a bunch of Services that actually setup HTTP request pattern trees.</p>
<p>Starting with the simplest one, <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloHtmlServices.scala">HelloHtmlServices</a></strong> we have:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloHtmlServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> helloHtml <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloHtml&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> context <span style="color: #000080;">=&gt;</span>
      request <span style="color: #F78811;">&#123;</span>
        path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request <span style="color: #000080;">=&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>Hello, world<span style="color: #000080;">!&lt;</span>/body<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> response <span style="color: #000080;">=</span> HttpResponse<span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>response<span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>Using the <strong>BlueEyesServiceBuilder</strong> the <strong>HelloHtmlServices</strong> trait creates a service that consists of a big pattern match that goes something like this: For a request to path &#8220;/&#8221;,  produce an HTML response when there is a HTTP GET request.  Notice that the <strong>response</strong> is actually wrapped in a <strong>Future</strong>.  This is an important part of the next generation web app architecture.  Because the underlying HTTP server is NIO-based (non-blocking), the actual HTTP handling threads can be very efficiently managed so that a thread is only in use when actual IO is happening.  BlueEyes supports this by using <strong>Future</strong> wrapped responses, allowing the HTTP thread to be unblocked by back-end processing.</p>
<p>If you want to try this out locally run the following to compile the app and create a Unix script that makes it easy to start the <strong>AppServer</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt stage</pre></div></div>

<p>Now start the <strong>AppServer</strong> process:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">target<span style="color: #000000; font-weight: bold;">/</span>start net.interdoodle.example.AppServer</pre></div></div>

<p>Verify that <strong>HelloHtmlServices</strong> is working by opening the following URL in your browser:<br />
<a href="http://localhost:8080/">http://localhost:8080/</a></p>
<p>Now lets walk through a few steps to deploy this application on the cloud with Heroku.<br />
<b>Step 1)</b> <a href="https://api.heroku.com/signup">Sign up for a Heroku account</a><br />
<b>Step 2)</b> <a href="http://toolbelt.herokuapp.com/">Install the Heroku Toolbelt</a><br />
<b>Step 3)</b> Login to Heroku from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

<p><b>Step 4)</b> Create a new application on Heroku using the Cedar stack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">-s</span> cedar</pre></div></div>

<p><b>Step 5)</b> Deploy the app on Heroku:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

<p><b>Step 6)</b> Verify that the app works in your browser:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku open</pre></div></div>

<p>Great!  We have an app built with Scala and BlueEyes running on the cloud.  Now for the next piece of the architecture. The UI of the application will be written in JavaScript and will run on the client-side.  But we need to have a way to transfer data between the client and the server.  JSON has become the regular way to do this because it is parsed easily and quickly on the client.  So a BlueEyes service will generate some JSON data that can then be consumed by a JavaScript application running on the client.  But how do we get that JavaScript application running on the client?  This is the next piece of the architecture.</p>
<p>Ideally the JSON services are served separately from the client-side of the application (where the client-side includes all HTML, JavaScript, CSS, images, and other static assets).  It is also ideal to serve the client-side from a Content Delivery Network (CDN) so that it&#8217;s edge cached and loads super fast.  Dynamic assets (the JSON services) can&#8217;t be edge cached so there is a logical (and functional) separation between the client-side and the server-side.  But there is a problem with this approach.</p>
<p>The CDN and the JSON services hosts each have different DNS names and browsers don&#8217;t allow cross-origin requests (actually they don&#8217;t allow access to the responses).  There are a few different ways to deal with this (JSONP, iframe hackery, etc) but the approach I&#8217;m taking is simple.  The JSON services server will serve an entry point / thin shim web page.  That shim then loads the rest of the client-side from the CDN and since the origin of the web page is the same as the JSON services, there is no need to make a cross-origin request.  (Side note: There is a new way to do cross-origin requests cleanly and natively in the browser, but it&#8217;s not ubiquitously supported yet.)</p>
<p>Here is <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloJsonServices.scala">HelloJsonServices</a></strong> that illustrates these patterns:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloJsonServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkJson <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> helloJson<span style="color: #000080;">:</span>HttpService<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloJson&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span> context<span style="color: #000080;">:</span>HttpServiceContext <span style="color: #000080;">=&gt;</span>
    request <span style="color: #F78811;">&#123;</span>
      path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/json&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jstring <span style="color: #000080;">=</span> JString<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello World!&quot;</span><span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jfield <span style="color: #000080;">=</span> JField<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;result&quot;</span>, jstring<span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> jobject <span style="color: #000080;">=</span> JObject<span style="color: #F78811;">&#40;</span>jfield <span style="color: #000080;">::</span> Nil<span style="color: #F78811;">&#41;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> response <span style="color: #000080;">=</span> HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>jobject<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
            Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>response<span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span> ~
        produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
            <span style="color: #0000ff; font-weight: bold;">val</span> contentUrl <span style="color: #000080;">=</span> System.<span style="color: #000000;">getenv</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;CONTENT_URL&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
            <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html xmlns<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>head<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;jquery-1.7.min.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;hello_json.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/head<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>
              <span style="color: #000080;">&lt;</span>/body<span style="color: #000080;">&gt;</span>
            <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
            Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This service handles requests to &#8220;/json&#8221; and if the requested content type is JSON then a simple JSON object is returned.  If the requested content is HTML then the shim web page is returned.  Inside the shim web page an environment variable, <strong>CONTENT_URL</strong>, is used to specify the URLs to load the JavaScript for the application.</p>
<p>The first JavaScript is the minified jQuery library.  This abstracts some browser differences, makes doing the JSON request and modifying the webpage very simple.  Here is the main client application <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/webapp/hello_json.js">hello_json.js</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/json&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This application has a function handler for when the page has loaded.  That function makes an ajax request to &#8220;/json&#8221; with the &#8220;application/json&#8221; content type.  Then on a successful response it just appends the result into the web page.</p>
<p>To run this locally first set the <strong>CONTENT_URL</strong> environment variable to the CDN where I&#8217;ve put the JavaScript files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CONTENT_URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>cdn-helloblueeyes.interdoodle.net<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now start (or restart) the server and open:<br />
<a href="http://localhost:8080/json">http://localhost:8080/json</a></p>
<p>To test the JSON service locally run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">--header</span> <span style="color: #ff0000;">&quot;Content-Type:application/json&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>json</pre></div></div>

<p>You can also use a local static file server for testing, just run <strong>net.interdoodle.example.httpstaticfileserver.HttpStaticFileServer</strong> and set <strong>CONTENT_URL</strong> accordingly.</p>
<p>If you want to try this on Heroku then set <strong>CONTENT_URL</strong> for your application:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku config:add <span style="color: #007800;">CONTENT_URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>cdn-helloblueeyes.interdoodle.net<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>This will set the environment variable and restart the application.  Then navigate to the your Heroku application&#8217;s &#8220;/json&#8221; URL in your browser.  Now both the server-side and client-side are cloudified!</p>
<p>Side Note: I&#8217;m using <a href="http://aws.amazon.com/cloudfront/">Amazon CloudFront</a> as the CDN for this example.  But any CDN would work fine.  There are various ways to upload files to Amazon CloudFront (actually they get uploaded to Amazon S3) but one thing I&#8217;m looking into is a SBT plugin that will do this.</p>
<p>Now lets add some simple data access into the mix.  I&#8217;ve chosen <a href="http://www.mongodb.org/">MongoDB</a> because it has native support for JSON and we can take advantage of <a href="https://github.com/bwmcadams/hammersmith">Hammersmith</a> &#8211; a non-blocking MongoDB driver.  In this example I&#8217;m not using Hammersmith since support for it hasn&#8217;t been officially added to BlueEyes (but at least there is the opportunity to easily switch to Hammersmith in the future).</p>
<p>Here is the code for <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/scala/net/interdoodle/example/HelloMongoServices.scala">HelloMongoServices</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">trait</span> HelloMongoServices <span style="color: #0000ff; font-weight: bold;">extends</span> BlueEyesServiceBuilder <span style="color: #0000ff; font-weight: bold;">with</span> MongoQueryBuilder <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkJson <span style="color: #0000ff; font-weight: bold;">with</span> BijectionsChunkString <span style="color: #F78811;">&#123;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> helloMongo <span style="color: #000080;">=</span> service<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;helloMongo&quot;</span>, <span style="color: #6666FF;">&quot;0.1&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    logging <span style="color: #F78811;">&#123;</span> log <span style="color: #000080;">=&gt;</span> context <span style="color: #000080;">=&gt;</span>
      startup <span style="color: #F78811;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// use MONGOLAB_URI in form: mongodb://username:password@host:port/database</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> mongolabUri <span style="color: #000080;">=</span> Properties.<span style="color: #000000;">envOrElse</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;MONGOLAB_URI&quot;</span>, <span style="color: #6666FF;">&quot;mongodb://127.0.0.1:27017/hello&quot;</span><span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> mongoURI <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> MongoURI<span style="color: #F78811;">&#40;</span>mongolabUri<span style="color: #F78811;">&#41;</span>
&nbsp;
        HelloConfig<span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">new</span> EnvMongo<span style="color: #F78811;">&#40;</span>mongoURI, context.<span style="color: #000000;">config</span>.<span style="color: #000000;">configMap</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;mongo&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">future</span>
      <span style="color: #F78811;">&#125;</span> -<span style="color: #000080;">&gt;</span>
      request <span style="color: #F78811;">&#123;</span> helloConfig<span style="color: #000080;">:</span> HelloConfig <span style="color: #000080;">=&gt;</span>
        path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/mongo&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              helloConfig.<span style="color: #000000;">database</span><span style="color: #F78811;">&#40;</span>selectAll.<span style="color: #000000;">from</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;bars&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> map <span style="color: #F78811;">&#123;</span> records <span style="color: #000080;">=&gt;</span>
                HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>JArray<span style="color: #F78811;">&#40;</span>records.<span style="color: #000000;">toList</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span> ~
          contentType<span style="color: #F78811;">&#40;</span>application/json<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            post <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              request.<span style="color: #000000;">content</span> map <span style="color: #F78811;">&#123;</span> jv<span style="color: #000080;">:</span> JValue <span style="color: #000080;">=&gt;</span>
                helloConfig.<span style="color: #000000;">database</span><span style="color: #F78811;">&#40;</span>insert<span style="color: #F78811;">&#40;</span>jv --<span style="color: #000080;">&gt;</span> classOf<span style="color: #F78811;">&#91;</span>JObject<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">into</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;bars&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
                Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> request.<span style="color: #000000;">content</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span> getOrElse <span style="color: #F78811;">&#123;</span>
                Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>JValue<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>status <span style="color: #000080;">=</span> HttpStatus<span style="color: #F78811;">&#40;</span>BadRequest<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
              <span style="color: #F78811;">&#125;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span> ~
          produce<span style="color: #F78811;">&#40;</span>text/html<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
            get <span style="color: #F78811;">&#123;</span> request<span style="color: #000080;">:</span> HttpRequest<span style="color: #F78811;">&#91;</span>ByteChunk<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=&gt;</span>
              <span style="color: #0000ff; font-weight: bold;">val</span> contentUrl <span style="color: #000080;">=</span> System.<span style="color: #000000;">getenv</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;CONTENT_URL&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
              <span style="color: #0000ff; font-weight: bold;">val</span> content <span style="color: #000080;">=</span> <span style="color: #000080;">&lt;</span>html xmlns<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>head<span style="color: #000080;">&gt;</span>
                                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;jquery-1.7.min.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                                <span style="color: #000080;">&lt;</span>script <span style="color: #0000ff; font-weight: bold;">type</span><span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;text/javascript&quot;</span> src<span style="color: #000080;">=</span><span style="color: #F78811;">&#123;</span>contentUrl + <span style="color: #6666FF;">&quot;hello_mongo.js&quot;</span><span style="color: #F78811;">&#125;</span><span style="color: #000080;">&gt;&lt;</span>/script<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>/head<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>
                              <span style="color: #000080;">&lt;</span>/body<span style="color: #000080;">&gt;</span>
                            <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
              Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span>HttpResponse<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>content <span style="color: #000080;">=</span> Some<span style="color: #F78811;">&#40;</span>content.<span style="color: #000000;">buildString</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">true</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
            <span style="color: #F78811;">&#125;</span>
          <span style="color: #F78811;">&#125;</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span> -<span style="color: #000080;">&gt;</span>
      shutdown <span style="color: #F78811;">&#123;</span> helloConfig<span style="color: #000080;">:</span> HelloConfig <span style="color: #000080;">=&gt;</span>
        Future.<span style="color: #000000;">sync</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This service has a startup hook that creates a MongoDB connection based on the <strong>MONGOLAB_URI</strong> environment variable or a default value.  Then there are three request handlers for the &#8220;/mongo&#8221; path.  The first handles JSON HTTP GET requests by fetching some data from MongoDB and returning it.  A JSON HTTP POST handler inserts the JSON that was sent into MongoDB.  Then there is a HTML HTTP GET request handler that returns the web page shim that loads the JavaScript from the CDN.</p>
<p>Here is the client-side of the application <strong><a href="https://github.com/jamesward/helloblueeyes/blob/master/src/main/webapp/hello_mongo.js">hello_mongo.js</a></strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;h4&gt;Bars:&lt;/h4&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul id=&quot;bars&quot;&gt;&lt;/ul&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input id=&quot;bar&quot;/&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;button id=&quot;submit&quot;&gt;GO!&lt;/button&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#submit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>addbar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bar&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            addbar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    loadbars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> loadbars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/mongo&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bars&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bars&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;li&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addbar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/mongo&quot;</span><span style="color: #339933;">,</span>
        type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'post'</span><span style="color: #339933;">,</span>
        dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> loadbars<span style="color: #339933;">,</span>
        data<span style="color: #339933;">:</span> <span style="color: #3366CC;">'{&quot;name&quot;: &quot;'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bar&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;}'</span><span style="color: #339933;">,</span>
        contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This JavaScript application starts by adding some elements to the page for displaying and entering &#8220;bars&#8221;.  The <strong>loadbars()</strong> function makes a ajax GET request to the JSON service and then appends the result into the element on the page with the id of <strong>bars</strong>.  The <strong>addbar()</strong> method makes a POST request to the JSON service, passing serialized JSON containing the name of the &#8220;bar&#8221; to the JSON service, then on success it calls <strong>loadbars()</strong>.</p>
<p>If you want to run this locally then you will need a MongoDB server setup and running locally.  Make sure <strong>CONTENT_URL</strong> is set correctly and if your MongoDB settings differ from the default, then set the <strong>MONGOLAB_URI</strong> environment variable.  Start the <strong>AppServer</strong> process and then open:<br />
<a href="http://localhost:8080/mongo">http://localhost:8080/mongo</a></p>
<p>You should be able to add new &#8220;bars&#8221; and see them listed.</p>
<p>To run on Heroku you will need to add the <a href="http://addons.heroku.com/mongolab">MongoLab add-on</a>.  When the MongoLab add-on is added the <strong>MONGOLAB_URI</strong> environment variable on your Heroku application will be automatically set with the connection information for the newly provisioned MongoDB system.  To add the MongoLab add-on just run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku addons:add mongolab</pre></div></div>

<p>Now open your Heroku app&#8217;s &#8220;/mongo&#8221; URL in your browser.  Wahoo!  You have a client/server browser app running on the cloud!  Hopefully that has helped you to get a glimpse of where web application architecture is going.  This is just part of the picture and I have a few other articles planned that will cover some of the other pieces.  So keep watching here and let me know what you think.</p>
<p>Acknowledgments: <a href="http://micronauticsresearch.com/">Mike Slinn</a>, a friend of mine that does Scala and Akka consulting, helped me understand BlueEyes and helped write some of the code for this project.  Mike is also the author of the recently released book <em><a href="http://slinnbooks.com/books/futures/index.jsp%20">Composable Futures with Akka 2.0 with Java and Scala Code Examples</a></em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/02/06/next-gen-web-apps-with-scala-blueeyes-mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex User Group 2012 Tour European Dates</title>
		<link>http://feedproxy.google.com/~r/BenForta/~3/pnty6PU2diE/Flex-User-Group-2012-Tour-European-Dates</link>
		<comments>http://feedproxy.google.com/~r/BenForta/~3/pnty6PU2diE/Flex-User-Group-2012-Tour-European-Dates#comments</comments>
		<pubDate>Sun, 05 Feb 2012 04:43:00 +0000</pubDate>
		<dc:creator>Ben Forta</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://forta.com/blog/index.cfm/2012/2/4/Flex-User-Group-2012-Tour-European-Dates</guid>
		<description><![CDATA[Following up on the Flex User Group 2012 Tour: North America Dates dates (mentioned recently), Flex User Group 2012 Tour: European Dates have now also been posted.]]></description>
			<content:encoded><![CDATA[Following up on the <a href="http://blogs.adobe.com/flex/2012/01/announcing-flex-user-group-2012-tour-north-america-dates.html">Flex User Group 2012 Tour: North America Dates</a> dates (<a href="http://forta.com/blog/index.cfm/2012/1/17/Flex-User-Group-2012-Tour-North-America-Dates">mentioned</a> recently), <a href="http://blogs.adobe.com/flex/2012/02/flex-user-group-2012-tour-european-dates.html">Flex User Group 2012 Tour: European Dates</a> have now also been posted.<img src="http://feeds.feedburner.com/~r/BenForta/~4/pnty6PU2diE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://lifeasanevangelist.com/2012/02/05/flex-user-group-2012-tour-european-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>HOWTO: Join multiple SWF files into one with AIR for iOS</title>
		<link>http://www.flashrealtime.com/how-to-join-swf-files-air-ios/</link>
		<comments>http://www.flashrealtime.com/how-to-join-swf-files-air-ios/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 23:59:08 +0000</pubDate>
		<dc:creator>Tom Krcha</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://www.flashrealtime.com/?p=2532</guid>
		<description><![CDATA[A while back, I promised to write some of the backstage tips that made it possible for Machinarium (1 GB sources!, 28 SWFs!) to run on an iPad with AIR, which requires only a single SWF. One of the issues you run into is how to join/concatenate 28 SWFs into single SWF. I wrote an [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http://www.flashrealtime.com/how-to-join-swf-files-air-ios/"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http://www.flashrealtime.com/how-to-join-swf-files-air-ios/&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>A while back, I promised to write some of the backstage tips that made it possible for Machinarium (1 GB sources!, 28 SWFs!) to run on an iPad with AIR, which requires only a single SWF.</p>
<p><img src="http://www.flashrealtime.com/wp-content/uploads/2012/02/compilationSWFone.png" alt="" title="compilationSWFone" width="187" height="189" class="alignnone size-full wp-image-2556" /></p>
<p>One of the issues you run into is how to join/concatenate 28 SWFs into single SWF. I wrote an article about using SWC libraries for that here <a href="http://www.flashrealtime.com/compiling-big-air-swf-to-ios/">Compiling big Flash/AIR projects with lot of SWFs for iOS</a>. This sometimes works, but very often the workflow is more complex and you want to keep the same SWF files for Android and iOS and use them at least in a bit similar way. On Android you can however load SWF files at the runtime and this is very effective for the memory usage. On iOS you have to watch this, especially when you have everything in a single SWF. So, ideally you place all assets into separate files and load them and dispose them on-demand. But that&#8217;s more of a general problem you should keep in mind &#8211; every asset that doesn&#8217;t contain AS3 (pictures, videos, music), put aside. But back to the topic.</p>
<p>Now comes the magic by <strong>David &#8216;Oldes&#8217; Oliva</strong> (the lead developer of <a href="http://www.machinarium.com">Machinarium</a>) from <a href="http://amanita-design.net">Amanita Design</a>, who made it all possible and wrote a script which can be used for joining SWFs together.</p>
<p><strong>Note: This solution allows you to use multiple SWF files containing AS3 script and logic in each of them, not only for assets. That&#8217;s why it&#8217;s so powerful.</strong></p>
<p><em>*prerequisite: you&#8217;ll need to understand how to work with the command-line on Mac or Windows.</em></p>
<h3>Steps:</h3>
<p>1) Prepare SWFs like you were using them the standard way, but instead of loading them dynamically via the Loader class, SWFLoader or a similar mechanism, each SWF has to be Class  (or contain at least one, can contain more), which you can instantiate. That&#8217;s because once you join all SWFs together, you will be instantiating it&#8217;s contents, not loading.</p>
<p>2) Download the samples package <a href="http://cl.ly/0g270t0K2Z082e0G1535">rswf-join-example.7z</a> (for unzipping use <a href="http://www.7-zip.org/">7-zip</a> compatible tool) / UPDATE: the file has been updated to support bitmap reduction</p>
<p>3) Download the REBOL script view environment <a href="http://www.rebol.com/download-view.html">http://www.rebol.com/download-view.html</a></p>
<p><strong>Using the tool:</strong></p>
<p>4) Navigate to the samples folder. There are three scripts that you might want adjust to fit your workflow:</p>
<p><strong><em>compile-and-run.r</em></strong><br />
- this is the rebol script that does part of the job and runs Game.bat</p>
<p><strong><em>Game.bat</em></strong><br />
- here you want to adjust the path to your Flex/AIR SDK so it points to the adl command</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">cd .<span style="color: #339933;">/</span>public<span style="color: #339933;">/</span>
<span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>AIR_SDK<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>adl Game.<span style="color: #202020;">xml</span></pre></div></div>

<p><strong><em>Game.rswf</em></strong><br />
- here you specify the SWFs you want to compile together, in the samples, you can see FLAs and it&#8217;s content to understand how to prepare your own workflow.</p>
<p>5) Run the compilation (of course change the path to rebol to the directory, where you have downloaded it or stored it)</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>REBOL<span style="color: #339933;">/</span>rebol compile<span style="color: #339933;">-</span>and<span style="color: #339933;">-</span>run.<span style="color: #202020;">r</span></pre></div></div>

<p>*At this point, if you get permission denied on some of the files, make sure all the processing files have the proper rights; you can set the rights using chmod, for instance:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">chmod <span style="color: #0000dd;">777</span> filename.<span style="color: #202020;">bat</span></pre></div></div>

<p>also 777 is pretty open rule, so consider 755 or 775 or similar.</p>
<p><strong>6) Once the compilation is done, the SWF will open and you can successfully use it with adt command from the Flex/AIR SDK to compile the final IPA for iOS.</strong></p>
<p>If you have any questions, please ask in the comments.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashrealtime.com/how-to-join-swf-files-air-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Application with Angular.js</title>
		<link>http://coenraets.org/blog/2012/02/sample-application-with-angular-js/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-application-with-angular-js</link>
		<comments>http://coenraets.org/blog/2012/02/sample-application-with-angular-js/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sample-application-with-angular-js#comments</comments>
		<pubDate>Thu, 02 Feb 2012 20:33:32 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/?p=2889</guid>
		<description><![CDATA[After I blogged a three-part Backbone.js tutorial (part 1, part 2, part 3), a number of people asked me to try Angular.js. So I decided to take it for a test drive. I thought it would be interesting to rebuild with Angular.js the Wine Cellar application I had built with Backbone. If you are new [...]
	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Application%20with%20Angular.js%20http://coenraets.org/blog/?p=2889" target="_blank">Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-application-with-angular-js/" target="_blank">Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");]]></description>
			<content:encoded><![CDATA[<p>After I blogged a three-part Backbone.js tutorial (<a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-1-getting-started/">part 1</a>, <a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-2-crud/">part 2</a>, <a href="http://coenraets.org/blog/2011/12/backbone-js-wine-cellar-tutorial-part-3-deep-linking-and-application-states/">part 3</a>), a number of people asked me to try <a href="http://angularjs.org/">Angular.js</a>. So I decided to take it for a test drive. I thought it would be interesting to rebuild with Angular.js the Wine Cellar application I had built with Backbone.<br />
<span id="more-2889"></span></p>
<p><img src="http://coenraets.org/blog/wp-content/uploads/2011/12/cellar2.jpg" alt="" title="cellar2" width="640" height="496" class="alignnone size-full wp-image-2392" /></p>
<p>If you are new to my Wine Cellar application, it is a simple CRUD app that allows you to manage (create, update, delete) wines in a Wine Cellar. The data is stored in a MySQL database that the client application accesses through a simple RESTful API. This seemed to be a good fit since CRUD applications are often positioned as the sweet spot for Angular.js.</p>
<p>You can run the application <a href="http://coenraets.org/angular-cellar">here</a>. The UI is intentionally plain to keep the focus on the key learning points. For obvious reasons, this online version is &#8220;read-only&#8221;. You can download the fully enabled version <a href="https://github.com/ccoenraets/angular-cellar">here</a>. </p>
<h4>Application Walkthrough</h4>
<p>The best way to get started with Angular.js is to go through the <a href="http://docs.angularjs.org/#!/tutorial">excellent tutorial</a> that is part of the documentation, so I&#8217;ll only provide a high level overview of my code here. </p>
<p>Like the Backbone.js implementation, the Angular.js version is a deep-linkable single page application. index.html is defined as follows:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html xmlns:ng=&quot;http://angularjs.org&quot;&gt;
&lt;head&gt;
&lt;title&gt;Angular Cellar&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;css/styles.css&quot; /&gt;
&lt;/head&gt;

&lt;body ng:controller=&quot;RouteCtrl&quot;&gt;

&lt;div id=&quot;header&quot;&gt;
    Angular Cellar
    &lt;button ng:click=&quot;addWine()&quot;&gt;New Wine&lt;/button&gt;
&lt;/div&gt;

&lt;div id=&quot;sidebar&quot;&gt;
    &lt;ng:include src=&quot;'tpl/wine-list.html'&quot;&gt;&lt;/ng:include&gt;
&lt;/div&gt;

&lt;div id=&quot;content&quot;&gt;
    &lt;ng:view&gt;&lt;/ng:view&gt;
&lt;/div&gt;

&lt;script src=&quot;lib/angular-0.9.19.min.js&quot; ng:autobind&gt;&lt;/script&gt;
&lt;script src=&quot;js/services.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/controllers.js&quot;&gt;&lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>The application is driven by a set of <strong>Controllers</strong> that I defined in controllers.js as follows:</p>
<pre class="brush: jscript; title: ; notranslate">
function RouteCtrl($route) {

    var self = this;

    $route.when('/wines', {template:'tpl/welcome.html'});

    $route.when('/wines/:wineId', {template:'tpl/wine-details.html', controller:WineDetailCtrl});

    $route.otherwise({redirectTo:'/wines'});

    $route.onChange(function () {
        self.params = $route.current.params;
    });

    $route.parent(this);

    this.addWine = function () {
        window.location = &quot;#/wines/add&quot;;
    };

}

function WineListCtrl(Wine) {

    this.wines = Wine.query();

}

function WineDetailCtrl(Wine) {

    this.wine = Wine.get({wineId:this.params.wineId});

    this.saveWine = function () {
        if (this.wine.id &gt; 0)
            this.wine.$update({wineId:this.wine.id});
        else
            this.wine.$save();
        window.location = &quot;#/wines&quot;;
    }

    this.deleteWine = function () {
        this.wine.$delete({wineId:this.wine.id}, function() {
            alert('Wine ' + wine.name + ' deleted')
            window.location = &quot;#/wines&quot;;
        });
    }

}
</pre>
<p><strong>RouteCtrl</strong> defines the routes of the application. Each route is defined by a template that is rendered in &lt;ng:view&gt; inside index.html. There can only be one &lt;ng:view&gt; in a document (more on that later). For example, here is the wine-list.html template:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul ng:controller=&quot;WineListCtrl&quot;&gt;
    &lt;li ng:repeat=&quot;wine in wines&quot;&gt;
        &lt;a href='#/wines/{{ wine.id }}'&gt;{{ wine.name }}&lt;/a&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>The <strong>WineListCtrl</strong> and <strong>WineDetailCtrl</strong> controllers provide access to the data using a service defined in services.js as follows: </p>
<pre class="brush: jscript; title: ; notranslate">
angular.service('Wine', function ($resource) {
    return $resource('api/wines/:wineId', {}, {
        update: {method:'PUT'}
    });
});
</pre>
<p>Services provide a great way to abstract your data access logic, and to easily change it without impacting the rest of the application. For example, you could easily change the Wine service to use a Mock service instead of a RESTful service.</p>
<h4>Impressions</h4>
<p>I was able to build this application in a very limited amount of time with no prior knowledge of the framework. The data-binding implementation is nice, and, in general, the amount of boilerplate code you have to write is very limited. Frameworks are often a matter of style and personal preferences. Angular.js takes a more declarative approach than other frameworks. Based on this initial experience, I would also describe it as more prescriptive: I didn&#8217;t have to spend a lot of time wondering what was the best way to do things as Angular.js tends to have clear utilization patterns. I haven&#8217;t spend enough time with the framework to determine if that comes at the cost of less control, and I&#8217;d love to hear what other people are thinking.</p>
<p>The only problem I ran into while building the application is the &#8220;one route / one view&#8221; coupling I alluded to above. As suggested in <a href="http://groups.google.com/group/angular/browse_thread/thread/c482321a95bc2949/2e5c9074485c102d?hide_quotes=no">this thread</a>, you can use &lt;ng:include&gt; to bind partials in the page. The same thread also indicates that multiple &lt;ng:views&gt; per route definition will be supported in the future. I was able to handle the simple UI requirements of this app using one &lt;ng:view&gt; and one &lt;ng:include&gt;. For more complex applications, I&#8217;d love the routing infrastructure to allow me to easily and arbitrarily add, remove, change, or animate different elements of the DOM when the route changes in order to support deeper UI transformations. I&#8217;m sure there are ways to do this. If Angular.js folks are reading this post, I&#8217;d love to hear what they think and what&#8217;s coming.</p>
<h4>Download</h4>
<p>The application is available on GitHub <a href="https://github.com/ccoenraets/angular-cellar">here</a>. </p>
<p>You will need the RESTful services to run this application. A PHP version (using the Slim framework) is available as part of the download. If you want to test the application with a Java back-end, you can download the Backbone version <a href="https://github.com/ccoenraets/backbone-jax-cellar">here</a>, and reuse its JAX-RS back-end.</p>

	
<!-- Start WP Socializer Plugin - Retweet Button -->
<a href="http://twitter.com/?status=RT%20@%20Sample%20Application%20with%20Angular.js%20http://coenraets.org/blog/?p=2889" >Retweet this</a>
<!-- End WP Socializer Plugin - Retweet Button -->

	
	
<!-- Start WP Socializer Plugin - Facebook Button -->
<a href="https://www.facebook.com/sharer.php?u=http://coenraets.org/blog/2012/02/sample-application-with-angular-js/" >Share on Facebook</a>
<!-- End WP Socializer Plugin - Facebook Button -->



Follow @ccoenraets
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2012/02/sample-application-with-angular-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

