diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Template/Plugin/DateTimeFormat.pm | 38 | ||||
-rw-r--r-- | lib/WebCoso/Maker.pm | 4 | ||||
-rw-r--r-- | lib/WebCoso/ReST.pm | 21 |
3 files changed, 60 insertions, 3 deletions
diff --git a/lib/Template/Plugin/DateTimeFormat.pm b/lib/Template/Plugin/DateTimeFormat.pm new file mode 100644 index 0000000..8c6d592 --- /dev/null +++ b/lib/Template/Plugin/DateTimeFormat.pm @@ -0,0 +1,38 @@ +package Template::Plugin::DateTimeFormat; +$Template::Plugin::DateTimeFormat::VERSION = '0.04'; +use 5.006; +use strict; +use warnings; +use DateTime; +use Class::Load; + +# hacked Template::Plugin::DateTime::Format with patch from +# https://rt.cpan.org/Public/Bug/Display.html?id=120391 + +use base 'Template::Plugin'; + +sub new { + my ($class, $context, $formatter_class, $new_args, $format_args) = @_; + Class::Load::load_class($formatter_class || die 'need class name'); + + my @new_args = ref $new_args eq 'ARRAY' ? @$new_args : $new_args; + if ($format_args) { + $format_args = [ $format_args ] unless ref $format_args eq 'ARRAY'; + } + + bless { + _CONTEXT => $context, + formatter => $formatter_class->new(@new_args), + format_args => $format_args || [], + }, $class; +} + +sub format { + my ($self, $date) = @_; + + my $fmt = $self->{formatter}; + my @args = @{$self->{format_args}}; + return $fmt->format_datetime($date, @args); +} + +1; diff --git a/lib/WebCoso/Maker.pm b/lib/WebCoso/Maker.pm index 35dc41f..5a6f20d 100644 --- a/lib/WebCoso/Maker.pm +++ b/lib/WebCoso/Maker.pm @@ -6,7 +6,7 @@ use File::Next; use Path::Class; use File::Cache::Parsed; use Cwd 'abs_path'; -use YAML::Syck; +use YAML; use WebCoso::Common; use WebCoso::TT; use WebCoso::XSLT; @@ -15,7 +15,7 @@ use Log::Log4perl ':easy'; my $fc=File::Cache::Parsed->new(follow=>1); $fc->add_parser(qr{\.ya?ml$} => - sub { Load($_[1]) }); + sub { local $YAML::LoadBlessed=1; Load($_[1]) }); $fc->add_writer(qr{\.ya?ml$} => sub { DumpFile($_[0],$_[1]) }); diff --git a/lib/WebCoso/ReST.pm b/lib/WebCoso/ReST.pm index cc29d95..5f7f922 100644 --- a/lib/WebCoso/ReST.pm +++ b/lib/WebCoso/ReST.pm @@ -8,6 +8,8 @@ use Text::Restructured::Writer::LibXML; use Log::Log4perl ':easy'; use Encode; +Text::Restructured::Directive::handle_directive( video => \&rst_video); + sub new { my ($class,%opts)=@_; @@ -16,12 +18,13 @@ sub new { $self->{rest}=Text::Restructured->new( { D=>{ - 'file-insertion-enabled'=>0, # we use TT + 'file-insertion-enabled'=>1, # we use TT for insertion, but we need this for "raw" generator=>0, date=>0, 'time'=>0, 'source-link'=>0, 'section-subtitles'=>1, + raw_enabled => 1, }, }, 'WebCoso'); @@ -36,4 +39,20 @@ sub new { bless $self,$class; } +sub rst_video { + my($parser, $name, $parent, $source, $lineno, $dtext, $lit) = @_; + my $dhash = Text::Restructured::Directive::parse_directive($parser, $dtext, $lit, $source, $lineno); + my $options = $dhash->{options}; + my @extra_attrs = (qw(loop type)); + # a video is like an image + my $dom = Text::Restructured::Directive::image(@_,@extra_attrs); + $dom->tag('video'); + for my $attr (@extra_attrs) { + if ($options->{$attr}) { + $dom->{attr}{$attr} = $options->{$attr}; + } + } + return $dom; +} + 1; |