| 1 | package HTML::MobileJp::Filter::DoCoMoCSS; | ||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | with 'HTML::MobileJp::Filter::Role'; | |||||||||
| 5 | |||||||||||
| 6 | has '+config' => ( | ||||||||||
| 7 | default => sub {{ | ||||||||||
| 8 | 1 | ▶ | base_dir => '', | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | xml_declaration_replace => 1, | ||||||||||
| 10 | xml_declaration => <<'END' | ||||||||||
| 11 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||
| 12 | <!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.0) 1.0//EN" "i-xhtml_4ja_10.dtd"> | ||||||||||
| 13 | END | ||||||||||
| 14 | , | ||||||||||
| 15 | }}, | ||||||||||
| 16 | 1 | ); | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use Encode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use HTML::DoCoMoCSS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | sub filter { | ||||||||||
| 22 | 1 | ▶ | my ($self, $content) = @_; | ||||||||
|
Subroutine
filter: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | unless ($self->mobile_agent->is_docomo) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | return; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | if ($self->config->{xml_declaration_replace}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | # instead of $doc->setEncoding etc.. | ||||||||||
| 30 | 1 | $content =~ s/.*(<html)/$self->config->{xml_declaration} . "\n$1"/msei; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 1 | my $inliner = HTML::DoCoMoCSS->new(base_dir => $self->config->{base_dir}); | |||||||||
| 34 | 1 | $content = $inliner->apply($content); | |||||||||
| 35 | 1 | $content = Encode::decode_utf8($content); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 1 | 1; | |||||||||
| 39 | __END__ | ||||||||||
| 40 | |||||||||||
| 41 | =encoding utf-8 | ||||||||||
| 42 | |||||||||||
| 43 | =head1 NAME | ||||||||||
| 44 | |||||||||||
| 45 | HTML::MobileJp::Filter::DoCoMoCSS - DoCoMo の場合 <link> の CSS をインライン展開 | ||||||||||
| 46 | |||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||
| 48 | |||||||||||
| 49 | - module: EntityReference | ||||||||||
| 50 | config: | ||||||||||
| 51 | base_dir: /path/to/documentroot | ||||||||||
| 52 | |||||||||||
| 53 | =head1 CONFIG AND DEFAULT VALUES | ||||||||||
| 54 | |||||||||||
| 55 | base_dir => '', | ||||||||||
| 56 | xml_declaration_replace => 1, | ||||||||||
| 57 | xml_declaration => <<'END' | ||||||||||
| 58 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||
| 59 | <!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.0) 1.0//EN" "i-xhtml_4ja_10.dtd"> | ||||||||||
| 60 | END | ||||||||||
| 61 | |||||||||||
| 62 | XML 宣言や DTD がないと文字が全部実体参照になったりうまく parse できないので | ||||||||||
| 63 | ヘッダを付け替えることで HTML::DoCoMoCSS の中の XML::libXML に指示をしています。 | ||||||||||
| 64 | |||||||||||
| 65 | TODO のHTML::MobileJp::Filter 側で XML オブジェクトを持つようになった際に | ||||||||||
| 66 | もっと良い方法で指定できるようになる予定です。 | ||||||||||
| 67 | |||||||||||
| 68 | =head1 SEE ALSO | ||||||||||
| 69 | |||||||||||
| 70 | L<HTML::DoCoMoCSS> | ||||||||||
| 71 | |||||||||||
| 72 | =head1 AUTHOR | ||||||||||
| 73 | |||||||||||
| 74 | Naoki Tomita E<lt>tomita@cpan.orgE<gt> | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||