NAME Dancer::Plugin::TTHelpers - Useful routines for generating HTML for use with Dancer + TT VERSION version 0.004 SYNOPSIS In your Dancer application's MyApp.pm file ... package MyApp; use Dancer ':syntax'; use Dancer::Plugin::TTHelpers; and in your application's views ... <% css('foo') %> <% js('bar') %> Name: <% text('name') %>
Shirt Size: <% radio('size', sizes) %>
Quantity: <% select('quantity', quants) %>
DESCRIPTION NOTE: this module is very alpha code. *Use at your own risk* Background I was working on a Dancer app and got tired of using the normal Template Toolkit mechanisms for generating forms. Also, I got tired of writing the boiler-plate for CSS and Javascript. Then I remembered when I was working with Rails a few years ago, there were some handy routines for generating this stuff, so after looking around briefly for something similar to what I wanted, I decided to make my own. This was the result. The Helpers By using this module in your Dancer app, new routines are made available from within your views that aid in generating HTML for forms and the standard HTML required for include CSS or Javascript files. Following are the list of routines available from within your templates. Items within square brackets(" [ ] ") are optional and may be omitted: "css(FILE, [ IE_COND ], [ ATTR ])" Outputs a "" tag. "FILE" should be the name of a CSS file within the public/css directory of your app. If "FILE" does not end with ".css", then it is appended. If COND is specified, the CSS link is surrounded with appropriate comments for IE. Any additional attributes for the "" tag may be specified as a hashref. Example usage: <% css('print', { media => "print" }) %> <% css('ie', 'lt IE 8' { media => "screen,projection" }) %> which could result in the following output: "js(FILE, [ IE_COND ], [ ATTR ])" Outputs a " The rest of the helpers are for generating form elements. Each one may optionally pass an object as its first argument. It is expected that this object will have an accessor with the same name as the one specified as the second argument so that the form elements can be initialized with the object's values by default. "radio([OBJ], NAME, [VALUES], [SEPARATOR])" Examples: <% radio('item', [ 'hat', 'shirt', 'shorts' ]) %> <% radio(obj, 'size', [ 'small', 'medium', 'large' ]) %> "text([OBJ], NAME, VALUE, [ ATTR ])" Examples: <% text('title') %> <% text(person, 'name') %> <% text(person, 'dob', { size => 8 }) %> "select([OBJ], NAME, OPTIONS, [KEY], [VALUE], [ ATTR ])" Example: <% select('priority', [ 'low','medium','high' ]) %> "checkbox([OBJ], NAME, CHECKED, [ ATTR ])" Example: "button([OBJ], NAME, [VALUE], [ ATTR ])" Example: "hidden([OBJ], NAME, VALUE, [ ATTR ] )" Example: AUTHOR author = Jonathan Scott Duff COPYRIGHT AND LICENSE This software is copyright (c) 2011 by Jonathan Scott Duff. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.