changeset 13:967fe50f1ef4

add open and edit mode
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 26 Jan 2018 14:16:04 +0900
parents 46b1a85d810b
children deecd8254ba8
files lib/Slideshow/Util.pm slide-cr slide-cr.pl
diffstat 3 files changed, 67 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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) = @_;
--- /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
--- 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