| 1 | package Plack::App::APISchema::Document; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use parent qw(Plack::Component); | ||
| 5 | use Plack::Util::Accessor qw(schema); | ||
| 6 | use Text::Markdown::Hoedown qw(markdown); | ||
| 7 | use Text::MicroTemplate qw(encoded_string); | ||
| 8 | use Text::MicroTemplate::DataSection qw(render_mt); | ||
| 9 | use Encode qw(encode_utf8); | ||
| 10 | |||
| 11 | use APISchema::Generator::Markdown; | ||
| 12 | |||
| 13 | sub call { | ||
| 14 | my ($self, $env) = @_; | ||
| 15 | |||
| 16 | my $generator = APISchema::Generator::Markdown->new; | ||
| 17 | my $markdown = $generator->format_schema($self->schema); | ||
| 18 | |||
| 19 | my $body = markdown( | ||
| 20 | $markdown, | ||
| 21 | extensions => int( | ||
| 22 | 0 | ||
| 23 | | Text::Markdown::Hoedown::HOEDOWN_EXT_TABLES | ||
| 24 | | Text::Markdown::Hoedown::HOEDOWN_EXT_AUTOLINK | ||
| 25 | | Text::Markdown::Hoedown::HOEDOWN_EXT_FENCED_CODE | ||
| 26 | | Text::Markdown::Hoedown::HOEDOWN_EXT_NO_INTRA_EMPHASIS | ||
| 27 | ) | ||
| 28 | ); | ||
| 29 | |||
| 30 | my $renderer = Text::MicroTemplate::DataSection->new(package => ref $self); | ||
| 31 | my $title = $self->schema->title || ''; | ||
| 32 | my $html = $renderer->render_mt('template.mt', $title, $body); | ||
| 33 | |||
| 34 | return [200, ['Content-Type' => 'text/html; charset=utf-8'], [encode_utf8 $html]]; | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | __DATA__ |