Rendering Framework

FIXME

IGNORE THE FOLLOWING NOTES FOR NOW, AND JUST TAKE A LOOK AT THE SAMPLE CODE !!

Rendering Framework 
  Skins 
    file-based 
    res.skinpath 
    db-based 
    skinmanager 
    .skin 
    renderSkin 
    renderSkinAsString 
    createSkin() 
    res.data 
    allowMacro() 
    containsMacro() 
  Macros 
    prefix, suffix, encoding, default 
    macro handlers 
      global 
      default handlers 
        response 
        request 
        session 
        param 
      path/object hierarchy handler 
      res.handlers 
    all properties as macro (but not password) 
    res.push, res.pop 
    res.write or return ! 
  string manipulation 
    format 
    encodeXml 
    encode 
  Helma render framework tutorial 
    url: http://helma.org/docs/devguide/framework/ 
    Basics: The Helma Request Cycle 
    Separating Presentation from Logic 
    Actions, Skins and Macros 
    Enter the Prototypes 
    The render framework in action 
    Macro Handlers 
    Macro Attributes 
    Manipulating Macro Handlers with res.handlers 
    Advanced Skins: Skin Paths 
    Appendix: typical skinset setup with relational db mapping

http://helma.org/docs/devguide/framework/

demoRenderingSkinHsp.zip

 
### mysql.sql ###  
  
CREATE DATABASE demoRenderingSkinHsp;  
USE demoRenderingSkinHsp;  
  
GRANT ALL ON demoRenderingSkinHsp.* TO helma@localhost IDENTIFIED BY 'secret';  
  
CREATE TABLE tb_person (  
  person_id MEDIUMINT(10) NOT NULL,  
  person_name TINYTEXT,  
  PRIMARY KEY (person_id)  
);  
  
INSERT INTO tb_person values (1, "michi");  
INSERT INTO tb_person values (2, "matthias");  
INSERT INTO tb_person values (3, "dieter");  
INSERT INTO tb_person values (4, "hannes");  
  
  
### db.properties ###  
  
jad.url      = jdbc:mysql://localhost/demoRenderingSkinHsp  
jad.driver   = com.mysql.jdbc.Driver  
jad.user     = helma  
jad.password = secret  
  
  
### Global/functions.js ###  
  
function aGlobalMacro_macro() {  
   res.write("a global macro");  
   return;  
}  
 
  
### Global/main.skin ###  
  
<html>  
  <head>  
  </head>  
  <body style="background-color:yellow">  
    <% response.body %>  
  </body>  
</html>  
  
  
### HopObject/functions.js ###  
  
function href_macro(param) {  
   var action = param.action ? param.action : "";  
   res.write(this.href(action));  
   return;  
}  
  
function skin_macro(param) {  
   this.renderSkin(param.name);  
   return;  
}  
  
  
### Root/type.properties ###  
  
persons = collection(Person)  
  
  
### Root/functions.js ###  
  
function main_action() {  
  
   // write directly to response, but we 'pop' that string  
   // out of the response-buffer  
   res.push();  
   this.renderSkin("listAllPersons");  
   var str = res.pop();  
  
   // render hsp-template and string to response, but we 'pop' that string  
   // out of the response-buffer  
   res.push();  
   this.createPersonTemplate();  
   this.renderSkin("createPerson");  
   str += res.pop();  
  
   // render hsp-template as string  
   str += this.createPersonTemplate_as_string();  
   // render skins as string  
   str += this.renderSkinAsString("createPerson");  
  
   res.data.body = str;  
   // actually render a skin directly to the response 
   renderSkin("main");  
   return;  
}  
  
  
function dummy_macro(param) {  
   var until = param.until ? parseInt(param.until, 10) : 5;  
   for (var i=0; i<until; i++) {  
      res.write(i + " ");  
   }  
   return;  
}  
  
  
function listAllPersons_macro(param) {  
   for (var i=0; i<root.persons.count(); i++) {  
      var p = root.persons.get(i);  
      p.renderSkin("listitem");  
   }  
   return;  
}  
  
  
### Root/createPerson.skin ###  
  
<form action="<% this.href action="createPerson" %>" method="POST">  
  <input type="text" name="name">  
  <input type="submit" name="send">  
  <% this.dummy until="10" %>  
  <% this.skin name="hello" %>  
  <% aGlobalMacro %>  
</form>  
  
  
### Root/createPersonTemplate.hsp ###  
  
<form action="<%= this.href("createPerson") %>" method="POST">  
  <input type="text" name="name">  
  <input type="submit" name="send">  
  <% var until = 10;  
  for (var i=0; i<until; i++) res.write(i + " "); %>  
</form>  
  
  
### Root/hello.skin ###  
  
Hello!  
  
  
### Root/listAllPersons.skin ###  
  
<h2>List of all Persons</h2>  
<% this.listAllPersons prefix="<ul>" suffix="</ul>" default="no persons" %>  
  
  
### Person/type.properties ###  
  
_db = jad  
_table = tb_person  
  
_id = person_id  
_parent = root.persons  
  
name = person_name  
  
  
### Person/functions.js ###  
  
function getInfo() {  
   return "just a person (" + this.name + ")";  
}  
  
  
### Person/listitem.skin ###  
  
<li>Name: <% this.name %></li> 

demoRenderingMacroHandlers.zip

### mysql.sql ###  
  
CREATE DATABASE demoRenderingMacroHandlers;  
USE demoRenderingMacroHandlers;  
  
GRANT ALL ON demoRenderingMacroHandlers.* TO helma@localhost IDENTIFIED BY 'secret';  
  
CREATE TABLE tb_person (  
  person_id MEDIUMINT(10) NOT NULL,  
  person_name TINYTEXT,  
  person_org_id MEDIUMINT(10) unsigned,  
  PRIMARY KEY (person_id)  
);  
  
  
CREATE TABLE tb_organisation (  
   org_id MEDIUMINT(10) unsigned NOT NULL,  
   org_name TINYTEXT,  
   org_country TINYTEXT,  
   PRIMARY KEY (org_id)  
);  
  
CREATE INDEX idx_pers_org ON tb_person (person_org_id);  
  
INSERT INTO tb_organisation values (1, "knallgrau", "at");  
INSERT INTO tb_organisation values (2, "helma", "at");  
INSERT INTO tb_organisation values (3, "amazon", "us");  
INSERT INTO tb_organisation values (4, "ebay", "us");  
INSERT INTO tb_organisation values (5, "yahoo", "us");  
  
INSERT INTO tb_person values (1, "michi", 1);  
INSERT INTO tb_person values (2, "matthias", 1);  
INSERT INTO tb_person values (3, "dieter", 1);  
INSERT INTO tb_person values (4, "hannes", 2);  
  
  
### db.properties ###  
  
jad.url      = jdbc:mysql://localhost/demoRenderingMacroHandlers  
jad.driver   = com.mysql.jdbc.Driver  
jad.user     = helma  
jad.password = secret  
  
  
### Global/main.skin ###  
  
<html>  
  <head>  
  </head>  
  <body style="background-color:yellow">  
    <% response.body %>  
  
    <hr />Macro Handlers Demonstration:<br />  
      <li>response.key01: <% response.key01 %></li>  
      <li>request.key01: <% request.key01 %></li>  
      <li>session.key01: <% session.key01 %></li>  
      <li>param.key01: <% param.key01 %></li>  
  </body>  
</html>  
  
  
### HopObject/functions.js ###  
  
function href_macro(param) {  
   var action = param.action ? param.action : "";  
   res.write(this.href(action));  
   return;  
}  
  
function skin_macro(param) {  
   this.renderSkin(param.name);  
   return;  
}  
  
  
### Root/type.properties ###  
  
_children = collection(Organisation)  
_children.accessname = org_name  
  
persons = collection(Person)  
  
manage = mountpoint(SysMgr)  
  
  
### Root/functions.js ###  
  
function main_action() {  
  
   res.handlers.SystemManager = root.manage;  
  
   res.push();  
   res.write("<h2>List of all Persons</h2>");  
   for (var i=0; i<root.persons.count(); i++) {  
      var p = root.persons.get(i);  
      p.renderSkin("info");  
   }  
  
   // create a skin from a string  
   var str = "<hr />Root Href: <% this.href %>";  
   var sk = createSkin(str);  
      // sk.allowMacro();  
      // sk.containsMacro();  
   this.renderSkin(sk);  
  
   res.data.body = res.pop();  
  
   // macro handler demo  
   res.data.key01 = "value01";  
   // set req.data.key01 by appending '?key01=value01' to the URL  
   session.data.key01 = "value01";  
   var obj = new Object();  
      obj.key01 = "value01";  
      obj.key02 = "value02";  
   renderSkin("main", obj);  
   return;  
}  
  
  
### Organisation/type.properties ###  
  
_db = jad  
_table = tb_organisation  
  
_id = org_id  
_parent = root  
  
name = org_name  
  
persons = collection(Person)  
persons.local = org_id  
persons.foreign = person_org_id  
  
allPersons = collection(Person)  
  
  
### Person/type.properties ###  
  
_db = jad  
_table = tb_person  
  
_id = person_id  
_parent = org.persons  
  
name = person_name  
  
org = object(organisation)  
org.local = person_org_id  
org.foreign = org_id  
  
  
### Person/functions.js ###  
  
function main_action() {  
  
   res.handlers.SystemManager = root.manage;  
  
   res.data.body = this.renderSkinAsString("info");  
   renderSkin("main");  
}  
  
  
### Person/info.skin ###  
  
<li>Name: <a href="<% this.href %>"><% this.name %></a> <% Organisation.name %> - <% SystemManager.info %></li> 

demoRenderingSkinsets.zip

### mysql.sql ###  
  
CREATE DATABASE demoRenderingSkinsets;  
USE demoRenderingSkinsets;  
  
GRANT ALL ON demoRenderingSkinsets.* TO helma@localhost IDENTIFIED BY 'secret';  
  
CREATE TABLE tb_person (  
  person_id MEDIUMINT(10) NOT NULL,  
  person_name TINYTEXT,  
  person_org_id MEDIUMINT(10) unsigned,  
  PRIMARY KEY (person_id)  
);  
  
INSERT INTO tb_person values (1, "michi", 1);  
INSERT INTO tb_person values (2, "matthias", 1);  
INSERT INTO tb_person values (3, "dieter", 1);  
INSERT INTO tb_person values (4, "hannes", 2);  
  
  
CREATE TABLE tb_skinset (  
   skinset_id MEDIUMINT(10) unsigned NOT NULL,  
   PRIMARY KEY (skinset_id)  
);  
  
CREATE TABLE tb_skin (  
   skin_id MEDIUMINT(10) unsigned NOT NULL,  
   skin_proto TINYTEXT,  
   skin_name TINYTEXT,  
   skin_skin TEXT,  
   skin_set_id MEDIUMINT(10) unsigned NOT NULL,  
   PRIMARY KEY (skin_id)  
);  
  
INSERT INTO tb_skinset values (1);  
INSERT INTO tb_skinset values (2);  
INSERT INTO tb_skinset values (3);  
  
INSERT INTO tb_skin values (1, "Global", "main", "<body bgcolor=green><% response.body %></body>", 1);  
INSERT INTO tb_skin values (2, "Global", "main", "<body bgcolor=blue><% response.body %></body>", 2);  
  
  
### db.properties ###  
  
jad.url      = jdbc:mysql://localhost/demoRenderingSkinsets  
jad.driver   = com.mysql.jdbc.Driver  
jad.user     = helma  
jad.password = secret  
  
  
### Global/main.skin ###  
  
<html>  
  <head>  
  </head>  
  <body bgcolor="yellow">  
    <% response.body %>  
  </body>  
</html>  
  
  
### HopObject/functions.js ###  
  
function href_macro(param) {  
   var action = param.action ? param.action : "";  
   res.write(this.href(action));  
   return;  
}  
  
function skin_macro(param) {  
   this.renderSkin(param.name);  
   return;  
}  
  
  
### layouts/gray/Global/main.skin ###  
  
<body bgcolor="gray"><% response.body %></body>  
  
   
### layouts/orange/Global/main.skin ###  
  
<body bgcolor="orange"><% response.body %></body>  
  
  
### Root/type.properties ###  
  
persons = collection(Person)  
  
skinsets = collection(Skinset)  
  
  
### Root/functions.js ###  
  
function main_action() {  
  
   if (req.data.skinsetId) {  
      // we define the lookup-path for the skins 
      // the file-based skins residing in the code-directly are always used as the last fallback 
      res.skinpath = new Array(root.skinsets.getById(req.data.skinsetId).skinmanager, app.dir + "/layouts/gray");  
   }  
   res.write("<li><a href=" + this.href() + "?skinsetId=1>green</a>");  
   res.write("<li><a href=" + this.href() + "?skinsetId=2>blue</a>");  
   res.write("<li><a href=" + this.href() + "?skinsetId=3>default</a>");  
  
   res.push();  
   res.write("<h2>List of all Persons</h2>");  
   for (var i=0; i<root.persons.count(); i++) {  
      var p = root.persons.get(i);  
      p.renderSkin("info");  
   }  
  
   res.data.body = res.pop();  
  
   renderSkin("main");  
   return;  
}  
  
  
### Skinset/type.properties ###  
  
_db = jad  
_table = tb_skinset  
  
_id = skinset_id  
_parent = root.skinsets  
  
skinmanager = collection(Skin)  
skinmanager.local = skinset_id  
skinmanager.foreign = skin_set_id  
skinmanager.group = skin_proto  
skinmanager.accessname = skin_name  
  
  
### Skin/type.properties ###  
  
_db = jad  
_table = tb_skin  
  
_id = skin_id  
_parent = skinset.skinmanager  
_name = skin_name  
  
skinset = object(Skinset)  
skinset.local = skin_id  
skinset.foreign = skin_set_id  
  
proto = skin_proto  
name = skin_name  
skin = skin_skin  
  
  
### Person/type.properties ###  
  
_db = jad  
_table = tb_person  
  
_id = person_id  
_parent = root.persons  
  
name = person_name  
  
  
### Person/info.skin ###  
  
<li>Name: <a href="<% this.href %>"><% this.name %></a></li>