Changeset 366
- Timestamp:
- 05/14/08 14:53:29 (2 months ago)
- Files:
-
- trunk/src/ingy/Vroom/MANIFEST (added)
- trunk/src/ingy/Vroom/Makefile.PL (modified) (1 diff)
- trunk/src/ingy/Vroom/README (modified) (2 diffs)
- trunk/src/ingy/Vroom/lib/Vroom.pm (modified) (7 diffs)
- trunk/src/ingy/Vroom/vroom (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/Vroom/Makefile.PL
r364 r366 4 4 all_from 'lib/Vroom.pm'; 5 5 6 require 'IO::All'; 7 require 'YAML::XS'; 8 require 'Class::Field'; 6 requires 'IO::All'; 7 requires 'YAML::XS'; 8 requires 'Class::Field'; 9 10 install_script 'vroom'; 9 11 10 12 WriteAll; trunk/src/ingy/Vroom/README
r364 r366 3 3 4 4 SYNOPSIS 5 > vim vroom # Write Some Slides 6 > vroom vroom # Compile Your Slides 7 > cd slides # Go To Your Slides 8 > vim * # Show Your Slides 5 > vim slides.vroom # Write Some Slides 6 > vroom --vroom # Show Your Slides 9 7 10 8 DESCRIPTION … … 28 26 29 27 Since Vim is an editor, you can change your slides during the show. 28 29 COMMAND USAGE 30 Vroom has a few command line options: 31 32 vroom 33 Just running vroom will compiles 'slides.vroom' into slide files. 34 35 vroom --vroom 36 Compile and start vim show. 37 38 vroom --clean 39 Clean up all the compiled output files. 40 41 INPUT FORMAT 42 Here is an example slides.vroom: 43 44 ---- config 45 title: My Spiffy Slideshow 46 height: 84 47 width: 20 48 ---- center 49 My Presentation 50 51 by Ingy 52 ---- 53 == Stuff I care about: 54 55 * Foo 56 +* Bar 57 +* Baz 58 ---- perl 59 use Vroom; 60 61 print "Hello World"; 62 ---- center 63 THE END 30 64 31 65 KEY MAPPINGS trunk/src/ingy/Vroom/lib/Vroom.pm
r364 r366 3 3 use strict; 4 4 use warnings; 5 6 # use XXX; 7 # use diagnostics; 8 9 our $VERSION = '0.10'; 5 10 6 11 use IO::All; … … 10 15 use Carp; 11 16 12 field input => ''; 17 field input => 'slides.vroom'; 18 field stream => ''; 13 19 field ext => ''; 14 field height => 20; 15 field width => 80; 20 field clean => 0; 21 field vroom => 0; 22 field digits => 0; 23 field config => { 24 title => 'Unnamed Presentation', 25 height => 24, 26 width => 80, 27 list_indent => 10, 28 }; 16 29 17 30 sub new { … … 22 35 my $self = shift; 23 36 37 local @ARGV = @_; 38 24 39 $self->getOptions; 40 25 41 $self->cleanUp; 42 return if $self->clean; 43 44 $self->makeAll; 45 46 $self->startUp if $self->vroom; 26 47 } 27 48 28 49 sub getOptions { 29 50 my $self = shift; 30 my $height = $self->height;31 my $width = $self->width;32 51 GetOptions( 33 "height=i" => \$height, 34 "width=i" => \$width, 35 ); 36 $self->height($height); 37 $self->width($width); 52 "clean" => \$self->{clean}, 53 "input=s" => \$self->{input}, 54 "vroom" => \$self->{vroom}, 55 ) or die $self->usage; 56 57 do { delete $self->{$_} unless defined $self->{$_} } 58 for qw(clean input vroom); 59 60 my @files = <*.vroom>; 61 62 $self->input($files[0]) 63 if @files; 38 64 } 39 65 40 66 sub cleanUp { 41 my $self = shift; 42 if (-e $self->dir) { 43 $_->unlink for io($self->dir)->All_Files; 44 } 67 unlink(glob "0*"); 68 unlink(".vimrc"); 69 } 70 71 sub makeAll { 72 my $self = shift; 73 $self->getInput; 74 $self->buildSlides; 75 $self->writeVimrc; 45 76 } 46 77 47 78 sub getInput { 48 79 my $self = shift; 49 my $ input = io('-')->all || io('vroom')->all50 or croak "No input provided. Make a file called ' vroom'";51 $self-> input($input);80 my $stream = io($self->input)->all 81 or croak "No input provided. Make a file called 'slides.vroom'"; 82 $self->stream($stream); 52 83 } 53 84 54 85 sub buildSlides { 55 86 my $self = shift; 56 my @raw_slides = grep length, split /^----\n/m, $self->input; 57 $self->digits = int(log(@raw_slides)/log(10)) + 2; 87 my @split = grep length, split /^(----\ *.*)\n/m, $self->stream; 88 push @split, '----' if $split[0] =~ /\n/; 89 my (@raw_configs, @raw_slides); 90 while (@split) { 91 my ($config, $slide) = splice(@split, 0, 2); 92 $config =~ s/^----\s*(.*?)\s*$/$1/; 93 push @raw_configs, $config; 94 push @raw_slides, $slide; 95 } 96 $self->{digits} = int(log(@raw_slides)/log(10)) + 2; 58 97 59 98 my $number = 1; 60 99 61 100 for my $raw_slide (@raw_slides) { 62 $self->ext(''); 63 if ($raw_slide =~ s/^!(.*)\n//) { 64 $raw_slide = setOptions($raw_slide, $1) 65 or next; 66 } 67 $raw_slide = padVertical($raw_slide); 101 my $config = $self->parseSlideConfig(shift @raw_configs); 102 next if $config->{skip}; 103 104 $raw_slide = $self->applyOptions($raw_slide, $config) 105 or next; 106 107 $raw_slide = $self->padVertical($raw_slide); 108 68 109 my @slides; 69 110 my $slide = ''; … … 77 118 my $suffix = 'a'; 78 119 for (my $i = 1; $i <= @slides; $i++) { 79 my $slide = padFullScreen($slides[$i - 1]);120 my $slide = $self->padFullScreen($slides[$i - 1]); 80 121 $slide =~ s{^\ *==\ *(.*?)\ *$} 81 {' ' x (($self->width - length($1)) / 2) . $1}gem; 82 io("$base_name$suffix" . $self->ext)->print($slide); 83 $suffix++; 122 {' ' x (($self->config->{width} - length($1)) / 2) . $1}gem; 123 my $suf = $suffix++; 124 $suf = $suf eq 'a' 125 ? '' 126 : $i == @slides 127 ? 'z' 128 : $suf; 129 io("$base_name$suf" . $self->ext)->print($slide); 84 130 } 85 131 } 86 132 } 87 133 134 sub formatNumber { 135 my $self = shift; 136 my $number = shift; 137 my $digits = $self->digits; 138 return sprintf "%0${digits}d", $number; 139 } 140 141 sub parseSlideConfig { 142 my $self = shift; 143 my $string = shift; 144 my $config = {}; 145 for my $option (split /\s*,\s*/, $string) { 146 $config->{$1} = 1 147 if $option =~ /^(config|skip|center|perl|yaml)$/; 148 $config->{indent} = $1 149 if $option =~ /i(\d+)/; 150 } 151 return $config; 152 } 153 154 sub applyOptions { 155 my $self = shift; 156 my ($slide, $config) = @_; 157 158 $config = { 159 %{$self->config}, 160 %$config, 161 }; 162 163 $self->ext(""); 164 if ($config->{config}) { 165 $config = { 166 %{$self->config}, 167 %{(YAML::XS::Load($slide))}, 168 }; 169 $self->config($config); 170 return ''; 171 } 172 if ($config->{center}) { 173 $slide =~ s{^(\+?)\ *(.*?)\ *$} 174 {$1 . ' ' x (($self->config->{width} - length($2)) / 2) . $2}gem; 175 $slide =~ s{^\s*$}{}gm; 176 } 177 if (defined $config->{indent}) { 178 my $indent = $config->{indent}; 179 $slide =~ s{^(\+?)}{$1 . ' ' x $indent}gem; 180 } 181 elsif ($slide =~ /^\+?\*/m) { 182 my $indent = $config->{list_indent}; 183 $slide =~ s{^(\+?)}{$1 . ' ' x $indent}gem; 184 } 185 if ($config->{perl}) { 186 $self->ext(".pl"); 187 } 188 if ($config->{yaml}) { 189 $self->ext(".yaml"); 190 } 191 return $slide; 192 } 193 194 sub padVertical { 195 my $self = shift; 196 my $slide = shift; 197 $slide =~ s/\A\s*\n//; 198 $slide =~ s/\n\s*\z//; 199 my @lines = split /\n/, $slide; 200 my $lines = @lines; 201 my $before = int(($self->config->{height} - $lines) / 2) - 1; 202 return "\n" x $before . $slide; 203 } 204 205 sub padFullScreen { 206 my $self = shift; 207 my $slide = shift; 208 chomp $slide; 209 my @lines = split /\n/, $slide; 210 my $lines = @lines; 211 my $after = $self->config->{height} - $lines + 1; 212 return $slide . "\n" x $after; 213 } 214 88 215 sub writeVimrc { 89 216 my $self = shift; 217 my $title = "%f " . $self->config->{title}; 218 $title =~ s/\s/_/g; 90 219 io(".vimrc")->print(<<"..."); 91 220 map <SPACE> :n<CR>:<CR>gg … … 94 223 map Q :q!<CR> 95 224 set laststatus=2 96 set statusline=$ self->{title}225 set statusline=$title 97 226 ... 98 227 } 99 228 100 sub writeMakefile { 101 my $self = shift; 102 io("Makefile")->print(<<'...'); 103 trouble love tracks: 104 vim [a-z]* 105 ... 106 } 107 108 sub printFinished { 109 print "Your slide show is ready... vroom vroom!!!\n"; 110 } 111 112 sub setOptions { 113 my $self = shift; 114 my ($slide, $options) = @_; 115 my @options = split /,/, $options; 116 my $config = {}; 117 for my $option (@options) { 118 if ($option eq 'config') { 119 $config = { %$config, %{(YAML::XS::Load($slide))} }; 120 return ''; 121 } 122 if ($option =~ /^c(enter)?$/) { 123 $slide =~ s{^(\+?)\ *(.*?)\ *$} 124 {$1 . ' ' x ((78 - length($2)) / 2) . $2}gem; 125 $slide =~ s{^\s*$}{}gm; 126 } 127 if ($option =~ /^i(\d+)$/) { 128 my $indent = $1; 129 $slide =~ s{^(\+?)}{$1 . ' ' x $indent}gem; 130 } 131 if ($option =~ /^(pl|js|rb|yaml)$/) { 132 $self->ext(".$1"); 133 } 134 } 135 return $slide; 136 } 137 138 sub padVertical { 139 my $self = shift; 140 my $slide = shift; 141 $slide =~ s/\A\s*\n//; 142 $slide =~ s/\n\s*\z//; 143 my @lines = split /\n/, $slide; 144 my $lines = @lines; 145 my $before = int(($self->height - $lines) / 2) - 1; 146 return "\n" x $before . $slide; 147 } 148 149 sub padFullScreen { 150 my $self = shift; 151 my $slide = shift; 152 chomp $slide; 153 my @lines = split /\n/, $slide; 154 my $lines = @lines; 155 my $after = $self->height - $lines + 1; 156 return $slide . "\n" x $after; 229 sub startUp { 230 exec "vim 0*"; 157 231 } 158 232 … … 163 237 =head1 SYNOPSIS 164 238 165 > vim vroom# Write Some Slides239 > vim slides.vroom # Write Some Slides 166 240 > vroom --vroom # Show Your Slides 167 241 … … 190 264 =head1 COMMAND USAGE 191 265 192 266 Vroom has a few command line options: 267 268 =over 269 270 =item vroom 271 272 Just running vroom will compiles 'slides.vroom' into slide files. 273 274 =item vroom --vroom 275 276 Compile and start vim show. 277 278 =item vroom --clean 279 280 Clean up all the compiled output files. 281 282 =back 193 283 194 284 =head1 INPUT FORMAT 195 285 196 286 Here is an example slides.vroom: 287 288 ---- config 289 title: My Spiffy Slideshow 290 height: 84 291 width: 20 292 ---- center 293 My Presentation 294 295 by Ingy 296 ---- 297 == Stuff I care about: 298 299 * Foo 300 +* Bar 301 +* Baz 302 ---- perl 303 use Vroom; 304 305 print "Hello World"; 306 ---- center 307 THE END 197 308 198 309 =head1 KEY MAPPINGS trunk/src/ingy/Vroom/vroom
r364 r366 2 2 3 3 use Vroom; 4 Vroom->new->run ;4 Vroom->new->run(@ARGV);
