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

NAME

Yukki::Web::Plugin::Role::Formatter - interface for HTML formatters

VERSION

version 0.132160

SYNOPSIS

  package MyPlugins::SimpleText;
  use 5.12.1;
  use Moose;

  extends 'Yukki::Web::Plugin';

  has html_formatters => (
      is          => 'ro',
      isa         => 'HashRef[Str]',
      default     => sub { +{
          'text/simple' => 'format_simple',
        } },
  );

  with 'Yukki::Web::Plugin::Role::Formatter;

  sub format_simple {
      my ($self, $file) = @_;

      my $html = $file->fetch;
      $html =~ s/$/<br>/g;
      
      return [ { title => 'Simple' }, $html ];
  }

DESCRIPTION

This role defines the interface for file formatters. The first formatter matching the MIME type for a file will be used to format a page's contents as HTML.

REQUIRED METHODS

html_formatters

This must return a reference to a hash mapping MIME-types to method names.

The methods will be called with a hashref parameter containing the following:

context

The current Yukki::Web::Context object.

repository

The name of the repository this file is in.

page

The full path to the name of the file being formatted.

media_type

This is the media type that Yukki has detected for the file.

content

The body of the page as a string.

The method should return an HTML document.

METHOD

has_format

  my $yes_or_no = $formatter->has_format($media_type);

Returns true if this formatter plugin has a formatter for the named media type.

format

  my $html = $self->format({
      context    => $ctx,
      repository => $repository,
      page       => $full_path,
      media_type => $media_type,
      content    => $content,
  });

Renders the text as HTML. If this plugin cannot format this media type, it returns undef.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Qubling Software LLC.

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