Cappuccino: the jake branch


Those steps assumes you have already setup your Cappuccino source similarly to my environment.

If not, please read previous articles.

Keep in mind that the “jake” branch will be merged into master at some point, and the switch should happen sometime in the upcoming weeks; at least I’ve been told this way so take this information with a grain of salt.
Therefore: those instructions can turn obsolete at any time and probably are.

If you read my previous article you already know that I’m running Snow Leopard.
At any point do not close the Terminal window until you did every step.

Download Narwhal from GitHub.

cd ~/src/
git clone git://github.com/tlrobinson/narwhal.git

Activate paths and use tusk to install required packages.

source ~/src/narwhal/bin/activate
tusk install jake browserjs narwhal-jsc jack

Build Narwhal JSC:

cd ~/src/narwhal/packages/narwhal-jsc
make webkit
export NARWHAL_ENGINE=jsc

Build Cappuccino:

# if you don't already have a cappuccino source remember to have a CAPP_BUILD defined and
# git clone git://github.com/280north/cappuccino.git ~/src/cappuccino_source
cd ~/src/cappuccino_source
git checkout -b jake origin/jake
rm -rf $CAPP_BUILD
jake
jake debug # if you want also the Debug build
jake docs # if you want up to date local xml/html documentation, requires doxygen

20091024-d7sqyb241537a5fcbjd5i5sui9

Building Cappuccino with jake instead of rake will take some minutes to compile.

I read about some people reporting that the process gets stuck, this didn’t happened to me (well it did, but because I was compiling against master by mistake); the jake building process took about 4 minutes to complete on a 2,53 GHz Unibody Intel Core 2 Duo Macbook Pro.

We are going to tweak our $PATH in order to find the new Cappuccino Tools and Narwhal binaries like jake.
Keep in mind that you probably already have them in /usr/local/bin so we must adjust our PATH with some precedence.
Old utilities in /usr/local/bin aren’t modified by this procedure, since the jake task that should install them is currently commented.

Here is my .bash_profile related code:

# CAPP_BUILD, directory for built Cappuccino framework.
export CAPP_BUILD="$HOME/src/cappuccino_framework"
 
# Cappuccino jake branch.
PATH="$CAPP_BUILD/Release/CommonJS/objective-j/bin:$PATH"
PATH="$HOME/src/narwhal/bin:$PATH"
 
# Finalize PATH
export PATH=$PATH

This will make capp, nib2cib and press available on command line.

Reopen Terminal and test:

03:52 ~ $ which capp
/Users/kain/src/cappuccino_framework/Release/CommonJS/objective-j/bin/capp
22:42 ~ $ cd Sites/
22:42 ~/Sites $ capp gen MySecondApp -t NibApplication
/Users/kain/src/cappuccino_framework/Release/CommonJS/objective-j/lib/capp/Resources/Templates/NibApplication -> MySecondApp
# ...

Have fun!

$1.99 domains with SSL purchase!

On Cappuccino spriting and why it matters, part 1

sheets4qx
The first working builds of sprited Cappuccino were released around 14th October.

If you’re familiar with Cappuccino this means frameworks that include images/themes and also entire applications can be sprited.
This will be the default behaviour for Cappuccino applications, we’ll talk about advantages in a bit, first, a word about spriting if you’re wondering what is it.

Developed around mid-1970, spriting is a technique still used today; if you’re into CSS you might have used it.
If you’re old enough and curious you may have also dug into a videogame’s resource files and you may have seen images composed of multiple little images in a grid.

In fact spriting mostly consists in placing images into a larger image grid, and display the image we are requesting by supplying its correct position in the grid.

What that means in Cappuccino?

Simply put, by using spriting, Cappuccino can squeeze all your project’s images in a single file, thus reducing the number of requested/served files.

This is a big gainer, since Cappuccino also makes intensive use of themes; Aristo, the now default theme, counts around 111 files.
They will be only 2 after spriting kicks in for all users in master branch.

The wonderful thing is that it’s built-in, you are not required to do this kind of stuff. Couple that with the fact that will be using Narwhal-JSC soon, Cappuccino will be *really* fast.

I will discuss with Francisco Tolmasky (tolmasky) of 280 North about how spriting works in Cappuccino and as usual will report my findings here, in a second part of the article.

Foundation.j and AppKit.j 404

During some Rails integration with Cappuccino I noticed that my Rails’ logs were filling fast with 404s.

At first I thought I did something wrong in including my Frameworks, however it turns out that’s a normal behaviour by design.

I won’t go into the details here on why it’s happening, but here’s a solution:

Ruby on Rails

To avoid the stack trace generation overhead in Rails simply put down those routes:

  map.connect '/Frameworks/Foundation/Foundation.j',
    :controller => 'application',
    :action     => 'handle_cappuccino_404',
    :conditions => { :method => :get }
  map.connect '/Frameworks/AppKit/AppKit.j',
    :controller => 'application',
    :action     => 'handle_cappuccino_404',
    :conditions => { :method => :get }

Then in your handle_cappuccino_404 method you can simply render :nothing => true:

class ApplicationController < ActionController::Base
  def handle_cappuccino_404
    render :nothing => true
  end
end

I think we can’t rescue_from ActionController::RoutingError at this point.
Please also read another solution involving Rails Metal below.

Rails Metal

I was thinking about using Rails Metal to avoid even the extra bits:

script/generate metal cappuccino

Then in app/metal/cappuccino.rb:

require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
 
class Cappuccino
  def self.call(env)
    if env["PATH_INFO"] =~ /^\/Frameworks\/Foundation|AppKit\/Foundation|AppKit.j/
      [200, {"Content-Type" => "text/html"}, []]
    else
      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
    end
  end
end

No need for the method described above: you can safely remove routes and the 404 handling method from your controller.

Sinatra

To avoid it in Sinatra:

# from http://github.com/mchung/cappuccino_sandbox
get "/Frameworks/AppKit/AppKit.j" do
  [404, {}, "Look elsewhere"]
end
get "/Frameworks/AppKit/Foundation.j" do
  [404, {}, "Look elsewhere"]
end

Creating a Cappuccino application with capp

cappuccino-icon
This is the second part of the Cappuccino bits series.

  1. Installing Cappuccino from source.
  2. Creating a Cappuccino application with capp.
  3. Playing with a Cappuccino project (TBA)

If you missed the part 1 I suggest reading it now before proceeding. If you don’t at least be sure you did understand the meaning of CAPP_BUILD and have it correctly setup.

capp is a dual utility that can help in generating your application and setting some environmental variables that Cappuccino will use. It’s part of Cappuccino’s Tools.

First, let’s take a look at the config options it can set:

  • user.name
  • user.email
  • organization.name
  • organization.url
  • organization.email
  • organization.identifier

You can get a view of what config options are already set with:

capp config -l

Start setting your config options with command:

capp config key "value"

where key is one of the values shown above, and value is actually what you want to be in the chosen key.

capp config user.name "Claudio Poli"
capp config organization.name "iCoreTech Research Labs"

Those will be used, for example, in the comments when an application gets generated by the capp command.

While config options’ description is pretty straightforward it should be noted that organization.identifier is the less recognizable; it’s the reserved domain identifier, commonly used when creating Mac applications.
You can set it to the format "com.mycompany" or "org.bestcompany", then if you create a project called MyApp its identifier becomes "com.mycompany.MyApp".

It’s worth noticing that you can see a single option value by running:

capp config --get key

where key is one of the options I wrote above, even though you may just well want capp config -l (or --list).

Once we setup our capp environment, we can go hands down in creating a whole new application.

If you run

capp -h

you can see a helpful guide on how to use capp.

Now, instead of using "capp config" we are going to use the generator part, namely "capp gen".

In the small usage banner after gen PATH we can see some options we can use, so pick the one you need, explained below:

capp gen MyWebSite


This will create a directory MyWebSite in the current directory you are currently in when you executed capp.
Of course you can also supply a full path instead of MyWebSite.
The generated application is a bare-metal Cappuccino/Objective-j application, called by the templating system "Application".
No xib/nib/cib files here, the initial code in Application.j is instructed to just show the basics.

Also note that in the MyWebSite directory there’s a folder called Framework. That’s right, capp gen PATH without further parameters copy the entire frameworks from a previous Cappuccino installation (see the part 1 of the tutorial) to your project.

This may be desiderable when working on a stable version, however we would like to have the entire framework symlinked to a special directory that we are interested in keeping up to date with recent Cappuccino changes.

In order to accomplish that, run:

capp gen MyWebSite -l


This will be still a bare-metal application, but if you go into Frameworks directory you’ll notice that AppKit, Foundation and Objective-J folders are simbolic links:

22:51 ~/Sites/MyWebSite/Frameworks $ ls -lha
total 24
drwxr-xr-x   6 kain  staff   204B 21 Ott 22:50 .
drwxr-xr-x  11 kain  staff   374B 21 Ott 22:50 ..
lrwxr-xr-x   1 kain  staff    51B 21 Ott 22:50 AppKit -> /Users/kain/src/cappuccino_framework/Release/AppKit
drwxr-xr-x   5 kain  staff   170B 21 Ott 22:50 Debug
lrwxr-xr-x   1 kain  staff    55B 21 Ott 22:50 Foundation -> /Users/kain/src/cappuccino_framework/Release/Foundation
lrwxr-xr-x   1 kain  staff    56B 21 Ott 22:50 Objective-J -> /Users/kain/src/cappuccino_framework/Release/Objective-J

This explains why the CAPP_BUILD env variable is so important even before trying to install Cappuccino Tools.

If instead of generating a whole application we only need to put Frameworks files in place we can run:

capp gen MyWebSite -f


Instead of -f you can use the verbose --frameworks, add -l for some extra, already explained, fun.

Ideally if you want to keep Cappuccino up to date you should follow the instructions in part 1 to git pull and recompile the framework.

This is the last option we will be covering for today, and it’s the one used to generate a project by using a Template.

You can see the actual list of templates by listing the contents of a specific directory:

ls -lha /usr/local/share/narwhal/packages/objj/lib/capp/Resources/Templates

You will see three templates:

  • Application
  • NibApplication
  • ThemeDescriptor

When creating your application you can choose your template by using the -t switch, so for example:

capp gen MyWebSite -t NibApplication

Application is the code generated when the -t switch is omitted.

NibApplication is an application skeleton that already implements code for running a nib/cib/xib based application, included in Resources. Also the Application.j and other files’ code is different.
For example Application.j contains a member variable that references a CPWindow, already in the nib file, and awakeFromCib is instructed to make the window go fullBridge, meaning full browser window. In this kind of application the graphics user interface is left in the nib file.

ThemeDescriptor is a special project for creating custom Cappuccino themes.

Tutorials ends here, thanks for reading. As usual feedback is appreciated.

Next: playing with a Cappuccino project.

Cappuccino logo used with permission. Cappuccino is a trademark of 280 North.

Installing Cappuccino from source


This is a series of tutorials about Cappuccino framework and they are based on my findings, especially the ones that often aren’t well documented or confusing.

Table of contents:

  1. Installing Cappuccino from source.
  2. Creating a Cappuccino application with capp.
  3. Playing with a Cappuccino project (TBA)

We are going to install Cappuccino from source, using git and github.
You need to install Git prior to this task, I covered the installation on Snow Leopard here or you can download some packages here.

The environment I’ll use is Snow Leopard, running stock Ruby.
We are going to use rake to build Cappuccino, se be sure it’s up to date with:

sudo gem install rake

You can install rake without sudo, and it will install itself in a gem directory under your home folder, you will have to add the bin directory to your PATH though.

Before you do anything you will have to setup a CAPP_BUILD environment variable.
This variable represents a directory that will store your Cappuccino framework copy.
I usually use a directory ~/src to store source code (or /SourceCache on a server) and ~/Sites to store my web projects.
So please keep this in mind and change the code represented here accordingly.

We are required Terminal usage, so open up a new Terminal and write:

mkdir ~/src/cappuccino_framework

Then open up your ~/.bash_profile or ~/.bash_login with your favorite editor and add:

export CAPP_BUILD="/Users/kain/src/cappuccino_framework"
export PATH=$PATH:/usr/local/bin # if you don't have it already

Of course replace kain with your username.

Save and close the file, run:

source ~/.bash_profile

in order to reload the changes without launching a new Terminal tab/window.

Now that our CAPP_BUILD is in place we can start downloading Cappuccino itself.

git clone git://github.com/280north/cappuccino.git ~/src/cappuccino_source

Please note that I’m not downloading Cappuccino from Git in CAPP_BUILD.
This directory have another purpose: as already said it stores our Cappuccino framework copy.

Once the download is over, cd into cappuccino_source directory and execute the install command:

cd ~/src/cappuccino_source && rake install

This will install Cappuccino Tools and Framework from source asking for superuser password when needed.

In order to keep our Cappuccino source up do date if we see that an important commit on GitHub have been done, we can cd into our cappuccino_source directory and run:

git pull # to update our tree from GitHub
rake clobber-all install # or only rake install

Extra bit for TextMate users, install Objective-J bundle:

open ./Build/Cappuccino/Tools/Editors/TextMate/JavaScript\ Objective-J.tmbundle

For non-TextMate users, have a look into ~/src/cappuccino_source/Build/Cappuccino/Tools/Editors directory.
Currently there’s support for Emacs, SubEthaEdit, TextMate, Vim and Xcode.

If you want to install Xcode support, double click on install.command, this will create a "~/Library/Application Support/Developer/Shared/Xcode/Specifications" directory if it does not already exist and copy the ObjectiveJ.* files to that directory.
Another bonus I tried but doesn’t seems up to date: Cappuccino Developer Tools.
Restart Xcode for the changes to take effect.

Tutorials ends here, remember, set your $CAPP_BUILD env variable before doing anything, this is important. If you keep the same directory structure when working or updating Cappuccino you don’t need to touch it again.

If you find this information useful or want to leave some feedback just use the comments form. Thanks.

Update:
Online API documentation is old. In the meantime you can generate your own on your local machine by installing Doxygen.
The fastest way is to have ports install Doxygen, and then run in cappuccino_source this command:

doxygen Tools/Documentation/Cappuccino.doxygen

or more simply:

rake docs

in your cappuccino_source directory.

Next: use capp to generate a Cappuccino application.

Cappuccino is a trademark of 280 North.
Thanks to #cappuccino (irc.freenode.net) people: tolmasky, nciagra, boucher, saikat for feedback.

obj-j bits

Gotcha bits, taken from obj-j tutorial.

  • Objective-J has two types of objects, native JavaScript objects and Objective-J objects
  • The beginning of a class is always the keyword @implementation, followed by the class name
  • Each method signature starts with either a dash (-) or a plus (+)
  • Dashes are used for instance methods
  • One pattern you’ll find in Objective-J and Cappuccino is the idea of passing a method as an argument to another method
  • The alloc class method is analogous to the “new” keyword in many languages
  • The init instance methods are like the constructors in those languages, in that they perform initialization on the newly created instance
  • Some classes specify their own custom init method
  • “self” is the Objective-J equivalent to JavaScript’s “this”
  • There are two types of import statements. The angle brackets indicate framework code, while the quotation marks indicate local project code
  • JavaScript is garbage collected, and so is Objective-J, so you won’t see any calls to retain or release in Objective-J code as you would in Objective-C
  • Categories allow you to add methods to a class without needing to create a new subclass or modify the class’s source code
  • The syntax for the category is @implementation, followed by the class you’re adding to, followed by the name of your category in parentheses
  • Technique called toll-free bridging which allows any JavaScript object like an array or a string to act both as a JavaScript object and a Cappuccino object at the same time
  • Variables not specifically declared with var become globals

Microsoft is gone.

My girlfriend's dog explains why SaaS is the way to go

My girlfriend's dog explains why SaaS is the way to go

In a rapid-changing, technologically speaking, world every day, even hour, a new software product comes to life. Chances are that this product is web based.

That said, I see 2010 as the final year for a potential revolution from desktop-to-web apps.
The numbers are here, and the technology to do it too; we already saw the rise of javascript and css, squeezed to the extreme to craft nifty and useful web applications.
We are starting to see frameworks like Cappuccino along with Atlas, and Titanium.

There will be almost no difference for the end user in terms of usability.

But for us developers? Well, there are advantage is porting your legacy app to web and let them take a breath of fresh air; SaaS, software as a service, it’s a consolidated way of doing business. Oh, and nobody will be able to pirate your serial numbers, because they don’t need one.

Continue reading

Rails vs. Tarantula

There are times when you, as a lone developer, simply don’t have time to write tests.

It’s bad but can happen, but I can guarantee that even if your application is small or simple it probably does contains some bugs, especially if you are forced to write it on the fly and fast (which should be the only reason to excuse your lack of tests).

Sending an application straight into production without running tests is bad, I can’t stress it enough.

However there’s a solution to have some little tests running prior in distributing your app: Tarantula.
Continue reading