EyeRad
DescriptionA RAD tool for create JSon files to be parsed with eyeJFP. It will function like glade tools in xml mode. I will start develop with the eyeJFP, and the Rad environment will be written in it. Characteristics
Questions
JFP Hello Worldapp.jfp
{
"myWindow1(Window)": {
"name": "wnd",
"type": "Window",
"cent": 1,
"width": 250,
"height": 150,
"title": "Hello Word example",
"children": {
"myLabel1(Label)": {
"name": "lbl",
"x": 20,
"y": 20,
"text": "Hello World!",
"serialize": 1
},
"myTextbox1(Textbox)": {
"name": "txt",
"x": 20,
"y": 50,
"width": 150
},
"myButton1(Button)": {
"name": "btn",
"caption": "Change Label Text",
"x": 20,
"y": 80,
"friends": ["myTextbox1"]
}
}
}
}
app.eyecode
function eyeRad_run($params=null) {
// JFP
require_once('eyeJFP.eyecode');
$eyeJFP = new eyeJFP('eyeRad', 'app.jfp');
eval($eyeJFP->parse());
...
The Class
class eyeJFP {
private $file;
private $data;
private $eval;
private $appName;
function __construct($appName, $file) {
if (!file_exists($file)) {
throw new Exception('File not found! ' . $file);
}
$this->appName = $appName;
$this->file = $file;
}
public function parse() {
$data = json_decode(file_get_contents($this->file), true);
if (sizeOf($data) == 0) {
throw new Exception('Invalid JSON format!');
}
$this->data['name'] = 'eyeApps';
$this->data['children'] = $data;
unset($this->eval);
$this->parseWidget($this->data, $this->data['name']);
return($this->eval);
}
private function parseWidget($data, $name, $father = null) {
if (is_array($data['children']) && sizeOf($data['children']) > 0) {
foreach ($data['children'] as $k => $v) {
$this->createWidget($v, $k, $data['name']);
$this->parseWidget($v, $k, $data['name']);
}
}
}
private function createWidget($data, $name, $father) {
if ($name == 'eyeApps') return(true);
preg_match_all('/(.*)\((.*)\)/', $name, $res);
$global_name = $res[1][0];
$type = $res[2][0];
// Create the array
$array = $data;
$array['name'] = $this->appName . '_' . $array['name'];
$array['father'] = ($father == 'eyeApps') ? $father : $this->appName . '_' . $father . '_Content' ;
$serialize = ($array['serialize']) ? '0' : '';
$friends = $array['friends'];
unset($array['children']);
unset($array['type']);
unset($array['serialize']);
unset($array['friends']);
$array_var = var_export($array, true);
// Creates the eval code
$this->eval .= "\${$global_name} = new {$type}($array_var);\n";
if (is_array($friends) && sizeOf($friends) > 0) {
foreach ($friends as $friend) {
$this->eval .= "\${$global_name}->addFriend(\${$friend});\n";
}
}
$this->eval .= "\${$global_name}->show({$serialize});\n";
$this->eval .= "\n";
}
}
Vision Document |
Personal toolsLog in / create accounteyeOS WikiStart Page News Recent changes Random pageeyeOS NetworkeyeOS Home Forums IRC Downloads DonationsToolboxWhat links here Related changes Upload file Special pages |