| 1 | #!/usr/bin/env perl | ||
| 2 | # Original: https://github.com/defunkt/mustache/blob/master/bin/mustache | ||
| 3 | |||
| 4 | # PODNAME: mustache.pl | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use autodie; | ||
| 9 | |||
| 10 | use Template::Mustache; | ||
| 11 | use YAML::XS qw/ Load /; | ||
| 12 | |||
| 13 | my ($self, $args) = @_; | ||
| 14 | my @args = $args ? @$args : @ARGV; | ||
| 15 | my $cli_opt = shift @args || '-h'; | ||
| 16 | |||
| 17 | if ($cli_opt eq "-h" and -t STDIN) { | ||
| 18 | print "Usage: mustache FILE ...\n"; | ||
| 19 | print "`perldoc mustache` for more usage info.\n"; | ||
| 20 | } | ||
| 21 | else { | ||
| 22 | my $doc = join('', <>); | ||
| 23 | if($doc =~ /^(\s*---(.+)---\s*)/isg) { | ||
| 24 | my $yml = $2; | ||
| 25 | $doc =~ s/\Q$1\E//g; # remove YAML data block, quote metachars | ||
| 26 | $yml =~ s/^\s+|\s+$//g; # trim whitespace | ||
| 27 | $yml = Load($yml); | ||
| 28 | print Template::Mustache->render($doc, $yml); | ||
| 29 | } | ||
| 30 | else { | ||
| 31 | print Template::Mustache->render($doc); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | __END__ | ||
| 36 | |||
| 37 | =pod | ||
| 38 | |||
| 39 | =encoding UTF-8 | ||
| 40 | |||
| 41 | =head1 NAME | ||
| 42 | |||
| 43 | mustache.pl | ||
| 44 | |||
| 45 | =head1 VERSION | ||
| 46 | |||
| 47 | version 1.3.3 | ||
| 48 | |||
| 49 | =head1 NAME | ||
| 50 | |||
| 51 | mustache.pl - Command line frontend for mustache logic-less templates. | ||
| 52 | |||
| 53 | Usage: mustache.pl FILE ... | ||
| 54 | |||
| 55 | See mustache(1) or http://mustache.github.io/mustache.1.html for more details. | ||
| 56 | |||
| 57 | =head1 RECIPES | ||
| 58 | |||
| 59 | Examples: | ||
| 60 | |||
| 61 | $ mustache.pl data.yml template.mustache | ||
| 62 | $ cat data.yml | mustache.pl - template.mustache | ||
| 63 | $ cat data.yml template.mustache | mustache.pl | ||
| 64 | |||
| 65 | =head1 AUTHORS | ||
| 66 | |||
| 67 | =over 4 | ||
| 68 | |||
| 69 | =item * | ||
| 70 | |||
| 71 | Pieter van de Bruggen <pvande@cpan.org> | ||
| 72 | |||
| 73 | =item * | ||
| 74 | |||
| 75 | Yanick Champoux <yanick@cpan.org> | ||
| 76 | |||
| 77 | =item * | ||
| 78 | |||
| 79 | Ricardo Signes <rjbs@cpan.org> | ||
| 80 | |||
| 81 | =back | ||
| 82 | |||
| 83 | =head1 COPYRIGHT AND LICENSE | ||
| 84 | |||
| 85 | This software is copyright (c) 2019, 2018, 2017, 2016, 2015, 2011 by Pieter van de Bruggen. | ||
| 86 | |||
| 87 | This is free software; you can redistribute it and/or modify it under | ||
| 88 | the same terms as the Perl 5 programming language system itself. | ||
| 89 | |||
| 90 | =cut |