changeset 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
files .hgignore lib/Slideshow/Util.pm lib/Slideshow/cpanfile slideshow.pl
diffstat 4 files changed, 98 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Jan 24 23:32:25 2018 +0900
+++ b/.hgignore	Thu Jan 25 16:59:37 2018 +0900
@@ -21,4 +21,6 @@
 themes/**/*.ttf
 themes/**/*.otf
 themes/**/*.woff
+
 lib/Slideshow/local/*
+.vstags
--- a/lib/Slideshow/Util.pm	Wed Jan 24 23:32:25 2018 +0900
+++ b/lib/Slideshow/Util.pm	Thu Jan 25 16:59:37 2018 +0900
@@ -6,18 +6,51 @@
 use Carp qw/ croak /;
 
 use base 'Exporter';
-use FindBin;
-use lib "$FindBin::Bin/local/lib/perl5";
 
 use Time::Piece;
 use feature 'say';
 use Path::Tiny;
+use File::chdir;
+use Capture::Tiny qw/capture/;
 
 our @EXPORT = qw/
+    getopts
     new
     set_template
+    build_recently 
+    build_pinpoint 
 /;
 
+sub getopts {
+    my ($arg,$path)  = @_;
+
+    unless (defined $arg){
+        return { help => 1};
+    }
+
+    if ($arg eq "new") {
+        return {new => 1};
+    } elsif ( $arg eq "upload") {
+       upload();
+       exit;
+
+    } elsif ( $arg eq "build") {
+
+        if(defined $path){
+            return { build_point=> $path};
+        } else {
+            return { build => "recent"};
+        }
+
+    } elsif ( $arg eq "upload"){
+        return { upload => 1};
+
+    } else {
+        return { help => 1};
+    }
+
+}
+
 sub set_template {
     my $template = shift;
     my $file  = path($template);
@@ -34,18 +67,50 @@
     $template->copy($slide);
 }
 
-sub make_recently {
 
+sub build_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]};
+
+    _build($recently);
 }
 
-sub make_pinpoint {
+sub build_pinpoint {
+    my $target = shift;
+
+    my $target_path = path($target);
+
+    my $dir = $target_path->dirname;
+    my $slide = $target_path->basename;
+
+   _build($dir,$slide); 
+}
+
 
+sub _build {
+    my ($dir,$target) = @_;
+    use Capture::Tiny;
+
+    $target //= 'slide.md';
+
+
+    local $CWD = $dir;
+
+    my ($stdout,$stderr,$exit) = capture {
+        system(" slideshow build ${target} -t s6cr");
+    };
+
+    if ($stderr){
+        croak "Perl can't build....";
+    }
 }
 
 
 sub upload {
 
-    use Capture::Tiny;
     my ($stdout,$stderr,$exit) = capture {
         system("hg addremove");
         system("hg add");
--- a/lib/Slideshow/cpanfile	Wed Jan 24 23:32:25 2018 +0900
+++ b/lib/Slideshow/cpanfile	Thu Jan 25 16:59:37 2018 +0900
@@ -1,4 +1,6 @@
 requires 'Path::Tiny';
 requires 'YAML::XS';
+requires 'File::chdir';
+requires 'DDP';
 requires 'perl', '5.008001';
 
--- a/slideshow.pl	Wed Jan 24 23:32:25 2018 +0900
+++ b/slideshow.pl	Thu Jan 25 16:59:37 2018 +0900
@@ -3,15 +3,33 @@
 use warnings;
 use utf8;
 
+use lib "lib","lib/Slideshow/local/lib/perl5";
 
-use lib 'lib';
 use Slideshow::Util;
-use Getopt::Long;
+use feature 'say';
+
+my $flags = getopts(@ARGV);
+
+help() if $flags->{help};
+
 
-my $new_flag;
+if ($flags->{new}){
+    new(set_template('lib/template.md'),"slides");
+} elsif ($flags->{build}) {
+   build_recently("slides");
+} else {
+    build_pinpoint($flags->{build_point});
+}
 
-GetOptions("new" => \$new_flag) or die("Error at new flags");
 
-if ($new_flag){
-    new(set_template('lib/template.md'),"slides");
+sub help {
+    say 'slider [%options]';
 }
+
+
+__END__
+
+my $flags = getopts(@ARGV);
+
+if ($flags->{new}){
+