Jemplate, First Attempt

Install

CPAN Modules

We’re looking at using Jemplate within a Catalyst application so we’re going to need a view on Jemplate. Let’s install Jemplate and Catalyst::View::Jemplate from CPAN

  1. Jemplate
  2. Catalyst::View::Jemplate - CPAN version 0.06 had a failure in t/01_live.t of:
    #   Failed test at t/01_live.t line 60.
    #     Structures begin differing at:   
    #          $got->[0] = ''
    #     $expected->[0] = 'text/javascript'
    

    The test at line 60 is:

       is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=utf-8' ] );
    
    Workaround: make (or force) install anyway.

Make Catalyst Aware of Jemplate

Add a Jemplate View

script/mojomojo_create view Jemplate Jemplate

Create and Enable Template Path

Let’s plan on putting jemplate files in root/template so we’ll let our app know about that path. We’ll do this by edit View/TT.pm and adding an entry to the config->{INCLUDE_PATH}

        $c->path_to('root', 'jemplate'),

Create Root Action to Compile and Return Javascript

sub jemplate : Global {
    my($self, $c) = @_;
    $c->forward('View::Jemplate');
}

Configure the Backend Cache for Jemplate

MojoMojo->config->{default_view} = 'TT';
MojoMojo->config->{cache}{backend} = { class => "Cache::FastMmap", };
MojoMojo->config->{'View::Jemplate'}{jemplate_dir} =
  MojoMojo->path_to( 'root', 'jemplate' );
MojoMojo->config->{'View::Jemplate'}{jemplate_ext} = '.jmpl';

Generate Jemplate Runtime Javascript

jemplate --runtime root/static/js/Jemplate.js

Make Pages Aware of Jemplate

Put the following in in whatever is your header template:

<script type="text/javascript" language="JavaScript" 
src="[%c.uri_for_static('js/Jemplate.js')%]"></script>
<script type="text/javascript" language="JavaScript" src="[%c.req.base%]/jemplate"></script>
My tags:
 
Popular tags:
 
Powered by MojoMojo