| HTML-MobileJp-Filter documentation | Contained in the HTML-MobileJp-Filter distribution. |
HTML::MobileJp::Filter::PictogramFallback::TypeCast - PC の場合絵文字を TypeCast の絵文字画像に
- module: PictogramFallback::TypeCast
config:
emoticon_yaml: /path/to/emoticon.yaml
template: <img src="/img/emoticon/%s.gif" />
emoticon_yaml => '', # /path/to/typecast/conf/emoticon.yaml template => '', # sprintf format
TypeCast の絵文字画像(DoCoMo 相当)にない絵文字はそのままです。 TypeCast にない絵文字について文字で表現するようにしたい場合は PictogramFallback と 組み合わせて以下のようにする方法があります。
- module: PictogramFallback::TypeCast
config:
emoticon_yaml: /path/to/emoticon.yaml
template: <img src="/img/emoticon/%s.gif" />
- module: PictogramFallback
config:
template: %s
params:
- fallback_name_htmlescape
Naoki Tomita <tomita@cpan.org>
| HTML-MobileJp-Filter documentation | Contained in the HTML-MobileJp-Filter distribution. |
package HTML::MobileJp::Filter::PictogramFallback::TypeCast; use Any::Moose; with 'HTML::MobileJp::Filter::Role'; has '+config' => ( default => sub {{ emoticon_yaml => '', # /path/to/typecast/conf/emoticon.yaml template => '', # sprintf format }}, ); has emoticon_map => ( is => 'rw', isa => 'Maybe[HashRef]', default => sub { {} }, ); use Encode; use Encode::JP::Mobile ':props'; use YAML; sub init { my $self = shift; my $yaml = YAML::LoadFile($self->config->{emoticon_yaml}) or die "can't open file: ". $self->config->{emoticon_yaml}; $self->emoticon_map($yaml->{docomo}); } sub filter { my ($self, $html) = @_; unless ($self->mobile_agent->is_non_mobile) { return; } $html = Encode::encode('x-utf8-docomo', $html, sub { encode_utf8 chr shift} ); $html = Encode::decode('utf-8', $html); $html =~ s{(\p{InMobileJPPictograms})}{ my $char = $1; my $code = sprintf '%X', ord $char; if (my $name = $self->emoticon_map->{$code}) { sprintf $self->config->{template}, $name, $char; } else { $char; } }ge; $html; } __PACKAGE__->meta->make_immutable; 1; __END__