HTML-Widget-Plugin-Calendar
    
    
  
  
  
view release on metacpan or search on metacpan
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
dist.ini
lib/HTML/Widget/Plugin/Calendar.pm
t/000-report-versions-tiny.t
t/calendar.t
xt/release/changes_has_content.t
xt/release/pod-syntax.t
{
   "abstract" : "simple construction of jscalendar inputs",
   "author" : [
      "Ricardo SIGNES"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.141520",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'simple construction of jscalendar inputs'
author:
  - 'Ricardo SIGNES'
build_requires:
  HTML::Widget::Factory: '0'
  Test::More: '0.96'
configure_requires:
  ExtUtils::MakeMaker: '6.30'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.141520'
license: perl
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
  "ABSTRACT" => "simple construction of jscalendar inputs",
  "AUTHOR" => "Ricardo SIGNES",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => "6.30"
  },
  "DISTNAME" => "HTML-Widget-Plugin-Calendar",
  "EXE_FILES" => [],
  "LICENSE" => "perl",
  "NAME" => "HTML::Widget::Plugin::Calendar",
  "PREREQ_PM" => {
    "Class::Data::Inheritable" => 0,
This archive contains the distribution HTML-Widget-Plugin-Calendar,
version 0.022:
  simple construction of jscalendar inputs
This software is copyright (c) 2005 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
This README file was generated by Dist::Zilla::Plugin::Readme v5.019.
lib/HTML/Widget/Plugin/Calendar.pm view on Meta::CPAN
use strict;
use warnings;
package HTML::Widget::Plugin::Calendar;
# ABSTRACT: simple construction of jscalendar inputs
$HTML::Widget::Plugin::Calendar::VERSION = '0.022';
use parent qw(HTML::Widget::Plugin Class::Data::Inheritable);
use HTML::Element;
use HTML::TreeBuilder;
use Data::JavaScript::Anon;
#pod =head1 SYNOPSIS
#pod
#pod   $factory->calendar({
#pod     name   => 'date_of_birth',
#pod     format => '%Y-%m-%d',
#pod     value  => $user->date_of_birth,
#pod   });
#pod
#pod =head1 DESCRIPTION
#pod
#pod This module plugs in to HTML::Widget::Factory and provides a calendar widget
#pod using the excellent jscalendar.
#pod
#pod =head1 METHODS
#pod
#pod =head2 C< provided_widgets >
#pod
#pod This plugin provides the following widgets: calendar, calendar_js
#pod
#pod =cut
sub provided_widgets { qw(calendar calendar_js) }
#pod =head2 calendar
#pod
#pod =cut
sub calendar {
  my ($self, $factory, $arg) = @_;
  $arg->{attr}{name} ||= $arg->{attr}{id};
  Carp::croak "you must supply a widget id for calendar"
    unless $arg->{attr}{id};
  $arg->{jscalendar} ||= {};
  $arg->{jscalendar}{showsTime} = 1 if $arg->{time};
  $arg->{format}
    ||= '%Y-%m-%d' . ($arg->{jscalendar}{showsTime} ? ' %H:%M' : '');
  my $widget = HTML::Element->new('input');
  $widget->attr($_ => $arg->{attr}{$_}) for keys %{ $arg->{attr} };
  $widget->attr(value => $arg->{value}) if exists $arg->{value};
  my $button;
  unless ($arg->{no_button}) {
    $button = HTML::Element->new(
      'button',
lib/HTML/Widget/Plugin/Calendar.pm view on Meta::CPAN
    $button->push_content($arg->{button_label} || '...');
  }
  my $script = HTML::Element->new('script', type => 'text/javascript');
  my $js
    = sprintf "Calendar.setup(%s);",
      Data::JavaScript::Anon->anon_dump({
        inputField => $widget->attr('id'),
        ifFormat   => $arg->{format},
        ($arg->{no_button} ? () : (button => $button->attr('id'))),
        %{ $arg->{jscalendar} },
      })
    ;
  # we need to make this an HTML::Element literal to avoid escaping the JS
  $js = HTML::Element->new('~literal', text => $js);
  $script->push_content($js);
  return join q{},
    $self->calendar_js($factory, $arg),
    map { $_->as_XML } ($widget, ($arg->{no_button} ? () : $button), $script),
  ;
}
#pod =head2 C< calendar_js >
#pod
#pod This method returns the JavaScript needed to use the calendar.  It will only
#pod return the JavaScript the first time it's called.
#pod
#pod Normally it's called when the calendar widget is used, but it may be called
#pod manually to force the JavaScript to be placed in your document at the location
#pod of your choosing.
#pod
#pod =cut
sub calendar_js {
  my ($self, $factory, $arg) = @_;
  return '' if $factory->{$self}->{output_js}++;
  my $base = $self->calendar_baseurl;
  Carp::croak "calendar_baseurl is not defined" if not defined $base;
  $base =~ s{/\z}{}; # to avoid baseurl//yourface or baseurlyourface
  my $scripts = <<END_HTML;
  <script type="text/javascript" src="$base/calendar.js"></script>
  <script type="text/javascript" src="$base/lang/calendar-en.js"></script>
  <script type="text/javascript" src="$base/calendar-setup.js"></script>
END_HTML
}
#pod =head2 C< calendar_baseurl >
#pod
#pod This method sets or returns the plugin's base URL for the jscalendar files.
#pod This must be set or calendar plugin creation will throw an exception.
#pod
#pod =cut
__PACKAGE__->mk_classdata( qw(calendar_baseurl) );
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
HTML::Widget::Plugin::Calendar - simple construction of jscalendar inputs
=head1 VERSION
version 0.022
=head1 SYNOPSIS
  $factory->calendar({
    name   => 'date_of_birth',
    format => '%Y-%m-%d',
    value  => $user->date_of_birth,
  });
=head1 DESCRIPTION
This module plugs in to HTML::Widget::Factory and provides a calendar widget
using the excellent jscalendar.
=head1 METHODS
=head2 C< provided_widgets >
This plugin provides the following widgets: calendar, calendar_js
=head2 calendar
=head2 C< calendar_js >
This method returns the JavaScript needed to use the calendar.  It will only
return the JavaScript the first time it's called.
Normally it's called when the calendar widget is used, but it may be called
manually to force the JavaScript to be placed in your document at the location
of your choosing.
=head2 C< calendar_baseurl >
This method sets or returns the plugin's base URL for the jscalendar files.
This must be set or calendar plugin creation will throw an exception.
=head1 AUTHOR
Ricardo SIGNES
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2005 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under
t/calendar.t view on Meta::CPAN
use Test::More 'no_plan';
use HTML::Widget::Factory;
use HTML::Widget::Plugin::Calendar;
my $factory = HTML::Widget::Factory->new({
  extra_plugins => [ HTML::Widget::Plugin::Calendar->new ],
});
can_ok($factory, 'calendar');
HTML::Widget::Plugin::Calendar->calendar_baseurl('/');
my $html = $factory->calendar({
  id     => 'birthday',
  format => '%Y-%d-%m',
});
( run in 0.733 second using v1.01-cache-2.11-cpan-5dc5da66d9d )