Thread: [htmltmpl] HTML::Template with simplified/automated fill in from database.
Brought to you by:
samtregar
|
From: Ronald S. <ron...@so...> - 2008-02-22 12:41:10
|
Given the data model below, does anyone know of a package or module that
would generate code for, or fill in, an HTML::Template like that
provided below the database ddl? If not, would there be interest in
such a module if I could create it?
Ron
create table books (
book_id integer,
title varchar(1024),
isbn varchar(80)
);
create table authors (
author_id integer,
book_id integer references books(book_id),
last_name varchar(80),
first_name varchar(80)
);
<html>
<head><title>Test Template</title>
<body>
<TMPL_LOOP NAME="+books">
<ul>
<li />Title is "<TMPL_VAR NAME=".title">"
<li />ISBN is <TMPL_VAR NAME=".isbn">
<li />Authors are:
<ul>
<!-- name below is shorthand for +books.book_id.authors -->
<!-- could still be abbreviated to +authors if fk's link
tables -->
<TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" >
<li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR
NAME=".first_name">
</TMPL_LOOP>
</ul>
</ul>
</TMPL_LOOP>
</body>
</html>
|
|
From: Sébastien Aperghis-T. <mad...@fr...> - 2008-02-23 00:40:39
|
Ronald Schmidt wrote: > Given the data model below, does anyone know of a package or module > that > would generate code for, or fill in, an HTML::Template like that > provided below the database ddl? If not, would there be interest in > such a module if I could create it? If I understand correctly your question, you probably want to write a producer module for SQL::Translator, the set of modules behind SQL Fairy. » http://search.cpan.org/dist/SQL-Translator/ » http://sqlfairy.sourceforge.net/ -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO. |
|
From: Ronald S. <ron...@so...> - 2008-02-23 12:14:00
|
Sébastien Aperghis-Tramoni wrote: > Ronald Schmidt wrote: > If I understand correctly your question, you probably want to write a > producer module for SQL::Translator, the set of modules behind SQL Fairy. > » http://search.cpan.org/dist/SQL-Translator/ > » http://sqlfairy.sourceforge.net/ As far as I can tell from looking at SQL::Translator producers, the producers generate visualizations or alternate serializations of a database model whereas I am looking to generate easy visualizations of objects serialized in a database USING the underlying model. If you now review the sample html template included in my initial email, do you think that you understand the question? Do you know of a module providing the functionality or find the design to be of sufficient interest to for a new module? |
|
From: Mark F. <azf...@gm...> - 2008-02-23 17:14:06
|
On Sat, Feb 23, 2008 at 5:13 AM, Ronald Schmidt <ron...@so...> wrote: > I am looking to generate easy visualizations of > objects serialized in a database USING the underlying model. It sounds like you're talking about a glue between "model" components like dbix::class, class::dbi, etc? What would drive it? An existing template, or an existing data definition? I see those two choices like this: 1) For a data structure, create a template on the fly, and populate it? - Isn't that data dumper? 2) For a template, get a list of params in the template and populate them if the same-named item is found in a data structure (retrieved from a model component)? Is that right? Mark |
|
From: Ronald S. <ron...@so...> - 2008-02-23 19:14:00
|
Mark Fuller wrote:
> On Sat, Feb 23, 2008 at 5:13 AM, Ronald Schmidt
> <ron...@so...> wrote:
>
>> I am looking to generate easy visualizations of
>> objects serialized in a database USING the underlying model.
>>
>
> It sounds like you're talking about a glue between "model" components
> like dbix::class, class::dbi, etc?
>
Close. Yes a glue layer between HTML::Template and a database. I could
try to use some of these higher layer abstractions (including Rose:DB)
or use a modern DBI layer with its
primay_key/primary_key_info/foreign_key_info functions ...
> What would drive it? An existing template, or an existing data
> definition? I see those two choices like this:
>
> 1) For a data structure, create a template on the fly, and populate it?
> - Isn't that data dumper?
>
1) Is NOT the driver. As I see it, it is often difficult to guess the
structure of underlying objects correctly from a schema.
> 2) For a template, get a list of params in the template and populate
> them if the same-named item is found in a data structure (retrieved
> from a model component)?
>
2) Is the proposed driver. Retrieved from model component or schema.
> Is that right?
>
It all sounds harder to explain than I thought it would be to use ;).
Any further thoughts?
> Mark
>
<html>
<head><title>Test Template</title>
<body>
<TMPL_LOOP NAME="+books">
<ul>
<li />Title is "<TMPL_VAR NAME=".title">"
<li />ISBN is <TMPL_VAR NAME=".isbn">
<li />Authors are:
<ul>
<!-- name below is shorthand for +books.book_id.authors -->
<!-- could still be abbreviated to +authors if fk's link
tables -->
<TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" >
<li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR
NAME=".first_name">
</TMPL_LOOP>
</ul>
</ul>
</TMPL_LOOP>
</body>
</html>
|
|
From: Mathew R. <mat...@ne...> - 2008-02-24 23:39:26
|
Hi Ronald, >>> I am looking to generate easy visualizations of >>> objects serialized in a database USING the underlying model. >> It sounds like you're talking about a glue between "model" components >> like dbix::class, class::dbi, etc? >> > Close. Yes a glue layer between HTML::Template and a database. I > could try to use some of these higher layer abstractions (including > Rose:DB) or use a modern DBI layer with its > primay_key/primary_key_info/foreign_key_info functions ... Based on your example below, are you thinking of something like Template::Plugin::DBI (as used in Template::Toolkit)? ie: see examples here: http://search.cpan.org/~abw/Template-DBI-2.64/lib/Template/Plugin/DBI.pm Alternatively, have you looked at HTML::FillInForm? > <html> > <head><title>Test Template</title> > <body> > <TMPL_LOOP NAME="+books"> > <ul> > <li />Title is "<TMPL_VAR NAME=".title">" > <li />ISBN is <TMPL_VAR NAME=".isbn"> > <li />Authors are: > <ul> > <!-- name below is shorthand for +books.book_id.authors --> > <!-- could still be abbreviated to +authors if fk's link > tables --> > <TMPL_LOOP NAME=".book_id.authors:ORDER_BY:.last_name,.first_name" > > <li /><TMPL_VAR NAME=".last_name">, <TMPL_VAR > NAME=".first_name"> > </TMPL_LOOP> > </ul> > </ul> > </TMPL_LOOP> > </body> > </html> If so, (IMO) H::T wasn't designed to be pluggable/extensible in that way. However, that hasn't stopped a number of users extending/modifying the H::T codebase in various ways, ie: I use a version which allows me to subclass H::T (or H::T::E) so that I can extend the tag syntax. From memory, I think someone else on this list has hooked together H::T and HTML::FillInForm. In your example above, I would subclass H::T to handle the following (or something similar): ... <TMPL_SQL_LOOP NAME="books"> ...<TMPL_FIELD NAME="title"> ...<TMPL_SQL_LOOP NAME="authors" WHERE="book_id = books.book_id" ORDER_BY="last_name, first_name"> ...<TMPL_FIELD last_name>... ...</TMPL_SQL_LOOP> </TMPL_SQL_LOOP> ... cheers, Mathew |