[Klone-users] More complex examples.

Radek radek.hnilica at gmail.com
Sun Dec 16 12:54:57 EST 2007


Hello,

I found KLone and I acknowledge it as very interesting tool/framework.

I'm using KLone in a little bit unusual way.  My work is not in
embedded systems, but in server administration.  For me KLone is a way
how to run a binary as a part of satellite server agent without
examination of current system os distribution and installed libraries
and other programs.  So the possibility of a statically linked binary
with a couple of libraries in it is a real, real price.

So I want to write that small web server connected to my satellite
server agent and let the the stuff do some of actions by themselves
without bothering me repeatedly in the Sunday early morning. Some will
say in the night.

What I did or find:
* I find how to build it static.  So I have not to fiddle with
different server installations and OS distributions.  Very nice.
* I find how to link it with sqlite3.  So I have open way to do some
data acquisition storage and presentation. Wow that's great.
* I just wrote menu in maybe primitive way. I'm not happy with the
code, bu it works.
* I have login mechanism, which is not yet finished.  Yes, I have to
check the password.
* The web server is doing some of the things I needed.  So I
distributed it on every server.  They are up and running, waiting for
the stuff.
* I sent a message to my colleagues to look at it and criticize freely.

That all is very interesting, and promising.

But I miss one thing.  A bunch of not so simple examples and real
applications which I can study and learn from these.  I try to google,
bud find nothing.
So please do you know about any such source.  I'll be happy studying
such a source.

What I'm interested in is:
 * how to do something like page template.  I want to separate page
design from page contents.  So I can change design without rewrite
every page.
 * how to write better "helper code" in separate libraries.  For
instance I do not know how to access the out, session, requests page
variables from helper libraries without passing them as arguments.
 * how to write a components I can use in pages.  I have something in
my mind but didn't try to write it in code yet.
 * how to write a better code for KLone.

For example I describe my way of doing menu.  The first version is
done in following way.

 * Because I do not know how to template.  I choose to call the menu
build function from each page.  So I have in every kl1 file code <%
render_menu(out, SCRIPT_NAME); %>.
 * The library of helpers contains the render_menu function in which
all the choices are hard coded.  But because I do not know how to
access out variable from that function I pass it as a first argument.
The second argument is name of the current page so the render_menu
know on which page it renders the menu. The current page in menu is
rendered in slightly different way than others.
 * The render_menu is mostly build with the macro
MENU_CHOICE(page,title).  This simplifies the writing and editing of
choices. The body of the function then looks like:
   void render_menu(io_t *out, const char *curpage)
  {
	io_printf(out, "Menu(%s):", curpage);  /* for debugging */
	io_printf(out, "<div class=\"menu\"><ul>");  /* we use class=menu and
ul,li.  so we can control the rendering by css */
	MENU_CHOICE("index.kl1", "Main menu");
	MENU_CHOICE("info.kl1",  "Agent Information");
	MENU_CHOICE("smb.kl1", "Samba");
	MENU_CHOICE("sqlite.kl1", "Agent Database");
	io_printf(out, "</ul></div>\n");
}

But I'm not sure if this is the right way how to put a "component"
like menu into page.  Last hour I think about render_menu not working
through io_print(out, ...), but returning the html code of the menu as
a string.  This allows to use the menu in pages by <%=
render_menu(SCRIPT_NAME) %>, and possibly combine menu and other
possible components in more advanced way.  It seems to be also more
readable.  But I did not explored all the consequences yet.

This and many other, not yet formed, questions are reason I badly need
how people do they things in KLone.


-- Radek




More information about the klone-users mailing list