diff options
Diffstat (limited to 'bin/mkdocs-prep.pl')
-rwxr-xr-x | bin/mkdocs-prep.pl | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/mkdocs-prep.pl b/bin/mkdocs-prep.pl index efa71fb..96bba69 100755 --- a/bin/mkdocs-prep.pl +++ b/bin/mkdocs-prep.pl @@ -8,6 +8,7 @@ use List::Util qw(pairs); use Config::Tiny; use Path::Tiny; use Text::Hogan::Compiler; +use IO::Prompter; =head1 NAME @@ -35,6 +36,10 @@ wrapped with double curly brackets. Template tokens are gathered from external config file F<site.mk>, where each line lists a token, an equals sign, and replacement string. +Inline defined tokens not declared in F<site.mk> will be prompted for. +if a value is provided it will be used, and also saved in F<site.mk>. +If no value is provided then inline default string is used. + Each token in the document, wrapped with double curly brackets {{like_this}}, is replaced (including brackets) with corresponding string. @@ -42,9 +47,11 @@ is replaced (including brackets) with corresponding string. =cut my ( $infile, $outfile ) = @ARGV; +@ARGV = undef; my $config = Config::Tiny->new; $config = Config::Tiny->read( 'site.mk', 'utf8' ); +my $config_has_changed; my $content = path($infile)->slurp_utf8; @@ -55,6 +62,13 @@ while ( $section =~ /^(\w+)\h*:\h*(\w+(?:\h+\w+)*)/mg ) { my $token = $1; my $string = $2; + unless ( exists $config->{_}->{$1} ) { + $_ = prompt "Which string should replace token '$token'?"; + next unless $_; + $config->{_}->{$1} = $_; + $config_has_changed++; + } + $content =~ s/\Q$string\E/{{$token}}/g; }; @@ -64,4 +78,7 @@ my $template = $compiler->compile($content); path($outfile)->spew_utf8( $template->render( $config->{_} ) ); +$config->write( 'site.mk', 'utf8' ) + if $config_has_changed; + 1; |