Creating a web templating engine

2005-06-14 Thread BÁRTHÁZI András

Hi,

I'm busy with creating a widget based web templating engine, but I have 
some problems, please help me. The engine would allow you to define 
widgets, and use those in your templates. I would like it to be an OO 
module.


In the template, you can write this:

 server:input id=name width=100px maxlength=64 important=yes /

When the template engine read it, it will call a subroutine:

 call_a_sub_for_input(id='name', width='100px', maxlength='64',
  important='yes');

What this sub gives back, will be put into the output. I hope, you got the 
idea.


I have the code, that can parse the template, and the code, that would 
call the widget, so no problems with it. I don't know, how to put it 
together. I don't know, how should the programmer define a new widget, 
how it would be the most nicer way? How it can be detected by the template 
engine? I don't want a register function, like this:


$wte = new WTE;
$wte.register('input', my_input_widget);

I don't prefer it, to be 20-30 register line in my programs, that does 
nothing, just register.


It would be OK, to just define a global subroutine, and allow the template 
engine to call widget_$name if it reads a widget, but...


sub widget_input(*%params) {
...
}

It's not nice. Maybe something like this?

new_widget :input = {
return input /;
}

It's almost a register function, but it's more compact, and I like it. But 
if I would like to get parameters from the widget caller, how can I manage 
it? Is it possible to call this new noname sub with parameters, and get it 
easily inside the sub, for example like this:?


new_widget :input = {
my $name = _something_{'id'};
return 'input name=' ~ $name ~ ' /';
}

And I have more questions, but that's enough for this mail. Did you got my 
problem?


Bye,
  Andras


Re: Creating a web templating engine

2005-06-14 Thread BÁRTHÁZI András

Hi,


$wte = new WTE;
$wte.register('input', my_input_widget);

I don't prefer it, to be 20-30 register line in my programs, that does
nothing, just register.


maybe something like this?

 class MyWTE is WTE {
   method input (...) {...}
   method some_other_thing_you_would_have_had_to_register (...) {...}
   ...;
 }


And how the WTE class will be able to call these methods?


new_widget :input = {
 my $name = _something_{'id'};
 return 'input name=' ~ $name ~ ' /';
}


 new_widget :input = - Str $id {
   return 'input name=' ~ $id ~ ' /';
 };  # or

 new_widget :input = sub (Str $id) {
   return 'input name=' ~ $id ~ ' /';
 }


Hmm. It's still good, isn't it?

new_widget :input = sub($id) {
...
}

I think I like it. :) I would choose a bit more compact form if it's 
possible (I think, it isn't) - so if somebody has any idea, please let me 
know. :) But it's quite OK.


Thanks,
  Andras


Re: Creating a web templating engine

2005-06-14 Thread Ingo Blechschmidt
Hi,

BRTHZI Andrs wrote:
 $wte = new WTE;
 $wte.register('input', my_input_widget);

 I don't prefer it, to be 20-30 register line in my programs, that
 does nothing, just register.

 maybe something like this?

  class MyWTE is WTE {
method input (...) {...}
method some_other_thing_you_would_have_had_to_register (...) {...}
...;
  }
 
 And how the WTE class will be able to call these methods?

you'd have to instantiate your MyWTE class instead of the original WTE.
Then you'd simple call the methods on your MyWTE object:
  my $wte = MyWTE.new;
  $wte.input(...);
  $wte.some_other_thing_you_would_have_had_to_register(...);

But I don't know if that's convenient in your program/module.


--Ingo

-- 
Linux, the choice of a GNU | When cryptography is outlawed, bayl bhgynjf
generation on a dual AMD   | jvyy unir cevinpl!  
Athlon!|