-
Notifications
You must be signed in to change notification settings - Fork 4
OSE
OSE
orOgx Scripting Engine
is Javascript with a few twists and added keywords, that you can use inOML
andhtml
templates. Here is a basic example
{{
loop $images as index image {
echo <div class="image"><span class="increment">&index</span><img src="&image.url" height="&image.height" width="&image.width"></div>;
}
}}
Scripts start with
{{
and end with}}
. For readability, they are omitted in the rest of this page.
OSE
uses different types of variables. They either start by@ # & $ %
.
Variables starting with
&
refer to thethread's data object
.
Variables starting with
@
refer to thescript's data object
.
Variables starting with
$
refer to an optionaldata object
.
Variables starting with
%
refer to theroute's data object
.
Variables starting with
#
refer toglobal variables
.
Note that variables have to start with
[a-zA-Z_]
OSE
only contains a few added keywords/methods
template
json
oml
ose
crumb
echo
uxi
method
function
for cyclable as [index or object or value] [object or value]
mongogx
scope
screen
result
The
template
keyword is used to load and return as string, a preloaded HTML template.
template MyPreloadedTemplate
You can also pass an object to templatize
template MyPreloadedTemplate SomeObject
The
json
keyword is used to load and return as a preloaded JSON object
json MyPreloadedJson
The
oml
keyword is used to load and return as a preloaded OML object
oml MyPreloadedOml
The
ose
keyword is used to load and return as a preloaded OSE script
ose MyPreloadedScript
The
crumb
keyword is used to retrieve a property from an object generated from the route-capture. It is equivalent to%
crumb id
The
result
is to be used to retrieve the result of a Promise, generated by aFunction
result function_id
The
echo
keyword is used to add to the return buffer, if return is not used, such as
echo 'hey ';
/* do some other stuff */
echo 'ho';
The end of the script would return
'hey ho'
Same as
return 'hey ho';
Note that you can omit the quotes when using echo
The
uxi
keyword is used to point to a live object.
uxi uxiID:uxiType
uxi mySwitch:Switch
The
method
keyword is used to point to a live object's method.
method methodName uxiID:uxiType //Link to method
method methodName() uxiID:uxiType //Execute method, parameters will be auto
To
toggle
aSwitch
using OSE
method toggle() mySwitch:Switch
Use the function keyword to declare and execute an inline function or call a globally available function
function MyGlobalFunction //Link to function
function MyGlobalFunction() //Execute function, parameters will be auto
function if($color === 'red'){return '#EE3333';} return '#33EE33'; //Inline, declare and execute
The
loop
keyword is used to loop or cycle over an array or an object. For an array of images as object
loop $images as image
loop $images as index image
To loop over the properties of an object
loop $myobject as property
loop $myobject as property value
The new variables:
image
,index
,property
andvalue
will be accessible starting with&
echo <div class="image" style="background-image:url(&image.url)"></div>;
All together
loop $images as index image {
echo <div class="image"><span class="increment">&index</div><img src="&image.url" height="&image.height" width="&image.width">;
}
If you use MongOGX as a local database, you get fetch some data and pass it to any object using OSE, such as
mongogx.DB.COL.find(QUERY)
A concrete example
mongogx.my_project.users.find({});
You can also test the scope of the app, and use another OSE script as a result of this condition
scope admin manager ? template Manager : template Employee
scope admin manager ? #company.revenue : null
...
You can also test the screen width of the app, and use another OSE script as a result of this condition
screen > 500 ? template Big : template Small
You can also use a callback and pass the local object
$
, thread object&
or the temporary object@
, such as
myCallBack($)
You can of course mix commands, for instance, to retrieve a file dynamically
{{template $mytemplate}} //will get the template that $mytemplate resolves to
{{json $myjson.someproperty}} //will get a jso document that $myjson resolves to then returns the prop/value
{{ose myotherscript}} //include another script
Of course you can set variables and use standard javascript
{{
@mytempvar = json myfile.mylist;
let somevar = 'some var';
loop @mytempvar as index object{
echo <span>&object.name</span>;
}
return somevar;
}}
- Welcome
- Changelog
- Structure
- Configuration
- Getting started
- CLI
- Poly
- Core
- Templating
- Routing
- Controllers
- Components
- Extra Components
- Helpers
- Styling
- Debugging