App-MaMGal

 view release on metacpan or  search on metacpan

lib/App/MaMGal/Formatter.pm  view on Meta::CPAN

# mamgal - a program for creating static image galleries
# Copyright 2007-2011 Marcin Owsiany <marcin@owsiany.pl>
# See the README file for license information
# An output formatting class, for creating the actual index files from some
# contents
package App::MaMGal::Formatter;
use strict;
use warnings;
use base 'App::MaMGal::Base';
use Carp;
use Locale::gettext;
use URI::file;
use HTML::Entities qw(encode_entities_numeric);
use App::MaMGal::Logger;

sub init
{
	my $self = shift;
	my $le = shift or croak "Need a locale env arg";
	ref $le and $le->isa('App::MaMGal::LocaleEnv') or croak "Arg is not a App::MaMGal::LocaleEnv, but a [$le]";
	$self->set_locale_env($le);
}

sub set_locale_env
{
	my $self = shift;
	my $le = shift;
	$self->{locale_env} = $le;
}

sub HEADER
{
	my $self = shift;
	my $head = shift || '';
	sprintf("<html><head><meta http-equiv='Content-Type' content='text/html; charset=%s'>%s</head><body>", $self->{locale_env}->get_charset, $head);
}

sub MAYBE_LINK
{
	my $self = shift;
	my $link = shift;
	my $text = shift;
	if ($link) {
		$self->LINK($link.'.html', $text)
	} else {
		$text
	}
}

sub MAYBE_IMG
{
	my $self = shift;
	my $img = shift;
	if ($img) {
		sprintf("<img src='%s'/>", encode_entities_numeric(URI::file->new($img)->as_string));
	} else {
		# TRANSLATORS: This text will appear literally where no thumbnail is avaialable
		# for a given object.
		# Please use &nbsp; for whitespace, to avoid line breaks.
		gettext('[no&nbsp;icon]');
	}
}

sub MAYBE_EMBED
{
	my $self = shift;
	my $film = shift;
	if ($film) {
		sprintf("<embed src='%s'/>", encode_entities_numeric(URI::file->new($film)->as_string));
	} else {
		# TRANSLATORS: This text will appear literally where no path is
		# avaialable for a given film.
		# Please use &nbsp; for whitespace, to avoid line breaks.
		gettext('[no&nbsp;film]');
	}
}

sub LINK
{
	my $self = shift;
	my $link = encode_entities_numeric(URI::file->new(shift)->as_string);
	my $text = shift;
	"<a href='$link'>$text</a>";
}

# TRANSLATORS: The following three are for navigation on a slide page (&lt; is shown as <, and &gt; as >)
sub PREV                { gettext('&lt;&lt; prev') }
sub NEXT                { gettext('next &gt;&gt;') }
sub LINK_DOWN		{ $_[0]->LINK('../index.html', gettext('Up a dir')) }
sub FOOTER		{ "</body></html>"; }
sub EMPTY_PAGE_TEXT	{ gettext("This directory is empty") }
sub CURDIR		{ sprintf '<span class="curdir">%s</span>', $_[1] }

sub format
{



( run in 0.402 second using v1.01-cache-2.11-cpan-aadc1410aed )