Created
May 22, 2017 14:57
-
-
Save mudler/807f8f71a88cace91a8fbbbd5faf01f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# PODNAME: generate-md | |
use lib './lib'; | |
use Mojo::Util qw(spurt); | |
use Pod::POM; | |
use Pod::POM::View::Pod; | |
use Pod::Markdown::Github; | |
use File::Find; | |
use constant SUBMODULE_DIR => "../docs/"; | |
use constant LIBS_DIR => "./lib/"; | |
use constant BASE_URL => "example.com"; | |
use feature 'say'; | |
use DateTime; | |
use constant DATE => DateTime->now->hms . " " . DateTime->now->dmy('/'); | |
use feature 'say'; | |
sub modulepod2markdown { | |
my $pod = Pod::POM->new(); | |
my $pom = $pod->parse_file( $_[0] ) || die $pod->error(); | |
my $markdown; | |
my $parser = Pod::Markdown::Github->new( perldoc_url_prefix => | |
BASE_URL ); | |
$parser->output_string( \$markdown ); | |
$parser->parse_string_document( Pod::POM::View::Pod->print($pom) ); | |
spurt( $markdown, SUBMODULE_DIR . $_[1] ) if $markdown =~ /[a-zA-Z]/g; | |
} | |
sub pull { | |
my $b = shift; | |
system("git pull"); | |
system("git merge origin " . $b ); | |
system("git submodule update"); | |
} | |
sub commit { | |
chdir(SUBMODULE_DIR); | |
system("git checkout master"); | |
system("git add --all ."); | |
system( "git commit -am 'Documentation automatic snapshot - " | |
. DATE | |
. "'; git push -u origin master" ); | |
chdir("../"); | |
system( | |
"git commit -am 'Documentation automatic snapshot - " . DATE . "'" ); | |
} | |
pull( $ARGV[0] ) if $ARGV[0]; | |
chdir(LIBS_DIR); | |
find( | |
{ wanted => sub { | |
my $file = $_; | |
next if ( !/\.pm$/ ); | |
s/\.\///; | |
s/\.pm/\.md/; | |
modulepod2markdown( $file, s/\//::/reg ); | |
}, | |
no_chdir => 1 | |
}, | |
"." | |
); | |
commit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment