bluto

Release package and announcement generator
Info | Log | Files | Refs | README | LICENSE

Announce.pm (2041B)


      1 package Bluto::Announce;
      2 
      3 use Template;
      4 
      5 use Bluto::Log qw/error info debug warn trace/;
      6 
      7 my $pos;
      8 
      9 sub _adapt_headings {
     10 	my $f;
     11 	my $last = undef;
     12 	my $this = undef;
     13 	my $r = '';
     14 	my $v = shift;
     15 
     16 	open(my $f, '<', \$v);
     17 	while (<$f>) {
     18 		$this = undef;
     19 		if (defined $last) {
     20 			if ($_ =~ /^===/) {
     21 				$this = '=' x (length($last) - 1);
     22 			} elsif ($_ =~ /^---/) {
     23 				if ($last !~ /^\W+$/) {
     24 					$this = '-' x (length($last) - 1);
     25 				} else {
     26 					$this = $_;
     27 				}
     28 			}
     29 
     30 		}
     31 		if (!defined $this) {
     32 			$this = $_;
     33 		}
     34 		$r .= $this;
     35 		$last = $_;
     36 	}
     37 	close($f);
     38 
     39 	return $r;
     40 }
     41 
     42 sub get_asciidoc {
     43 	my $release = shift;
     44 	my $env = shift;
     45 
     46 	my $v;
     47 
     48 	my $tt = Template->new({
     49 		INCLUDE_PATH => '.',
     50 		INTERPOLATE => 1,
     51 		ABSOLUTE => 1,
     52 		});
     53 
     54 	if (defined $env->{template_path}) {
     55 		if (!$tt->process($env->{template_path}, $release, \$v)) {
     56 			error('error processing template: '. $tt->error());
     57 			$v = undef;
     58 		}
     59 	} else {
     60 		debug("no template specified, using default");
     61 		if (!defined $pos) {
     62 			$pos = tell(Bluto::Announce::DATA);
     63 		}
     64 		seek(Bluto::Announce::DATA, $pos, 0);
     65 		my $tpl = do { local $/; <Bluto::Announce::DATA>};
     66 		if (!$tt->process(\$tpl, $release, \$v)) {
     67 			error('error processing default template (sorry!!): '. $tt->error());
     68 			$v = undef;
     69 		}
     70 	}
     71 
     72 	$v = _adapt_headings($v);
     73 
     74 	return $v;
     75 }
     76 
     77 1;
     78 
     79 __DATA__
     80 
     81 Release announcement: [% name %]
     82 ===
     83 
     84 
     85 Version release: [% version %]
     86 
     87 License: [% license %]
     88 
     89 Copyright: [% copyright %]
     90 
     91 Author: [% author_maintainer %]
     92 
     93 Source bundles
     94 --------------
     95 
     96 [% FOREACH v IN src %]* [% v %]
     97 [% END %]
     98 
     99 VCS
    100 ---
    101 
    102 [% FOREACH v IN vcs %]* [% v %]
    103 [% END %]
    104 
    105 ONLINE RESOURCES
    106 ----------------
    107 
    108 [% FOREACH v IN url %]* [% v %]
    109 [% END %]
    110 
    111 [% FOREACH v IN contributors %][% IF !have_contributors %]CONTRIBUTORS IN THIS VERSION
    112 ----------------------------
    113 
    114 [% SET have_contributors = 1 %][% END %]* [% v.name %][% IF v.pgp %] (pgp:[% v.pgp %])[% END %]
    115 [% END %][% IF have_contributors %]
    116 
    117 [% END %]CHANGELOG
    118 ---------
    119 
    120 [% changelog %]
    121 
    122 -----
    123 
    124 Generated by [% engine %] at [% time %]Z