The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Template::Plugin::YUI2::Loader - dependency management with YUI's loader util

VERSION

Version 0.02

SYNOPSIS

This module aims to ease the use of YUI's loader utility by providing means to collect the names of the YUI2 components to be loaded and the code to be run once those components have been successfully loaded anywhere in a nested template structure.

  # in a template A.tt :
  
  ...
  [% USE loader = YUI2.Loader;
     CALL loader.components( 'calendar', 'dragdrop' ).on_success( some_js_code ); 
  %]
  ...

  # in a template wrapper.tt :
  
  <head>
  ...
  </head>
  <body>
  ...

  [% # presumably quite late in the body insert the loader
     USE loader = YUI2.Loader; 
  %]
  
  <script src="http://yui.yahooapis.com/2.8.0r4/build/yuiloader/yuiloader-min.js"></script>
  <script type="text/javascript">
        var loader = 
        new YAHOO.util.YUILoader({
                require: [% loader.components %],
                onSuccess: function() {
                        [% loader.on_success %]
                }
        });
        loader.insert();
  <script>
  </body>

  # in a template B.tt :

  [% WRAPPER wrapper.tt %]
        ...
        [% INCLUDE A.tt;
           USE loader = YUI2.Loader;
           CALL loader.components( 'cookie' ).on_success( some_js_code );
        %]
        ...
  [% END %]

EXPORT

Exported stash variable: YUI2Loader_

METHODS

components

This plugin method is for requesting YUI components.

It accepts (multiple) YUI module names. Please refer to Yahoo's online documentation of the YUI loader utility for the respective names of the components in this context. A repeated request of a component is silently ignored. In order to be able to chain calls to the loader plugin object, the plugin object itself is returned on write access.

With no parameters passed it will return the component list as a javascript data structure suitable to be used as a value for the loader's configuration option 'requires' (see SYNOPSIS).

on_success

This plugin method is for scheduling code to run once the YUI components have been fully loaded. It accepts javascript code as a parameter. In order to be able to chain calls to the loader plugin object, the plugin object itself is returned on write access.

With no parameters passed it will return the javascript code snippets passed to the method on previous calls as a javascript code suitable to be used inside the function reference passed to the loader's configuration option 'onSuccess' (see SYNOPSIS). When stringifying the list of code snippets each code item is returned in the order of write calls to this method, and is wrapped in a call of an anonymous javascript function in order to prevent the conflicting of code.

AUTHOR

Alexander Kühne, <alexk at cpan.org>

BUGS

Please report any bugs or feature requests to bug-template-plugin-yui2-loader at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Plugin-YUI2-Loader. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Template::Plugin::YUI2::Loader

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2010 Alexander Kühne, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 167:

Non-ASCII character seen before =encoding in 'Kühne,'. Assuming CP1252