Page created:
Jun 18, 2009 (? ago)
Last modified ? ago
To main page | Opera Unite HowTo's

Uniteness (Framework)


Uniteness is a framework for Opera Unite that I develop to simplify low-level stuff, like URLs, static images, relative paths resolving, GET POST, debugging and redirects.

This is a very preview release. Backwards compatibility isn't guaranteed. It lacks wrappers for some features, like templating (though you can still use them).

License: MIT license
Known bug: images aren't serving, see 0.11 release notes for explanations.
Current version 0.11: Download

What's new

 v. 0.11 

Demo apps

(v.11) StopLorem
(v.1) Crud-ness   Download  or Install   
(This is actually a copy of CRUD and static, but using Uniteness, and it's almost three times less cods)


Basic template

1. ./config.xml:
<widget network="private public">
  <widgetname>App</widgetname>
  <feature name="http://xmlns.opera.com/fileio">
  </feature>
  <feature name="http://xmlns.opera.com/webserver">
    <param name="type" value="service"/>
    <param name="servicepath" value="app"/>
  </feature>
</widget>
2. ./index.html:
<script src="serverside/lib/uniteness-0.11.js"></script>
<script>

DEBUG = 1;
LOAD_SCRIPT('serverside/main.js');

</script>
3. Put current uniteness (download above) to ./serverside/lib/.

4. ./serverside/main.js:
URLs([
    '_index', start_page,
    'clientside', 'static',
]); 

function start_page(r, single) {
     r.write('Hello, '+r.GET.name);
};
5. Drag-n-drop config.xml to Opera Unite.

Then you can edit main.js (it will reload automatically).

URLs

URLs([
    '_index', start_page,
    'edit', edit_item,
    'imgs', 'static',
    'javascripts', 'static',
]); 

function start_page(r) {
    r.write( ' <img src="'+r.uri('/imgs/logo.jpg')+'"><br> ' )
}
function edit_item(r) {
    r.redirect('/')  # will redirect to correct url of "Main Page"
}

....
will create those URLs:
http://device.login.operaunite.com/service
http://device.login.operaunite.com/service/edit
http://device.login.operaunite.com/service/imgs/...
r.uri(...) function converts "/my_page" to "/correct_service_path/my_page".

Static Files

URLs([
    // ....
    'imgs', 'static',
]); 
"imgs" will be a static directory (use it to serve client-side images, stylesheets, Javascripts). Note the quotes!

Issues. Static images has some kind of BUG - after a few usages image is broken. I'm not sure why is that yet.

GET/POST

function start_page(r) {
    var got_id = r.GET.id;
    var my_title = r.POST.title;

print "stuff!"

function start_page(r) {
    r.write('stuff!')

Data storage

var db = new JSON_FILE('state_prices.json', []);
// [] means that by default you are creating array 
// you CAN store dictionaries inside of that array
// {} would be dictionary
var obj = {title : r.POST.title, price : r.POST.price }
// db.store is in-memory variable (array) that gets saved to disk
// when .save() is called
db.store.push(obj)  // CREATE first(0) object
db.store[0] = obj   // UPDATE first(0) object 
db.store.remove(0)  // DELETE first object
db.save()

// Print all "titles" to user

for(var i in db)
    r.write( db.store[i].title + '<br>' )
The best part of it that you can use lists of lists, lists of dictionaries, or any arbitrary structure, actually. No schemas, no migrations.

Better errors

var DEBUG = 1
Shows user-friendly errors in page (like PHP):


var DEBUG = 0
The errors will go to your Error Consols and not seen by visitors.

Templates

No templates yet, use Markuper. I'll wrap it too probably.

Human-readable URLs

http://...operaunite.com/service/my/humane/url?test
function start_page(r) {
    r.URI                 // contains '/my/humane/url'
    r.uri('/bar/?foo')    // will return '/service/bar/?foo'
    r.uri('/')            // will return '/service/' (main page URL)
    r.uri(r.URI)          // ... '/service/my/humane/url' (for resetting GET)
I know this can be confusing, will think how to fix it.

pprint(variable)

For complexly nested this can be a way to output contents:
function start_page(r) {
    r.write(pprint(opera))

Button


<a href="http://unitehowto.com/uniteness">
    <img src="http://unitehowto.com/i/uniteness.png" border="0">
</a>

Slava V. [about me]


main page



Last updated


  1. Markuper (HTML templates)
  2. .ua
  3. Opera Unite HowTo's
  4. .us (files)
  5. Distribute Your Application
  6. 24/7 sites (permanent applications - idea) [stub]
  7. Issues
  8. HTTP Connections (AJAX/REST)
  9. Cookies
  10. file_wrap.js - File Wrapper
  11. Basic HowTo: Simple app (tutorial)
  12. Static images, client-side scripts
  13. Application Examples
  14. How to Debug Opera Unite apps
  15. Persistence & databases
  16. Opera Unite benchmark
  17. From PHP to Opera Unite
  18. Uniteness (Framework)
  19. Config.xml
  20. Key-value storage
  21. Widget Object
  22. Notifications (Growl'esque)
  23. Reset (debug)
  24. Cron example
  25. What I meant by CNAMEs
  26. Wish List
  27. Device Unavailable
  28. StopLorem (Opera Unite blogging)
  29. uniteness-0.11
  30. GET/POST data
  31. CRUD And Static (example)
  32. Opera object
  33. URLs
  34. Headers & Redirects
  35. Error Console
  36. JSON State (storing data)
  37. Security
  38. /storage/ (in fileio)
  39. Yusef library
  40. unite_info (a-la php_info)
  41. Javascript Imports
  42. onunload / _close
  43. fileio: Sandboxed Filesystem
  44. Request Hierarchy (like php_info)
  45. Intro: Web Apps with Opera Unite