65 lines
1.3 KiB
Perl
65 lines
1.3 KiB
Perl
|
package Classy::Handler::Fragment;
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
use namespace::autoclean;
|
||
|
|
||
|
our $VERSION = '0.10';
|
||
|
|
||
|
use Markdent::Role::HTMLStream;
|
||
|
use List::Util qw(first);
|
||
|
use Classy::Event::AsideBlock;
|
||
|
use Markdent::Types;
|
||
|
use Params::ValidationCompiler qw( validation_for );
|
||
|
|
||
|
use Moose;
|
||
|
|
||
|
with 'Markdent::Role::HTMLStream';
|
||
|
|
||
|
# We're a fragment, don't output start/end document
|
||
|
sub start_document { }
|
||
|
sub end_document { }
|
||
|
|
||
|
around '_stream_start_tag' => sub {
|
||
|
my $orig = shift;
|
||
|
my $self = shift;
|
||
|
my $tag = shift;
|
||
|
my $attr = shift;
|
||
|
|
||
|
if ($tag eq "img" && !exists $attr->{class}) {
|
||
|
$attr->{class} = "as-post";
|
||
|
}
|
||
|
|
||
|
$self->$orig($tag, $attr);
|
||
|
};
|
||
|
|
||
|
{
|
||
|
my $validator = validation_for(
|
||
|
params => [
|
||
|
inner => { type => t('Str') },
|
||
|
class => {
|
||
|
type => t('Str'),
|
||
|
optional => 1,
|
||
|
},
|
||
|
],
|
||
|
named_to_list => 1,
|
||
|
);
|
||
|
|
||
|
sub aside_block {
|
||
|
my $self = shift;
|
||
|
my ( $inner, $class ) = $validator->(@_);
|
||
|
my %attrs = ( class => "aside" );
|
||
|
|
||
|
if ( $class ) {
|
||
|
$attrs{class} .= " $class";
|
||
|
}
|
||
|
$self->_stream_start_tag( 'div', \%attrs );
|
||
|
|
||
|
$self->_stream_text($inner);
|
||
|
|
||
|
$self->_stream_end_tag('div');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
1;
|