Hachioji.pm #1 LT⽤資料                 ⽤資料名前  Hideaki Ohno       Twitter: @hide_o_55       はてな: id:hide_o_55作った物  Docca     ...
Upcoming SlideShare
Loading in …5
×

Docca - Document Convert API

996 views

Published on

Hachioji.pm #1 LT

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
996
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Docca - Document Convert API

  1. 1. Hachioji.pm #1 LT⽤資料 ⽤資料名前 Hideaki Ohno Twitter: @hide_o_55 はてな: id:hide_o_55作った物 Docca Document Convert API 作った動機 Hachioji.pmnの発表⽤のPDFをどうせ作成するならPerlで作成したい!!! 特定の形式のドキュメントを⼀旦HTMLに変換し、さらに別の形式に変換する プラグイン⽅式で対応する形式を増やせる ⼊⼒されたデータをHTMLに変換する in_filter HTMLを別の形式に変換する out_filter 変換例 Xatena記法 → HTML → PDF URL → HTML → PNG使⽤⽅法use Plack::Builder;use Plack::Request;use Try::Tiny;use Docca;my $docca = Docca->new( in_filter => { Xatena => { xatena => { hatena_compatible => 1 } }, Markdown => {}, URL => {}, }, out_filter => { PDF => { bin_name => /usr/local/bin/wkhtmltopdf } }, xslate => { path => [qw/./], },);my $app = sub { my $env = shift; my $req = Plack::Request->new($env); my $res = $req->new_response(200); try { my $in = $req->parameters->get(content); my $pdf = $docca->convert( $in, { template_file => default.tx, } ) ->from(Xatena)->to( PDF, { encoding => utf-8, } ); $res->content_type(application/pdf); $res->body($pdf); } catch { my $e = shift; $res->code(500); }; return $res->finalize;};builder { enable Plack::Middleware::Static, path => qw{^/(image|css|js)/}, root => ./static; mount /to_pdf => $app;};

×