| JS-YUI-Loader documentation | Contained in the JS-YUI-Loader distribution. |
JS::YUI::Loader - Load (and cache) the Yahoo JavaScript YUI framework
Version 0.06
use JS::YUI::Loader;
my $loader = JS::YUI::Loader->new_from_yui_host;
$loader->include->yuitest->reset->fonts->base;
print $loader->html;
# The above will yield:
# <link rel="stylesheet" href="http://yui.yahooapis.com/2.5.1/build/reset/reset.css" type="text/css"/>
# <link rel="stylesheet" href="http://yui.yahooapis.com/2.5.1/build/fonts/fonts.css" type="text/css"/>
# <link rel="stylesheet" href="http://yui.yahooapis.com/2.5.1/build/base/base.css" type="text/css"/>
# <script src="http://yui.yahooapis.com/2.5.1/build/yahoo/yahoo.js" type="text/javascript"></script>
# <script src="http://yui.yahooapis.com/2.5.1/build/dom/dom.js" type="text/javascript"></script>
# <script src="http://yui.yahooapis.com/2.5.1/build/event/event.js" type="text/javascript"></script>
# <script src="http://yui.yahooapis.com/2.5.1/build/logger/logger.js" type="text/javascript"></script>
# <script src="http://yui.yahooapis.com/2.5.1/build/yuitest/yuitest.js" type="text/javascript"></script>
You can also cache YUI locally:
my $loader = JS::YUI::Loader->new_from_yui_host(cache => { dir => "htdocs/assets", uri => "http://example.com/assets" });
$loader->include->yuitest->reset->fonts->base;
print $loader->html;
# The above will yield:
# <link rel="stylesheet" href="http://example.com/assets/reset.css" type="text/css"/>
# <link rel="stylesheet" href="http://example.com/assets/fonts.css" type="text/css"/>
# <link rel="stylesheet" href="http://example.com/assets/base.css" type="text/css"/>
# <script src="http://example.com/assets/yahoo.js" type="text/javascript"></script>
# <script src="http://example.com/assets/dom.js" type="text/javascript"></script>
# <script src="http://example.com/assets/event.js" type="text/javascript"></script>
# <script src="http://example.com/assets/logger.js" type="text/javascript"></script>
# <script src="http://example.com/assets/yuitest.js" type="text/javascript"></script>
JS::YUI::Loader is a tool for loading YUI assets within your application. Loader will either provide the URI/HTML to access http://yui.yahooapis.com directly, or you can cache assets locally or serve them from an exploded yui_x.x.x.zip dir.
Return a new JS::YUI::Loader object configured to fetch and/or serve assets from http://yui.yahooapis.com/<version>
Return a new JS::YUI::Loader object configured to fetch/serve assets from a local, exploded yui_x.x.x.zip dir
As an example, for a dir of ./assets, the reset.css asset should be available as:
./assets/reset/reset.css
Return a new JS::YUI::Loader object configured to serve assets from an arbitrary uri
As an example, for a base of http://example.com/assets, the reset.css asset should be available as:
http://example.com/assets/reset.css
Return a new JS::YUI::Loader object configured to serve assets from an arbitrary dir
As an example, for a dir of ./assets, the reset.css asset should be available as:
./assets/reset.css
Include each <component> in the "manifest" for the loader.
A <component> should correspond to an entry in the YUI component catalog (see below)
Returns a chainable component selector that will include what is called
You can use the methods of the selector to choose components to include. See YUI component catalog below
You can return to the loader by using the special ->then method:
$loader->include->reset->yuilogger->grids->fonts->then->html;
Returns a chainable component selector that will exclude what is called
You can use the methods of the selector to choose components to include. See YUI component catalog below
You can return to the loader by using the special ->then method:
$loader->exclude->yuilogger->then->html;
Turn on the -min filter for all included components
For example:
connection-min.js
yuilogger-min.js
base-min.css
fonts-min.css
Turn on the -debug filter for all included components
For example:
connection-debug.js
yuilogger-debug.js
base-debug.css
fonts-debug.css
Disable filtering of included components
For example:
connection.js
yuilogger.js
base.css
fonts.css
Attempt to fetch a URI for <component> using the current filter setting of the loader (-min, -debug, etc.)
If the loader has a cache, then this method will try to fetch from the cache. Otherwise it will use the source.
Attempt to fetch a Path::Class::File for <component> using the current filter setting of the loader (-min, -debug, etc.)
If the loader has a cache, then this method will try to fetch from the cache. Otherwise it will use the source.
Attempt to fetch a URI for <component> using the current filter setting of the loader (-min, -debug, etc.) from the cache
Attempt to fetch a Path::Class::File for <component> using the current filter setting of the loader (-min, -debug, etc.) from the cache
Attempt to fetch a URI for <component> using the current filter setting of the loader (-min, -debug, etc.) from the source
Attempt to fetch a Path::Class::File for <component> using the current filter setting of the loader (-min, -debug, etc.) from the source
Return a JS::YUI::Loader::Item for <component> using the current filter setting of the loader (-min, -debug, etc.)
Return the item path for <component> using the current filter setting of the loader (-min, -debug, etc.)
Return the item file for <component> using the current filter setting of the loader (-min, -debug, etc.)
Generate and return a string containing HTML describing how to include components. For example, you can use this in the <head> section of a web page.
If the loader has a cache, then it will attempt to generate URIs from the cache, otherwise it will use the source.
Here is an example:
<link rel="stylesheet" href="http://example.com/assets/reset.css" type="text/css"/>
<link rel="stylesheet" href="http://example.com/assets/fonts.css" type="text/css"/>
<link rel="stylesheet" href="http://example.com/assets/base.css" type="text/css"/>
<script src="http://example.com/assets/yahoo.js" type="text/javascript"></script>
<script src="http://example.com/assets/dom.js" type="text/javascript"></script>
<script src="http://example.com/assets/event.js" type="text/javascript"></script>
<script src="http://example.com/assets/logger.js" type="text/javascript"></script>
<script src="http://example.com/assets/yuitest.js" type="text/javascript"></script>
Generate and return a string containing HTML describing how to include components. For example, you can use this in the <head> section of a web page.
Here is an example:
<link rel="stylesheet" href="http://example.com/assets/reset.css" type="text/css"/>
<link rel="stylesheet" href="http://example.com/assets/fonts.css" type="text/css"/>
<link rel="stylesheet" href="http://example.com/assets/base.css" type="text/css"/>
<script src="http://example.com/assets/yahoo.js" type="text/javascript"></script>
<script src="http://example.com/assets/dom.js" type="text/javascript"></script>
<script src="http://example.com/assets/event.js" type="text/javascript"></script>
<script src="http://example.com/assets/logger.js" type="text/javascript"></script>
<script src="http://example.com/assets/yuitest.js" type="text/javascript"></script>
Animation Utility (utility)
AutoComplete Control (widget)
Base CSS Package (css)
Calendar Control (widget)
Charts Control (widget)
Color Picker Control (widget)
Connection Manager (utility)
Container Family (widget)
Container Core (Module, Overlay) (widget)
DataSource Utility (utility)
DataTable Control (widget)
Dom Collection (core)
Drag & Drop Utility (utility)
Rich Text Editor (widget)
Element Utility (utility)
Event Utility (core)
Fonts CSS Package (css)
Get Utility (utility)
Grids CSS Package (css)
Browser History Manager (utility)
ImageCropper Control (widget)
ImageLoader Utility (utility)
JSON Utility (utility)
Layout Manager (widget)
Logger Control (tool)
Profiler (tool)
ProfilerViewer Control (tool)
Reset CSS Package (css)
Resize Utility (utility)
Selector Utility (utility)
Simple Editor (widget)
Slider Control (widget)
TabView Control (widget)
TreeView Control (widget)
Uploader (widget)
Yahoo Global Object (core)
Loader Utility (utility)
YUI Test Utility (tool)
Robert Krimen, <rkrimen at cpan.org>
Please report any bugs or feature requests to bug-js-yui-loader at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JS-YUI-Loader. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc JS::YUI::Loader
You can also look for information at:
Copyright 2008 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| JS-YUI-Loader documentation | Contained in the JS-YUI-Loader distribution. |
package JS::YUI::Loader; use warnings; use strict;
our $VERSION = '0.06'; use constant LATEST_YUI_VERSION => "2.5.1"; use Moose; use JS::YUI::Loader::Carp; use JS::YUI::Loader::Catalog; use HTML::Declare qw/LINK SCRIPT/; has catalog => qw/is ro required 1 isa JS::YUI::Loader::Catalog lazy 1/, default => sub { shift->source->catalog }; has manifest => qw/is ro required 1 isa JS::YUI::Loader::Manifest lazy 1/, handles => [qw/include exclude clear select parse schedule/], default => sub { my $self = shift; require JS::YUI::Loader::Manifest; return JS::YUI::Loader::Manifest->new(catalog => $self->catalog, loader => $self); }; has list => qw/is ro required 1 isa JS::YUI::Loader::List lazy 1/, default => sub { my $self = shift; require JS::YUI::Loader::List; return JS::YUI::Loader::List->new(loader => $self); }; has source => qw/is ro required 1 isa JS::YUI::Loader::Source/; has cache => qw/is ro isa JS::YUI::Loader::Cache/; has filter => qw/is rw isa Str/, default => "";
sub new_from_yui_host { return shift->new_from_internet(@_); } sub new_from_internet { my $class = shift; my ($given, $catalog) = $class->_new_given_catalog(@_); my %source; $source{version} = delete $given->{version} if exists $given->{version}; $source{base} = delete $given->{base} if exists $given->{base}; require JS::YUI::Loader::Source::Internet; my $source = JS::YUI::Loader::Source::Internet->new(catalog => $catalog, %source); return $class->_new_finish($given, $source); }
sub new_from_yui_dir { my $class = shift; my ($given, $catalog) = $class->_new_given_catalog(@_); my %source; $source{version} = delete $given->{version} if exists $given->{version}; $source{base} = delete $given->{base} if exists $given->{base}; $source{dir} = delete $given->{dir} if exists $given->{dir}; require JS::YUI::Loader::Source::YUIDir; my $source = JS::YUI::Loader::Source::YUIDir->new(catalog => $catalog, %source); return $class->_new_finish($given, $source); }
sub new_from_uri { my $class = shift; my ($given, $catalog) = $class->_new_given_catalog(@_); my %source; $source{base} = delete $given->{base} if exists $given->{base}; require JS::YUI::Loader::Source::URI; my $source = JS::YUI::Loader::Source::URI->new(catalog => $catalog, %source); return $class->_new_finish($given, $source); }
sub new_from_dir { my $class = shift; my ($given, $catalog) = $class->_new_given_catalog(@_); my %source; $source{base} = delete $given->{base} if exists $given->{base}; $source{dir} = delete $given->{dir} if exists $given->{dir}; require JS::YUI::Loader::Source::Dir; my $source = JS::YUI::Loader::Source::Dir->new(catalog => $catalog, %source); return $class->_new_finish($given, $source); }
sub filter_min { my $self = shift; return $self->filter("min"); return $self; }
sub filter_debug { my $self = shift; $self->filter("debug"); return $self; }
sub no_filter { my $self = shift; $self->filter(""); return $self; }
sub uri { my $self = shift; return $self->cache_uri(@_) if $self->cache; return $self->source_uri(@_); }
sub file { my $self = shift; return $self->cache_file(@_) if $self->cache; return $self->source_file(@_); }
sub cache_uri { my $self = shift; my $name = shift; return $self->cache->uri([ $name => $self->filter ]) || croak "Unable to get uri for $name from cache ", $self->cache; }
sub cache_file { my $self = shift; my $name = shift; return $self->cache->file([ $name => $self->filter ]) || croak "Unable to get file for $name from cache ", $self->cache; }
sub source_uri { my $self = shift; my $name = shift; return $self->source->uri([ $name => $self->filter ]) || croak "Unable to get uri for $name from source ", $self->source; }
sub source_file { my $self = shift; my $name = shift; return $self->source->file([ $name => $self->filter ]) || croak "Unable to get file for $name from source ", $self->source; }
sub item { my $self = shift; my $name = shift; return $self->catalog->item([ $name => $self->filter ]); }
sub item_path { my $self = shift; my $name = shift; return $self->item($name)->path; }
sub item_file { my $self = shift; my $name = shift; return $self->item($name)->file; } sub name_list { my $self = shift; return $self->manifest->schedule; } sub _html { my $self = shift; my $uri_list = shift; my $separator = shift || "\n"; my @uri_list = $self->list->uri; my @html; for my $uri (@uri_list) { if ($uri =~ m/\.css/) { push @html, LINK({ rel => "stylesheet", type => "text/css", href => $uri }); } else { push @html, SCRIPT({ type => "text/javascript", src => $uri, _ => "" }); } } return join $separator, @html; }
sub html { my $self = shift; return $self->_html([ $self->list->uri ], @_); }
sub source_html { my $self = shift; return $self->_html([ $self->list->source_uri ], @_); } sub _new_given { my $class = shift; return @_ == 1 && ref $_[0] eq "HASH" ? shift : { @_ }; } sub _new_catalog { my $class = shift; my $given = shift; my $catalog = delete $given->{catalog} || {}; return $given->{catalog} = $catalog if blessed $catalog; return $given->{catalog} = JS::YUI::Loader::Catalog->new(%$catalog); } sub _build_cache { my $class = shift; my $given = shift; my $source = shift; my (%cache, $cache_class); if (ref $given eq "ARRAY") { $cache_class = "JS::YUI::Loader::Cache::URI"; my ($uri, $dir) = @$given; %cache = (uri => $uri, dir => $dir); } elsif (ref $given eq "HASH") { $cache_class = "JS::YUI::Loader::Cache::URI"; my ($uri, $dir) = @$given{qw/uri dir/}; %cache = (uri => $uri, dir => $dir); } elsif (ref $given eq "Path::Resource") { $cache_class = "JS::YUI::Loader::Cache::URI"; %cache = (uri => $given->uri, dir => $given->dir); } else { $cache_class = "JS::YUI::Loader::Cache::Dir"; %cache = (dir => $given); } eval "require $cache_class;" or die $@; return $cache_class->new(source => $source, %cache); } sub _new_cache { my $class = shift; my $given = shift; my $source = shift; if (my $cache = delete $given->{cache}) { $given->{cache} = $class->_build_cache($cache, $source); } } sub _new_given_catalog { my $class = shift; my $given = $class->_new_given(@_); my $catalog = $class->_new_catalog($given); return ($given, $catalog); } sub _new_finish { my $class = shift; my $given = shift; my $source = shift; $class->_new_cache($given, $source); return $class->new(%$given, source => $source); }
1;
1; # End of JS::YUI::Loader