Skip to content

Commit

Permalink
all and default are again different transition sets (default being im…
Browse files Browse the repository at this point in the history
…pressive's defaults)
  • Loading branch information
jberger committed Feb 18, 2013
1 parent b4e2158 commit a3d9c91
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 67 deletions.
3 changes: 2 additions & 1 deletion bin/makebeamerinfo
Expand Up @@ -117,8 +117,9 @@ L<Impressive|http://impressive.sourceforge.net/> is a pdf viewer that aids in vi
--transitions
Request a specific transition set. Currenly it may be one of:
- all allow all of the transitions
- default impressive's default transitions (default)
- turn pageturn and wiperight, the author's preference
- sane (default) selections which make sense
- sane selections which make sense for beamer
Note that these may also be specified with the (exported) environment
variable $MAKEBEAMERINFO_TRANSITIONS, again set to one of the above
Expand Down
34 changes: 22 additions & 12 deletions lib/App/makebeamerinfo.pm
Expand Up @@ -12,22 +12,23 @@ use Text::Balanced qw/extract_bracketed extract_multiple/;
our $VERSION = "2.002";
$VERSION = eval $VERSION;

use App::makebeamerinfo::Transitions;
use App::makebeamerinfo::Transitions 'new_transition_set';

# the "wipe" transition set is useful for me
my %transitions = (
all => App::makebeamerinfo::Transitions->new('all'),
all => new_transition_set('all', ':all'),
default => new_transition_set('default', ':default'),
);

$transitions{turn} = App::makebeamerinfo::Transitions->new(
$transitions{turn} = new_transition_set(
'turn',
increment => ["WipeRight"],
frame => ["PageTurn"],
);

# the "sane" transition set sorts the available transitions
# into the two uses as appropriate for a beamer presentation
$transitions{sane} = App::makebeamerinfo::Transitions->new(
$transitions{sane} = new_transition_set(
'sane',
increment => [ qw/
WipeCenterIn WipeCenterOut
Expand Down Expand Up @@ -67,26 +68,35 @@ sub new {
# and AtBeginSubsection elements (default true)
collapse => 1,
# set_transition default to sane
transition_set => $transitions{sane},
transition_set => $transitions{default},
},
};

if ( defined $args->{transition_set} and exists $transitions{ $args->{transition_set} } ) {
$self->{options}{transition_set} = $transitions{ $args->{transition_set} };
}

# pull files from arguments if present
$self->{files}{pdf} = abs_path($args->{pdf}) if $args->{pdf};
$self->{files}{nav} = abs_path($args->{nav}) if $args->{nav};

bless $self, $class;

if ( defined $args->{transition_set} ) {
$self->transition_set( $args->{transition_set} );
}

$self->_hunt_for_files;

return $self;

}

sub transition_set {
my $self = shift;
if ( my $name = shift ) {
my $trans = $self->{transitions}{$name} || die "Unknown transition set $name\n";
$self->{options}{transition_set} = $trans;
}
return $self->{options}{transition_set}->name
}

sub _hunt_for_files {
my $self = shift;
my $files = $self->{files};
Expand Down Expand Up @@ -299,14 +309,14 @@ sub writeInfo {
if (
$pages->{$page}{'type'} eq 'frame'
&& ! $pages->{$page}{'to_collapse'}
&& ! $trans->all_frame
&& ! $trans->default_frame
) {
print $info "\t \'transition\': " . $trans->get_random_element . ",\n";
}
print $info "\t},\n";
}
print $info "}\n";
unless ( $trans->all_increment ) {
unless ( $trans->default_increment ) {
print $info "AvailableTransitions = [";
print $info join( ", ", $trans->get_selected('increment') );
print $info "]";
Expand Down Expand Up @@ -356,7 +366,7 @@ L<LaTeX Beamer|http://latex-beamer.sourceforge.net/>
=item *
Need more tests! Specifically, unit tests. This was my first published script, written before I was aware of such thing. The version 2.0 release was requested by user and as such is still lacking a roundly covering test suite. This should be corrected.
The test suite is improving, but still not excellent coverage. Continuing this is important.
=back
Expand Down
58 changes: 43 additions & 15 deletions lib/App/makebeamerinfo/Transitions.pm
Expand Up @@ -4,6 +4,12 @@ use strict;
use warnings;
use Carp;

use Exporter ();
our @ISA = 'Exporter';
our @EXPORT_OK = qw/new_transition_set/;

sub new_transition_set { __PACKAGE__->new(@_) }

#list of the available transitions
our @All = ( qw/
Crossfade
Expand All @@ -27,33 +33,56 @@ sub new {
};
bless $self, $class;

# handle shortcut
if ( @_ == 1 ) {
my $base = shift;
push @_, frame => $base, increment => $base;
}

$self->_initialize(@_);
return $self;
}

sub _initialize {
my $self = shift;

# called without arguments, get all, otherwise null for later setting
my $base = @_ ? 0 : 1;
my %init = @_;

$self->{increment}{$_} = $base for @All;
$self->{frame}{$_} = $base for @All;
for my $type ( qw/ frame increment / ) {

return unless @_;
my $spec = $init{$type};

my %init = @_;
$self->{$type} = {};
next if $spec eq ':default';

my $base = 0;
if ( $spec eq ':all' ) {
$base = 1;
}

$self->{increment}{$_} = 1 for @{ $init{increment} };
$self->{frame}{$_} = 1 for @{ $init{frame} };
$self->{$type}{$_} = $base for @All;

if ( ref $spec ) {
$self->{$type}{$_} = 1 for @$spec;
}

}
}

# get all selected

sub get_selected {
my ($self, $type) = @_;
my $hash = $self->get_type($type);
my @keys = keys %$hash;
croak "Type $type is default" unless @keys;
return sort grep { $hash->{$_} } @keys;
}

sub get_type {
my ($self, $type) = @_;
my $hash = $self->{$type} || croak "Unknown transition type '$type'";
return sort grep { $hash->{$_} } keys %$hash;
return $hash;
}

# return the contents of a random element of an array
Expand All @@ -77,16 +106,15 @@ sub get_random_element {
return $return;
}

# test if all X are selected
# test if default X are selected

sub _all {
sub _default {
my ($self, $type) = @_;
my @array = $self->get_selected($type);
return @All == @array;
return ! keys %{ $self->{$type} };
}

sub all_frame { shift->_all('frame') }
sub all_increment { shift->_all('increment') }
sub default_frame { shift->_default('frame') }
sub default_increment { shift->_default('increment') }

# ro accessors
sub name { $_[0]->{name} }
Expand Down
67 changes: 44 additions & 23 deletions t/full.t
Expand Up @@ -2,20 +2,13 @@ use strict;
use warnings;

use Test::More;
use File::Temp ();
use File::Spec;

use App::makebeamerinfo;

#================
# Create some temporary files

my $dir = File::Temp->newdir;
my $nav = File::Spec->catfile( "$dir", 'myfile.nav' );

{
open my $nav_handle, '>', $nav or die "Cannot create temporary nav file for testing";
print $nav_handle <<'NAV';
my $nav = <<'NAV';
\beamer@endinputifotherversion {3.10pt}
\headcommand {\slideentry {0}{0}{1}{1/1}{}{0}}
\headcommand {\beamer@framepages {1}{1}}
Expand All @@ -33,10 +26,8 @@ my $nav = File::Spec->catfile( "$dir", 'myfile.nav' );
\headcommand {\beamer@documentpages {5}}
\headcommand {\def \inserttotalframenumber {3}}
NAV
}

my $good_info = File::Temp->new( SUFFIX => '.pdf.info' );
print $good_info <<'INFO';
my $turn_info = <<'INFO';
PageProps = {
1: {
'title': "Title",
Expand All @@ -59,33 +50,63 @@ PageProps = {
}
AvailableTransitions = [WipeRight]
INFO
seek($good_info, 0, 0);

#========================
# Tests

my $app = App::makebeamerinfo->new( nav => $nav, transition_set => 'turn' );
my $app = App::makebeamerinfo->new;
isa_ok( $app, 'App::makebeamerinfo' );

$app->readNav;
{
# this should prevent cross platform newline problems when reading the test doc above
local $/ = '
';

open my $nav_handle, '<', \$nav or die "Cannot open scalar for reading: $!";
$app->readNav($nav_handle);
}

ok( values %{ $app->{pages} }, "Found pages" );
ok( values %{ $app->{sections} }, "Found sections" );

my $info = File::Temp->new();
$app->writeInfo($info);
seek($info, 0, 0);
#=====================
# Test default set

is $app->transition_set, 'default', 'Default to correct set (default)';

my $output = '';
{
open my $output_handle, '>', \$output or die "Cannot open scalar for writing: $!";
$app->writeInfo($output_handle);
}

unlike( $output, qr/transition/, 'Default set does not emit transition statments' );
unlike( $output, qr/AvailableTransitions/, 'Default set does not emit AvailableTransitions' );

my $i = 0;
while(my $good_line = <$good_info>) {
chomp $good_line;
#=================
# Test turn set

my $test_line = <$info>;
chomp $test_line;
$app->transition_set('turn');

is( $test_line, $good_line, "Files equal line: " . ++$i );
$output = '';
{
open my $output_handle, '>', \$output or die "Cannot open scalar for writing: $!";
$app->writeInfo($output_handle);
}

# remove confusing vertical whitespace
$output =~ s/[\r\n]//g;
$turn_info =~ s/[\r\n]//g;

is( $output, $turn_info, 'Output as expected' );

#===================
# Other tests

eval { $app->transition_set('does_not_exist') };
ok( $@, 'Selecting unknown transition set dies' );
like( $@, qr/Unknown transition set/, 'Error message' );

done_testing;


22 changes: 6 additions & 16 deletions t/transitions.t
Expand Up @@ -15,32 +15,22 @@ my $trans = App::makebeamerinfo::Transitions->new(

is $trans->name, 'myname', 'Name gets added correctly';

my @all = @App::makebeamerinfo::Transitions::All;
is keys %{ $trans->{frame} }, @all, 'right number of frame transitions';
is keys %{ $trans->{increment} }, @all, 'right number of increment transitions';
my @all = sort @App::makebeamerinfo::Transitions::All;
is_deeply [ sort keys %{ $trans->{frame} } ], \@all, 'right frame transitions';
is_deeply [ sort keys %{ $trans->{increment} } ], \@all, 'right increment transitions';

is_deeply [ $trans->get_selected('frame') ], $frame, 'frame transitions selected';
is_deeply [ $trans->get_selected('frame') ], $frame, 'frame transitions selected';
is_deeply [ $trans->get_selected('increment') ], $increment, 'increment transitions selected';

ok ! $trans->all_frame, 'Does not use all frames';
ok ! $trans->all_increment, 'Does not use all increment';

is $trans->get_random_element('increment'), 'WipeUp', 'Get the right transition when only one selected';
is $trans->get_random_element('increment'), 'WipeUp', 'Get the right transition when only one selected (again)';

$trans->{last_transition} = 'Crossfade';
is $trans->get_random_element, 'SlideDown', 'Get other transition';
is $trans->get_random_element, 'Crossfade', 'Get other transition (again)';

my $all = App::makebeamerinfo::Transitions->new('all');

ok $all->all_frame, 'Uses all frames';
ok $all->all_increment, 'Uses all increment';

$all->{frame}{Crossfade} = 0;
ok ! $all->all_frame, 'Now, does not use all frames';
ok $all->all_increment, 'But still uses all increment';

ok ! $trans->default_frame, 'Not using default set for frame';
ok ! $trans->default_increment, 'Not using default set for increment';

done_testing;

0 comments on commit a3d9c91

Please sign in to comment.