| 1 | package Vroom::Vroom::Link; | ||
| 2 | BEGIN { | ||
| 3 | $Vroom::Vroom::Link::VERSION = '0.06'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use parent qw/Vroom/; | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use IO::All; | ||
| 11 | |||
| 12 | sub makeHTML { | ||
| 13 | my $self = shift; | ||
| 14 | require Template::Toolkit::Simple; | ||
| 15 | $self->cleanAll; | ||
| 16 | $self->makeSlides; | ||
| 17 | io('html')->mkdir; | ||
| 18 | my @slides = glob('0*'); | ||
| 19 | for (my $i = 0; $i < @slides; $i++) { | ||
| 20 | my $slide = $slides[$i]; | ||
| 21 | my $prev = ($i > 0) ? $slides[$i - 1] : ''; | ||
| 22 | my $next = ($i + 1 < @slides) ? $slides[$i + 1] : ''; | ||
| 23 | my $text = io($slide)->all; | ||
| 24 | my $title = $text; | ||
| 25 | my @textwithLinks = split /(http:\/\/\S+)/, $text; | ||
| 26 | $text = Template::Toolkit::Simple->new()->render( | ||
| 27 | $self->slideTemplate, | ||
| 28 | { | ||
| 29 | title => $self->config->{title} . " $slide", | ||
| 30 | prev => $prev, | ||
| 31 | next => $next, | ||
| 32 | content => \@textwithLinks, | ||
| 33 | } | ||
| 34 | ); | ||
| 35 | io("html/$slide.html")->print($text); | ||
| 36 | } | ||
| 37 | |||
| 38 | my $index = []; | ||
| 39 | for (my $i = 0; $i < @slides; $i++) { | ||
| 40 | my $slide = $slides[$i]; | ||
| 41 | next if $slide =~ /^\d+[a-z]/; | ||
| 42 | my $title = io($slide)->all; | ||
| 43 | $title =~ s/.*?((?-s:\S.*)).*/$1/s; | ||
| 44 | push @$index, [$slide, $title]; | ||
| 45 | } | ||
| 46 | |||
| 47 | io("html/index.html")->print( | ||
| 48 | Template::Toolkit::Simple->new()->render( | ||
| 49 | $self->indexTemplate, | ||
| 50 | { | ||
| 51 | config => $self->config, | ||
| 52 | index => $index, | ||
| 53 | } | ||
| 54 | ) | ||
| 55 | ); | ||
| 56 | $self->cleanUp; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub slideTemplate { | ||
| 60 | \ <<'...' | ||
| 61 | <html> | ||
| 62 | <head> | ||
| 63 | <title>[% title | html %]</title> | ||
| 64 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
| 65 | <script> | ||
| 66 | function navigate(e) { | ||
| 67 | var keynum = (window.event) // IE | ||
| 68 | ? e.keyCode | ||
| 69 | : e.which; | ||
| 70 | if (keynum == 8) { | ||
| 71 | [% IF prev -%] | ||
| 72 | window.location = "[% prev %]" + ".html"; | ||
| 73 | [% END -%] | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | [% IF next -%] | ||
| 77 | if (keynum == 13 || keynum == 32) { | ||
| 78 | window.location = "[% next %]" + ".html"; | ||
| 79 | return false; | ||
| 80 | } | ||
| 81 | [% END -%] | ||
| 82 | if (keynum == 73 || keynum == 105) { | ||
| 83 | window.location = "index.html"; | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | return true; | ||
| 87 | } | ||
| 88 | </script> | ||
| 89 | </head> | ||
| 90 | <body onkeypress="return navigate(event)"> | ||
| 91 | <pre> | ||
| 92 | [%- FOREACH string IN content -%] | ||
| 93 | [%- IF string.match('(http://\S+)') -%] | ||
| 94 | <a href="[% string %]">[% string %]</a> | ||
| 95 | [%- ELSE -%] | ||
| 96 | [%- string | html -%] | ||
| 97 | [%- END -%] | ||
| 98 | [%- END -%] | ||
| 99 | </pre> | ||
| 100 | </body> | ||
| 101 | ... | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | =encoding utf8 | ||
| 106 | |||
| 107 | =head1 NAME | ||
| 108 | |||
| 109 | Vroom::Vroom::Link - Make Vroom::Vroom HTML links clickable | ||
| 110 | |||
| 111 | =head1 SYNOPSIS | ||
| 112 | |||
| 113 | vink --html | ||
| 114 | |||
| 115 | =head1 DESCRIPTION | ||
| 116 | |||
| 117 | Vroom is ingy döt net's slides engine, running in vim. | ||
| 118 | |||
| 119 | For extra oomph, clickable links when publishing the slides to HTML. | ||
| 120 | |||
| 121 | =head1 SEE | ||
| 122 | |||
| 123 | L<http://search.cpan.org/perldoc?Vroom::Vroom> | ||
| 124 | |||
| 125 | =head1 AUTHOR | ||
| 126 | |||
| 127 | Dr Bean <drbean at (a) cpan dot (.) org> | ||
| 128 | |||
| 129 | =head1 COPYRIGHT | ||
| 130 | |||
| 131 | Copyright (c) 2010, Dr Bean | ||
| 132 | |||
| 133 | This program is free software; you can redistribute it and/or modify it | ||
| 134 | under the same terms as Perl itself. | ||
| 135 | |||
| 136 | See http://www.perl.com/perl/misc/Artistic.html | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | 1; |