Catalyst::View::Semantic - Template::Semantic view for Catalyst
package MyApp::View::Semantic; use Moose; extends 'Catalyst::View::Semantic'; __PACKAGE__->meta->make_immutable; 1;
setup end action in Root
sub auto : Private { my ($self, $c) = @_; $c->stash( js => [], css => [], jscode => '' ); } sub end : ActionClass('RenderView') { my ($self, $c) = @_; return if $c->response->status > 200 || $c->response->body; $c->stash->{title} //= 'Default page title'; unshift $c->stash->{css}, 'bootstrap.min'; # add default css unshift $c->stash->{js}, 'vendor/prototype'; # add default js $c->forward('View::Semantic', []); }
create layout as root/template/layout.html
<!DOCTYPE html> <html> <head> <title>Page Title</title> <link href="" rel="stylesheet" /> <script src=""> </script> <script type="application/x-javascript"> //<![CDATA[ Event.observe(document, 'dom:loaded', function() { /*code*/ }); //]]> </script> </head> <body> </body> </html>
in MyApp::Controller::Foo
sub bar :Local { my ($self, $c) = @_; $c->stash( view => { a => [ map { '.' => $_->name, '@href' => $_->url } $c->model('MyDB::Item')->all ] }); }
create template for action as root/template/foo/bar.html
<div>list: <a href="#">item</a></div>
that's it.
This is Catalyst view class for Template::Semantic with sane (hopefully) defaults and some useful methods like html layout and pager. Feel free to extend your view. Check the Template::Semantic::Cookbook and source of this module.
The following is a list of configuration attributes you can set in your global Catalyst configuration or locally as in:
package MyApp::View::Semantic; use Moose; extends 'Catalyst::View::Semantic'; __PACKAGE__->config( template_extension => 'xml', # override default extension wrapper => sub { html => { 'body > div#main' => shift } } # override default wrapper );
Used at the prefix path for where yout templates are stored. Defaults to $c->path_to('root','template').
$c->path_to('root','template')
Optionally set the filename extension of your templates. Default: 'html'
Name of key in stash which contains processing instructions for default template(from action path) or template specified in $c->stash->{template}. Default: 'view'
$c->stash->{template}
Name of key in stash which contains name of template on which apply processing instructions. Default: 'template'
Set $c->response->content_type to this value unless specified. Default: 'text/html'
Default wrapper callback - sets layout template name and Template::Semamtic instruction to insert wrapped content. Default sub { layout => { body => shift } }
sub { layout => { body => shift } }
A key in stash which contains title to include in default layout. Default: 'title'
A key in stash which contains array of css file names (without extension) to include in default layout. Default: 'css'
A key in stash which contains array of js file names (without extension) to include in default layout. Default: 'js'
A key in stash which contains string of js code to include in default layout. Default: 'jscode'
Prefix location of css files. Default: '/static/css'
Prefix location of js files. Default: '/static/js'
Name of default pager template
Renders the template specified in <$template> or in $c->stash->{$self->template_key} or $c->namespace/$c->action (the private name of the matched action). $code or stash contents under $c->stash{$self->process_key} are passed to the underlying view object. If wrapper is defined, than result is wrapped using default layout.
<$template
$c->stash->{$self->template_key}
$c->namespace/$c->action
$c->stash{$self->process_key}
wrapper
Output is stored in $c->response->body and value of $c->response->content_type to text/html or whatever you configured as the "content_type" attribute unless this header has previously been set.
$c->response->body
$c->response->content_type
text/html
Returns Templace::Semantic::Document as result of processing $template with $code instructions.
$template
$code
Renders html document. Check "SYNOPSIS" for default layout which should be in $template file. $meta should be a hash with corresponding keys ("title_key", "css_key", "js_key", "jscode_key")
$meta
Renders pager snippet from $template or $self->pager_template using $pager ( Data::Page object ) You should have root/template/pager.html (or other path which corresponds to your configuration)
$self->pager_template
$pager
<div> <a class="prev" href="#">prev</a> <span> <a href="#" class="">middle</a> </span> <a class="next" href="#">next</a> </div>
Access underlying Template::Semantic object
GitHub
http://github.com/vividsnow/Catalyst-View-Semantic
Search MetaCPAN
https://metacpan.org/module/Catalyst::View::Semantic
Yegor Korablev <egor@cpan.org>
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Template::Semantic, HTML::Zoom, Text::Xslate, Template, Catalyst::View, Catalyst::View::HTML::Zoom
To install Catalyst::View::Semantic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::View::Semantic
CPAN shell
perl -MCPAN -e shell install Catalyst::View::Semantic
For more information on module installation, please visit the detailed CPAN module installation guide.