commit 613f01c50bd01ebc63cb283dcfdbcc7b4b1cdb8d
parent 67f313ddf3a961b5de0a95553f3365724a4f8773
Author: lash <dev@holbrook.no>
Date: Thu, 20 Jun 2024 01:35:55 +0100
Extend asciidoc header markers in dynamic headings
Diffstat:
4 files changed, 107 insertions(+), 23 deletions(-)
diff --git a/Bluto.pm b/Bluto.pm
@@ -5,6 +5,7 @@ use SemVer;
use Log::Term::Ansi qw/error info debug warn trace/;
use Bluto::Archive;
+use Bluto::Announce;
use constant { VCS_TAG_PREFIX => 'v' };
use constant { VERSION => '0.0.1' };
@@ -101,6 +102,33 @@ sub _set_author {
return 0;
}
+sub _check_readme {
+ my $env = shift;
+ my $f;
+ my $fp;
+
+ for my $fn (('README', 'README.txt', 'README.adoc', 'README.rst', 'README.md')) {
+ $fp = File::Spec->catfile($env->{src_dir}, $fn);
+ if ( -f $fp ) {
+ info('using readme file: ' . $fp);
+ $env{readme} = $fp;
+ return 0;
+ }
+ }
+
+ warn('no readme file found');
+ return 1;
+}
+
+sub check_sanity {
+ my $env = shift;
+ my $r = 0;
+
+ $r += _check_readme($env);
+
+ return $r;
+}
+
sub from_config {
my $cfg = shift;
my $env = shift;
@@ -110,7 +138,7 @@ sub from_config {
$version = $cfg->{version};
} else {
$fn = File::Spec->catfile($env->{src_dir}, 'VERSION');
- open(my $f, "<$fn") or error('no version file found: ' . $fn) && return undef;
+ open(my $f, '<', $fn) or error('no version file found: ' . $fn) && return undef;
$version = <$f>;
close($f);
$version = SemVer->new($version);
@@ -213,7 +241,7 @@ sub from_config {
# TODO: if have sha256, check against the contents
for my $fn (@changelog_candidates) {
my $fp = File::Spec->catfile ( $env->{content_dir}, $fn );
- if (open(my $f, "<$fp")) {
+ if (open(my $f, '<', $fp)) {
$m_main{changelog} = '';
my $i = 0;
while (!eof($f)) {
@@ -250,23 +278,10 @@ sub from_config {
return $have_version_match;
}
-sub get_announcement {
- my $env = shift;
-
- my $tt = Template->new({
- INCLUDE_PATH => '.',
- INTERPOLATE => 1,
- ABSOLUTE => 1,
- });
- my $out;
- $tt->process($env->{template_path}, \%m_main, \$out) or error('error processing template: '. $tt->error());
- return $out;
-}
-
sub get_rss {
my $env = shift;
- my $out = get_announcement($env);
+ my $out = Bluto::Announce::get_asciidoc(\%m_main, $env);
return Bluto::RSS::to_string(\%m_main, $env, $out);
}
diff --git a/Bluto/Announce.pm b/Bluto/Announce.pm
@@ -0,0 +1,61 @@
+package Bluto::Announce;
+
+use Log::Term::Ansi qw/error info debug warn trace/;
+
+sub _adapt_headings {
+ my $f;
+ my $last = undef;
+ my $this = undef;
+ my $r = '';
+ my $v = shift;
+
+ open(my $f, '<', \$v);
+ while (<$f>) {
+ $this = undef;
+ if (defined $last) {
+ if ($_ =~ /^===/) {
+ $this = '=' x length($last);
+ } elsif ($_ =~ /^---/) {
+ if ($last !~ /^\W+$/) {
+ debug('last is ' . $last);
+ $this = '-' x (length($last) - 1);
+ } else {
+ $this = $_;
+ }
+ }
+
+ }
+ if (!defined $this) {
+ $this = $_;
+ }
+ $r .= $this;
+ $last = $_;
+ }
+ close($f);
+
+ return $r;
+}
+
+sub get_asciidoc {
+ my $release = shift;
+ my $env = shift;
+
+ my $v;
+
+ my $tt = Template->new({
+ INCLUDE_PATH => '.',
+ INTERPOLATE => 1,
+ ABSOLUTE => 1,
+ });
+
+ if (!$tt->process($env->{template_path}, $release, \$v)) {
+ error('error processing template: '. $tt->error());
+ $v = undef;
+ }
+
+ $v = _adapt_headings($v);
+
+ return $v;
+}
+
+1;
diff --git a/base.tt b/base.tt
@@ -1,11 +1,11 @@
-Release announcement for [% name %]
+Release announcement: [% name %]
===
Version release: [% version %]
License: [% license %]
Source bundles
----
+--------------
[% FOREACH v IN src %]* [% v %]
[% END %]
@@ -17,16 +17,18 @@ VCS
[% END %]
ONLINE RESOURCES
----
+----------------
[% FOREACH v IN url %]* [% v %]
[% END %]
CHANGELOG
----
+---------
[% changelog %]
----
+-----
Release generator: [% engine %]
+
+-----
diff --git a/to_std.pl b/to_std.pl
@@ -33,6 +33,7 @@ my %env = (
content_dir => getcwd,
template_path => 'base.tt',
engine => undef,
+ readme => undef,
);
#my $src_dir =
#my $out_dir = getcwd;
@@ -52,7 +53,13 @@ foreach my $k (keys %env ) {
$env{engine} = 'bluto v' . SemVer->new(Bluto::VERSION). " (perl $^V)";
foreach my $k (keys %env ) {
- debug('environment "' . $k . '": ' . $env{$k});
+ if (defined $env{$k}) {
+ debug('environment "' . $k . '": ' . $env{$k});
+ }
+}
+
+if (Bluto::check_sanity(\%env)) {
+ croak('sanity check fail');
}
my $fn = File::Spec->catfile($env{src_dir}, 'bluto.ini');
@@ -64,7 +71,6 @@ if (!defined $version) {
die("config processing failed");
}
-my $announcement = Bluto::get_announcement(\%env);
my $rss = Bluto::get_rss(\%env);
print($rss);