comparison lib/Slideshow/Util.pm @ 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 0b502eb897cc
children 80767afba59c
comparison
equal deleted inserted replaced
12:46b1a85d810b 13:967fe50f1ef4
17 getopts 17 getopts
18 new 18 new
19 set_template 19 set_template
20 build_recently 20 build_recently
21 build_pinpoint 21 build_pinpoint
22 open_slide
23 edit_slide
22 /; 24 /;
23 25
24 sub getopts { 26 sub getopts {
25 my ($arg,$path) = @_; 27 my ($arg,$path) = @_;
26 28
28 return { help => 1}; 30 return { help => 1};
29 } 31 }
30 32
31 if ($arg eq "new") { 33 if ($arg eq "new") {
32 return {new => 1}; 34 return {new => 1};
35
33 } elsif ( $arg eq "upload") { 36 } elsif ( $arg eq "upload") {
34 upload(); 37 upload();
35 exit; 38 exit;
36 39
37 } elsif ( $arg eq "build") { 40 } elsif ( $arg eq "build") {
40 return { build_point=> $path}; 43 return { build_point=> $path};
41 } else { 44 } else {
42 return { build => "recent"}; 45 return { build => "recent"};
43 } 46 }
44 47
45 } elsif ( $arg eq "upload"){ 48
46 return { upload => 1}; 49 } elsif ( $arg eq "open"){
50 return { open => 1};
51
52 } elsif ( $arg eq "edit"){
53 return { edit=> 1};
47 54
48 } else { 55 } else {
49 return { help => 1}; 56 return { help => 1};
50 } 57 }
51 58
65 # ex... 2018/02/14 72 # ex... 2018/02/14
66 my $slide = $root_dir->child($t->strftime('%Y%m%d'). '/'.'slide.md')->touchpath; 73 my $slide = $root_dir->child($t->strftime('%Y%m%d'). '/'.'slide.md')->touchpath;
67 $template->copy($slide); 74 $template->copy($slide);
68 } 75 }
69 76
70 77 sub _search_recently {
71 sub build_recently {
72 my ($root_directory_name) = @_; 78 my ($root_directory_name) = @_;
73 my $root_dir = path($root_directory_name); 79 my $root_dir = path($root_directory_name);
74 my $t = localtime; 80 my $t = localtime;
75 81
76 my $recently = shift @{[sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]}; 82 my $recently = shift @{[sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]};
77 83
84 return $recently;
85 }
86
87
88
89 sub build_recently {
90 my $recently = _search_recently(shift);
78 _build($recently); 91 _build($recently);
79 } 92 }
80 93
81 sub build_pinpoint { 94 sub build_pinpoint {
82 my $target = shift; 95 my $target = shift;
87 my $slide = $target_path->basename; 100 my $slide = $target_path->basename;
88 101
89 _build($dir,$slide); 102 _build($dir,$slide);
90 } 103 }
91 104
105 sub edit_slide {
106 my $recently = _search_recently(shift);
107 my $target = $recently->child('slide.md');
108 exec $ENV{EDITOR}, ($target->realpath);
109 }
110
111 sub open_slide {
112 my $recently = _search_recently(shift);
113 my $target = $recently->child('slide.html');
114
115 if ( $target->realpath){
116 system "open", ($target->realpath);
117 } else {
118 say "didn't slide.html";
119 }
120 }
92 121
93 sub _build { 122 sub _build {
94 my ($dir,$target) = @_; 123 my ($dir,$target) = @_;
95 use Capture::Tiny; 124 use Capture::Tiny;
96 125