2008/11/18 Barry Walsh <[EMAIL PROTECTED]>

> This looks very good... looking forward to seeing it on CPAN.
>

> A quick question...  is it easy to make it use different template file
> extension (.tt, .tt2, tt3, .html) and use a different INCLUDE_PATH.    These
> options make it very easy to then sit on top of current production systems.
>

Yup, the default path gets built in:

    MX::T::View::build_template_src_path()

This uses 'template_src_base' and 'template_src_ext' set by the particular
view that you are using (where the default view is MX::T::View::TT). If
'template_src_base' isn't set then the path of the current module is used.
Probably best to set global defaults in your view instance (or your could
write your own View that implements MX::T:View)

    package Farm::Cow;
    with 'MooseX::Templated::Role';

    my $cow = Farm::Cow->new();
    $cow->templated_view->template_src_base( '/my/new/path' );
    $cow->templated_view->template_src_ext( '.tt2' );

    $cow->render()
    # /my/new/path/Farm/Cow.tt2

    $cow->render( 'xml')
    # /my/new/path/Farm/Cow.xml.tt2

    (I'll write some tests to confirm this)

>From the MX::T::View pod:

*  build_template_src_path( \%options )
*
    Builds the default filename to be used the template source

    Farm::Cow => /path/to/Farm/Cow.tt

    template_src_base  class_name    template_src_ext
    /path/to/          Farm/Cow      .tt

This is how it all pieces together (thanks again to perigrin for help in
refactoring)

  MX::T::Role - public interface
    - has 'template_view'
        => does 'MX::T::View  (default MX::T::View::TT)

  MX::T::View - backend interface for 'views'
    - requires 'process'
    - provides build_source()

  MX::T::View::TT
    - with 'MooseX::Templated::View'
    - sets up defaults for particular template system (path/ext)
    - implements 'process'

I should probably just add all this to the docs :)


>
> BTW.. as previously mentioned.. I think u should use a different default
> extension to "*.t"... perhaps .tt or .tt2?
>

Sorry - that was a typo in the docs - I did change the default extension for
Template files to be ".tt" - thanks for the heads up - I'll be committing
those changes soon.

Cheers,

Ian


>
> /I3az/
>
>
>
> Ian Sillitoe wrote:
>
>> This is a follow up on a previous thread ("Moose::Role::TTSelf"). With
>> peregrin's help (and considerable patience - many thanks) - I think
>> MooseX::Templated is pretty much at the point of pushing to CPAN. I'm
>> forwarding this to this list in case anyone has any more
>> comments/suggestions before I tip it over the edge (synopsis appended
>> below)
>>
>> http://code2.0beta.co.uk/moose/svn/MooseX-Templated/
>>
>> Cheers,
>>
>> Ian
>>
>>
>> =head1 NAME
>>
>> MooseX::Templated::Role - Framework to render Moose objects with templates
>>
>> =head1 SYNOPSIS
>>
>> Farm/Cow.pm
>>
>>    package Farm::Cow;
>>    use Moose;
>>    with 'MooseX::Templated::Role';
>>
>>    has 'spots'   => ( is => 'rw' );
>>    has 'hobbies' => ( is => 'rw', default => sub { ['mooing', 'chewing'] }
>> );
>>
>>    sub moo { "Moooooooo!" }
>>
>> Farm/Cow.t
>>
>>    This cow has [% self.spots %] spots. It mostly spends its time
>>    [% self.hobbies.join(" and ") %]. However, when it is very happy
>>    it exclaims, "[% self.moo %]!".
>>
>> Elsewhere on the Farm...
>>
>>    my $cow = Farm::Cow->new( spots => '8' );
>>
>>    $cow->render();
>>
>>    # This cow has 8 spots. It mostly spends its time
>>    # mooing and chewing. However, when it is very happy
>>    # it exclaims, "Moooooooo!".
>>
>> Alternatively, back in the cowshed
>>
>>    package Farm::Cow;
>>
>>    <snip>
>>
>>    sub _templated_xml {
>>        return <<"_XML_TT";
>>
>>    <cow sound="[% self.moo | html %]" spots="[% self.spots %]">
>>
>>    [%- FOREACH hobby = self.hobbies %]
>>        <hobby name="[% hobby | html %]"/>
>>    [%- END %]
>>
>>    </cow>
>>    _XML_TT
>>    }
>>
>> Back out on the farm
>>
>>    $cow->render( 'xml' );
>>
>>    # <cow sound="Moooooooo" spots="8">
>>    #    <hobby name="mooing"/>
>>    #    <hobby name="chewing"/>
>>    # </cow>
>>
>>
>>
>
>


-- 
Dr Ian Sillitoe
CATH Team -- http://cathdb.info

"Advice is what we ask for when we already know
the answer but wish we didn't" -- Erica Jong

Reply via email to