Mercurial > hg > Members > anatofuz > slides
comparison lib/Slideshow/Util.pm @ 6:e35e9779078a
auto-Update generated slides by script
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 25 Jan 2018 16:59:37 +0900 |
parents | e762bb571a45 |
children | 7d3faa099bc6 |
comparison
equal
deleted
inserted
replaced
5:e762bb571a45 | 6:e35e9779078a |
---|---|
4 use utf8; | 4 use utf8; |
5 | 5 |
6 use Carp qw/ croak /; | 6 use Carp qw/ croak /; |
7 | 7 |
8 use base 'Exporter'; | 8 use base 'Exporter'; |
9 use FindBin; | |
10 use lib "$FindBin::Bin/local/lib/perl5"; | |
11 | 9 |
12 use Time::Piece; | 10 use Time::Piece; |
13 use feature 'say'; | 11 use feature 'say'; |
14 use Path::Tiny; | 12 use Path::Tiny; |
13 use File::chdir; | |
14 use Capture::Tiny qw/capture/; | |
15 | 15 |
16 our @EXPORT = qw/ | 16 our @EXPORT = qw/ |
17 getopts | |
17 new | 18 new |
18 set_template | 19 set_template |
20 build_recently | |
21 build_pinpoint | |
19 /; | 22 /; |
23 | |
24 sub getopts { | |
25 my ($arg,$path) = @_; | |
26 | |
27 unless (defined $arg){ | |
28 return { help => 1}; | |
29 } | |
30 | |
31 if ($arg eq "new") { | |
32 return {new => 1}; | |
33 } elsif ( $arg eq "upload") { | |
34 upload(); | |
35 exit; | |
36 | |
37 } elsif ( $arg eq "build") { | |
38 | |
39 if(defined $path){ | |
40 return { build_point=> $path}; | |
41 } else { | |
42 return { build => "recent"}; | |
43 } | |
44 | |
45 } elsif ( $arg eq "upload"){ | |
46 return { upload => 1}; | |
47 | |
48 } else { | |
49 return { help => 1}; | |
50 } | |
51 | |
52 } | |
20 | 53 |
21 sub set_template { | 54 sub set_template { |
22 my $template = shift; | 55 my $template = shift; |
23 my $file = path($template); | 56 my $file = path($template); |
24 return $file; | 57 return $file; |
32 # ex... 2018/02/14 | 65 # ex... 2018/02/14 |
33 my $slide = $root_dir->child($t->strftime('%Y%m%d'). '/'.'slide.md')->touchpath; | 66 my $slide = $root_dir->child($t->strftime('%Y%m%d'). '/'.'slide.md')->touchpath; |
34 $template->copy($slide); | 67 $template->copy($slide); |
35 } | 68 } |
36 | 69 |
37 sub make_recently { | |
38 | 70 |
71 sub build_recently { | |
72 my ($root_directory_name) = @_; | |
73 my $root_dir = path($root_directory_name); | |
74 my $t = localtime; | |
75 | |
76 my $recently = shift @{[sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]}; | |
77 | |
78 _build($recently); | |
39 } | 79 } |
40 | 80 |
41 sub make_pinpoint { | 81 sub build_pinpoint { |
82 my $target = shift; | |
42 | 83 |
84 my $target_path = path($target); | |
85 | |
86 my $dir = $target_path->dirname; | |
87 my $slide = $target_path->basename; | |
88 | |
89 _build($dir,$slide); | |
90 } | |
91 | |
92 | |
93 sub _build { | |
94 my ($dir,$target) = @_; | |
95 use Capture::Tiny; | |
96 | |
97 $target //= 'slide.md'; | |
98 | |
99 | |
100 local $CWD = $dir; | |
101 | |
102 my ($stdout,$stderr,$exit) = capture { | |
103 system(" slideshow build ${target} -t s6cr"); | |
104 }; | |
105 | |
106 if ($stderr){ | |
107 croak "Perl can't build...."; | |
108 } | |
43 } | 109 } |
44 | 110 |
45 | 111 |
46 sub upload { | 112 sub upload { |
47 | 113 |
48 use Capture::Tiny; | |
49 my ($stdout,$stderr,$exit) = capture { | 114 my ($stdout,$stderr,$exit) = capture { |
50 system("hg addremove"); | 115 system("hg addremove"); |
51 system("hg add"); | 116 system("hg add"); |
52 }; | 117 }; |
53 | 118 |