To main page | Opera Unite HowTo'sUniteness (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 newv. 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 template1. ./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). URLsURLs([
'_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 FilesURLs([
// ....
'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/POSTfunction 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 storagevar 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 errorsvar DEBUG = 1Shows user-friendly errors in page (like PHP): ![]() var DEBUG = 0The errors will go to your Error Consols and not seen by visitors. TemplatesNo templates yet, use Markuper. I'll wrap it too probably.Human-readable URLshttp://...operaunite.com/service/my/humane/url?testfunction 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>
| Last updated
|