# HG changeset patch # User Takahiro SHIMIZU # Date 1516943764 -32400 # Node ID 967fe50f1ef4e6f6a922192c3b5c874d9274e2d3 # Parent 46b1a85d810bcc3d6c6685ff98e9012d27559344 add open and edit mode diff -r 46b1a85d810b -r 967fe50f1ef4 lib/Slideshow/Util.pm --- a/lib/Slideshow/Util.pm Thu Jan 25 22:18:40 2018 +0900 +++ b/lib/Slideshow/Util.pm Fri Jan 26 14:16:04 2018 +0900 @@ -19,6 +19,8 @@ set_template build_recently build_pinpoint + open_slide + edit_slide /; sub getopts { @@ -30,6 +32,7 @@ if ($arg eq "new") { return {new => 1}; + } elsif ( $arg eq "upload") { upload(); exit; @@ -42,8 +45,12 @@ return { build => "recent"}; } - } elsif ( $arg eq "upload"){ - return { upload => 1}; + + } elsif ( $arg eq "open"){ + return { open => 1}; + + } elsif ( $arg eq "edit"){ + return { edit=> 1}; } else { return { help => 1}; @@ -67,14 +74,20 @@ $template->copy($slide); } - -sub build_recently { +sub _search_recently { my ($root_directory_name) = @_; my $root_dir = path($root_directory_name); my $t = localtime; my $recently = shift @{[sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]}; + return $recently; +} + + + +sub build_recently { + my $recently = _search_recently(shift); _build($recently); } @@ -89,6 +102,22 @@ _build($dir,$slide); } +sub edit_slide { + my $recently = _search_recently(shift); + my $target = $recently->child('slide.md'); + exec $ENV{EDITOR}, ($target->realpath); +} + +sub open_slide { + my $recently = _search_recently(shift); + my $target = $recently->child('slide.html'); + + if ( $target->realpath){ + system "open", ($target->realpath); + } else { + say "didn't slide.html"; + } +} sub _build { my ($dir,$target) = @_; diff -r 46b1a85d810b -r 967fe50f1ef4 slide-cr --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slide-cr Fri Jan 26 14:16:04 2018 +0900 @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; + +use lib "lib","lib/Slideshow/local/lib/perl5"; + +use Slideshow::Util; +use feature 'say'; + +my $flags = getopts(@ARGV); + +help() if $flags->{help}; + + +if ($flags->{new}){ + new(set_template('lib/template.md'),"slides"); +} elsif ($flags->{build}) { + build_recently("slides"); +} elsif ( $flags->{open}) { + open_slide("slides"); +} elsif ( $flags->{edit}) { + edit_slide("slides"); +} else { + build_pinpoint($flags->{build_point}); +} + + +sub help { + say 'slider [%options]'; +} + + +__END__ \ No newline at end of file diff -r 46b1a85d810b -r 967fe50f1ef4 slide-cr.pl --- a/slide-cr.pl Thu Jan 25 22:18:40 2018 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use utf8; - -use lib "lib","lib/Slideshow/local/lib/perl5"; - -use Slideshow::Util; -use feature 'say'; - -my $flags = getopts(@ARGV); - -help() if $flags->{help}; - - -if ($flags->{new}){ - new(set_template('lib/template.md'),"slides"); -} elsif ($flags->{build}) { - build_recently("slides"); -} else { - build_pinpoint($flags->{build_point}); -} - - -sub help { - say 'slider [%options]'; -} - - -__END__ \ No newline at end of file