Size: 264
Comment:
|
Size: 4906
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
Line 5: | Line 6: |
== Init String, CPString == | Objective-J is a powerful object-oriented language which compiles to run in the browser. |
Line 7: | Line 8: |
{{{ | API [[http://www.cappuccino-project.org/learn/documentation/]] == Get the code == Clone it using git: * cd ~ * mkdir gitCappuccino * cd gitCappuccino * git clone git://github.com/cappuccino/cappuccino.git * cd ~/gitCappuccino/cappuccino == Vim editor Objective-J plugin == Run the follwoing commands after fetching code from github: * mkdir -p ~/.vim/plugin * cd ~/gitCappuccino/cappuccino/Tools/Editors/Vim] * cp objj.vim ~/.vim/plugin == Emacs editor Objective-J plugin == * mkdir ~/cappuccinoEmacs * cd ~/gitCappuccino/cappuccino/Tools/Editors/Emacs * cp *.el ~/cappuccinoEmacs/ * touch ~/.emacs * nano ~/.emacs * (add-to-list 'load-path "~/cappuccinoEmacs") * (require 'objj-mode) == Init String, stringWithFormat, CPString == {{{#!highlight objectivej |
Line 9: | Line 38: |
var str2 = [CPString initWithString: @""]; | var str2 = [CPString initWithString: @""]; var str3 = [CPString stringWithFormat:"StrX %s %s %s" , [obj field1] , [obj field2] , [obj field3] ]; |
Line 11: | Line 41: |
== Mutable Array == {{{#!highlight objectivej @import <Foundation/CPMutableArray.j> var arrayX = [[CPMutableArray alloc] init]; }}} == Callbacks == {{{#!highlight objectivej @implementation TestObject : CPObject { } -(void)helloWorld{ CPLogConsole("Called hello world"); } //(...) @end //-------------------- var selectorHelloWorld = @selector(helloWorld) ; var signature = [self methodSignatureForSelector: aSelector]; var invocation = [CPInvocation invocationWithMethodSignature:signature]; [invocation setSelector: selectorHelloWorld]; [invocation invokeWithTarget: self]; //self -> instance of TestObject }}} {{{#!highlight objectivej @implementation TestObject : CPObject { } -(void)helloWorldMsg:(CPString) message p1:(int)intVal { CPLogConsole( message ); CPLogConsole( intVal ); } //(...) @end //-------------------- var selectorHelloWorldMsg = @selector(helloWorldMsg:p1:) ; var sig = [self methodSignatureForSelector: selectorHelloWorldMsg]; var invocation = [CPInvocation invocationWithMethodSignature:sig]; [invocation setSelector: selectorHelloWorldMsg]; [invocation setArgument:@"Message" atIndex:2 ]; //0-> self 1->_cmd [invocation setArgument: 1234 atIndex:3 ]; //0-> self 1->_cmd [invocation invokeWithTarget: self]; }}} == Dates == {{{#!highlight objectivej var datex = [CPDate dateWithTimeIntervalSince1970: dateInSeconds]; //set CPDate with seconds since 01-01-1970 UTC var strDate = [instanceCPDate description];// get string with date in format YYYY-MM-DD HH:MM:SS TZ±HHMM. }}} == Dictionary from JSON object == {{{#!highlight objectivej - (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data { var dict = [CPDictionary dictionaryWithJSObject: [data objectFromJSON] ]; [textField setStringValue: [dict valueForKey:@"lkeyx"] ]; } - (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error { } }}} == URL request == {{{#!highlight objectivej var url = [CPString stringWithFormat:"/JEE-war/rest/getInfo/%@", [textField stringValue] ] ; var request = [CPURLRequest requestWithURL: url ]; var connection = [CPURLConnection connectionWithRequest:request delegate:self]; //calls didFailWithError and didReceiveData }}} == Mime types Glassfish + JBoss == Adapted from [[https://github.com/cappuccino/cappuccino/wiki/Server-Side-Issues]] You need to have the mime type of file types it doesn’t understand set to something for Cappuccino to work. Specifically, you should set the following mime-type/extension pairs. This can be done in the '''web.xml''': {{{#!highlight xml <mime-mapping> <extension>j</extension> <mime-type>text/javascript</mime-type> </mime-mapping> <mime-mapping> <extension>plist</extension> <mime-type>text/xml</mime-type> </mime-mapping> <mime-mapping> <extension>sj</extension> <mime-type>text/javascript</mime-type> </mime-mapping> }}} == Download file == [[http://ique.github.io/2009/11/cptableview-uploading-and-downloading-in-cappuccino/]] {{{#!highlight objectivej DownloadIFrame = document.createElement("iframe"); DownloadIFrame.style.position = "absolute"; DownloadIFrame.style.top = "-100px"; DownloadIFrame.style.left = "-100px"; DownloadIFrame.style.height = "0px"; DownloadIFrame.style.width = "0px"; document.body.appendChild(DownloadIFrame); //.... DownloadIFrame.src = "http://localhost:3000/uploads/fileXpto"; }}} == Index of string == {{{#!highlight objectivej var idx = [data rangeOfString:@"str xyz"]; }}} |
Cappuccino
Cappuccino is a framework which makes it easy to create advanced web apps.
http://www.cappuccino-project.org/
Objective-J is a powerful object-oriented language which compiles to run in the browser.
API http://www.cappuccino-project.org/learn/documentation/
Get the code
Clone it using git:
- cd ~
- mkdir gitCappuccino
- cd gitCappuccino
- git clone git://github.com/cappuccino/cappuccino.git
- cd ~/gitCappuccino/cappuccino
Vim editor Objective-J plugin
Run the follwoing commands after fetching code from github:
- mkdir -p ~/.vim/plugin
- cd ~/gitCappuccino/cappuccino/Tools/Editors/Vim]
- cp objj.vim ~/.vim/plugin
Emacs editor Objective-J plugin
- mkdir ~/cappuccinoEmacs
- cd ~/gitCappuccino/cappuccino/Tools/Editors/Emacs
- cp *.el ~/cappuccinoEmacs/
- touch ~/.emacs
- nano ~/.emacs
- (add-to-list 'load-path "~/cappuccinoEmacs")
- (require 'objj-mode)
Init String, stringWithFormat, CPString
Mutable Array
Callbacks
1 @implementation TestObject : CPObject
2 {
3 }
4
5 -(void)helloWorld{
6 CPLogConsole("Called hello world");
7 }
8 //(...)
9 @end
10
11 //--------------------
12 var selectorHelloWorld = @selector(helloWorld) ;
13 var signature = [self methodSignatureForSelector: aSelector];
14 var invocation = [CPInvocation invocationWithMethodSignature:signature];
15 [invocation setSelector: selectorHelloWorld];
16 [invocation invokeWithTarget: self]; //self -> instance of TestObject
17
1 @implementation TestObject : CPObject
2 {
3 }
4
5 -(void)helloWorldMsg:(CPString) message p1:(int)intVal {
6 CPLogConsole( message );
7 CPLogConsole( intVal );
8 }
9 //(...)
10 @end
11
12 //--------------------
13 var selectorHelloWorldMsg = @selector(helloWorldMsg:p1:) ;
14 var sig = [self methodSignatureForSelector: selectorHelloWorldMsg];
15 var invocation = [CPInvocation invocationWithMethodSignature:sig];
16 [invocation setSelector: selectorHelloWorldMsg];
17 [invocation setArgument:@"Message" atIndex:2 ]; //0-> self 1->_cmd
18 [invocation setArgument: 1234 atIndex:3 ]; //0-> self 1->_cmd
19 [invocation invokeWithTarget: self];
Dates
Dictionary from JSON object
1 - (void)connection:(CPURLConnection) connection didReceiveData:(CPString)data
2 {
3 var dict = [CPDictionary dictionaryWithJSObject: [data objectFromJSON] ];
4 [textField setStringValue: [dict valueForKey:@"lkeyx"] ];
5 }
6
7 - (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
8 {
9 }
URL request
Mime types Glassfish + JBoss
Adapted from https://github.com/cappuccino/cappuccino/wiki/Server-Side-Issues
You need to have the mime type of file types it doesn’t understand set to something for Cappuccino to work. Specifically, you should set the following mime-type/extension pairs. This can be done in the web.xml:
1 <mime-mapping>
2 <extension>j</extension>
3 <mime-type>text/javascript</mime-type>
4 </mime-mapping>
5 <mime-mapping>
6 <extension>plist</extension>
7 <mime-type>text/xml</mime-type>
8 </mime-mapping>
9 <mime-mapping>
10 <extension>sj</extension>
11 <mime-type>text/javascript</mime-type>
12 </mime-mapping>
Download file
http://ique.github.io/2009/11/cptableview-uploading-and-downloading-in-cappuccino/
1 DownloadIFrame = document.createElement("iframe");
2 DownloadIFrame.style.position = "absolute";
3 DownloadIFrame.style.top = "-100px";
4 DownloadIFrame.style.left = "-100px";
5 DownloadIFrame.style.height = "0px";
6 DownloadIFrame.style.width = "0px";
7 document.body.appendChild(DownloadIFrame);
8 //....
9 DownloadIFrame.src = "http://localhost:3000/uploads/fileXpto";
Index of string
1 var idx = [data rangeOfString:@"str xyz"];