[jifty-devel] Idea for Template::Declare::XML

Andrew Sterling Hanenkamp sterling at hanenkamp.com
Thu Aug 9 12:13:36 EDT 2007


Okay, so after discussions in the other thread about the
Template::Declare::Tags stuff, the revision here is that the
Template::Declare::XML would be used to declare a TagSet package that could
then be imported into any template package.

For example, in CASPlus, I might add packages like this:

package CASPlus::TagSet::CAS;

use Template::Declare::XML;
use Template::Declare::TagSet schema {
    tag serviceResponse =>
        is not_empty;

    # more tag definitions
};

package CASPlus::View;
use Jifty::View::Declare -base;

# This is a customized subclass of Template::Declare::Tags that nows to look
for ->app_class('TagSet', 'CAS')
use Jifty::Tags 'CAS' => { namespace => 'cas' };

template 'serviceValidate' => sub {
    xml_decl { 'xml', version => '1.0' };

   cas::serviceResponse {
      # more stuff
   };
};

I like that a lot. It does much better at separating the concerns than my
first suggestion.

Cheers,
Andrew

On 8/9/07, Andrew Sterling Hanenkamp <sterling at hanenkamp.com> wrote:
>
> agentz,
>
> The TagSet stuff in TD is cool, btw.
>
> On 8/9/07, Agent Zhang <agentzh at gmail.com> wrote:
> >
> > On 7/14/07, Andrew Sterling Hanenkamp <sterling at hanenkamp.com > wrote:
> > > Here's a sample of what I was thinking:
> > >
> > > use Template::Declare::XML;
> > > use Jifty::View::Declare schema {
> > >     namespace cas => ' http://www.yale.edu/tp/cas';
> > >     default_prefix is 'cas';
> > >
> > >     tag serviceResponse =>
> > >         is not_empty;
> > >
> >
> > This is a wonderful way to generate XML schema file or even DTD file
> > using TD :) Anyone feels like hacking that in? ;)
>
>
> I want to, but I don't know when I would be able to commit. Maybe sometime
> over the next month, but probably not in the next week or two.
>
> >
> > > template 'serviceValidate' => sub {
> > >     my $result = get 'result';
> > >
> > >     xml_decl { version => 1.0, encoding => 'UTF-8' };
> > >
> >
> > I've just committed a patch for the xml_decl sub but the API is now a
> > bit more general.
> >
> > For instance,
> >
> >     xml_decl { 'xml', version => '1.0' };
> >     xml_decl { 'xml-stylesheet',  href => "chrome://global/skin/",
> > type => "text/css" };
> >
> > will produce
> >
> >     <?xml version=" 1.0"?>
> >     <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
>
>
> Good idea.
>
> >
> > > If there's a namespace prefix "cas" then it can infer this to be
> > shorthand for:
> > >
> > > tag 'cas_serviceResponse' =>
> > >     prefix 'cas',
> > >     local_name 'serviceResponse',
> > >     is not_empty;
> > >
> >
> > To be honest, I'm not very happy with this way of specifying XML
> > namespaces since it's not flexible enough. I'm proposing using Perl
> > packages to emulate this kind of things. For example, html::div { ...
> > }, but we need to define the html package and import symbols into it
> > ourselves (sort of).
>
>
> Yeah, I wasn't precisely pleased with this myself, but it would have been
> flexible enough for what I was considering at the time. :-P
>
> The package idea is interesting, I'd be interested to see an example of
> how you would declare it and use it.
>
> Cheers,
> Andrew
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20070809/621512ce/attachment.htm


More information about the jifty-devel mailing list