Skip to content

Commit

Permalink
Add description_label attribute to use a H1 other than DESCRIPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed May 6, 2015
1 parent 7bd571e commit 4e4e474
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Release history for Dist-Zilla-Plugin-Readme-Brief
- Dependencies changed since 0.002005, see misc/*.deps* for details
- develop: ↑2 (suggests: ↑2)

[Features]
- Can override which section to take brief from instead of DESCRIPTION by setting `description_label`

0.002005 2015-03-04T15:21:15Z 03b80f3
[Dependencies::Stats]
- Dependencies changed since 0.002004, see misc/*.deps* for details
Expand Down
10 changes: 9 additions & 1 deletion README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ version 0.002006
[Readme::Brief]
; Override autodetected install method
installer = eumm
; Override name to use for brief body
description_label = WHAT IS THIS

# DESCRIPTION

Expand All @@ -32,7 +34,7 @@ However, bugs are highly likely to be encountered, especially as there are no te
# MECHANICS

- Heading is derived from the `package` statement in `main_module`
- Description is extracted as the entire `H1Nest` of the section titled `DESCRIPTION` in `main_module`
- Description is extracted as the entire `H1Nest` of the section titled `DESCRIPTION` ( or whatever `description_label` is ) in `main_module`
- Installation instructions are automatically determined by the presence of either
- A `Makefile.PL` file in your dist ( Where it assumes `EUMM` style )
- A `Build.PL` file in your dist ( where it assumes `Module::Build` style )
Expand Down Expand Up @@ -63,6 +65,12 @@ this attribute allows you to control which, or all, and the order.

The verbiage however has not yet been cleaned up such that having both is completely lucid.

## description\_label

This case-insensitive attribute defines what `=head1` node will be used for the description section of the brief.

By default, this is `DESCRIPTION`.

# SEE ALSO

Here are some competing modules and how this module differs from them.
Expand Down
27 changes: 22 additions & 5 deletions lib/Dist/Zilla/Plugin/Readme/Brief.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ our $VERSION = '0.002006';

use Moose qw( with has around );
use List::Util qw( first );
use MooseX::Types::Moose qw( ArrayRef );
use MooseX::Types::Moose qw( ArrayRef Str );
use Moose::Util::TypeConstraints qw( enum );
use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
use PPIx::DocumentName;
Expand Down Expand Up @@ -59,6 +59,21 @@ has 'installer' => (

no Moose::Util::TypeConstraints;

=attr description_label
This case-insensitive attribute defines what C<=head1> node will be used for the description section of the brief.
By default, this is C<DESCRIPTION>.
=cut

has 'description_label' => (
isa => Str,
is => 'ro',
lazy => 1,
default => sub { 'DESCRIPTION' },
);

around 'mvp_multivalue_args' => sub {
my ( $orig, $self, @rest ) = @_;
return ( $self->$orig(@rest), 'installer' );
Expand All @@ -69,7 +84,7 @@ around 'mvp_aliases' => sub {
return { %{ $self->$orig(@rest) }, installers => 'installer' };
};

around dump_config => config_dumper( __PACKAGE__, { attrs => ['installer'] } );
around dump_config => config_dumper( __PACKAGE__, { attrs => [ 'installer', 'description_label' ] } );

__PACKAGE__->meta->make_immutable;
no Moose;
Expand Down Expand Up @@ -221,11 +236,11 @@ sub _description {

for my $node_number ( 0 .. $#nodes ) {
next unless Pod::Elemental::Selectors::s_command( head1 => $nodes[$node_number] );
next unless 'DESCRIPTION' eq uc $nodes[$node_number]->content;
next unless uc $self->description_label eq uc $nodes[$node_number]->content;
push @found, $nodes[$node_number];
}
if ( not @found ) {
$self->log( 'DESCRIPTION not found in ' . $self->_source_pm_file->name );
$self->log( $self->description_label . ' not found in ' . $self->_source_pm_file->name );
return q[];
}
return $self->_podtext_nodes( map { @{ $_->children } } @found );
Expand Down Expand Up @@ -298,6 +313,8 @@ EOFMB
[Readme::Brief]
; Override autodetected install method
installer = eumm
; Override name to use for brief body
description_label = WHAT IS THIS
=head1 NOTE
Expand All @@ -312,7 +329,7 @@ However, bugs are highly likely to be encountered, especially as there are no te
=item * Heading is derived from the C<package> statement in C<main_module>
=item * Description is extracted as the entire C<H1Nest> of the section titled C<DESCRIPTION> in C<main_module>
=item * Description is extracted as the entire C<H1Nest> of the section titled C<DESCRIPTION> ( or whatever C<description_label> is ) in C<main_module>
=item * Installation instructions are automatically determined by the presence of either
Expand Down
45 changes: 45 additions & 0 deletions t/description_label.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use strict;
use warnings;

use Test::More;

# ABSTRACT: Basic Test

use Dist::Zilla::Util::Test::KENTNL 1.004 qw( dztest );
use Test::DZil qw( simple_ini );

my $test = dztest();
$test->add_file( 'lib/Example.pm' => <<'EOF' );
package Foo;
=head1 WHAT IS THIS
This is a description
=cut
1;
EOF

$test->add_file(
'dist.ini' => simple_ini(
[ 'GatherDir' => {} ], #
[ 'Readme::Brief' => { description_label => "WHAT IS THIS" } ],
)
);
$test->build_ok;

my $src_file = $test->test_has_built_file('README');
my @lines = $src_file->lines_utf8( { chomp => 1 } );

use List::Util qw( first );

ok( ( first { $_ eq 'Foo' } @lines ), 'Document name found and injected' );
ok( ( first { $_ eq 'This is a description' } @lines ), 'Description injected' );
ok( ( first { $_ eq 'INSTALLATION' } @lines ), 'Installation section injected' );
ok( ( first { $_ eq 'COPYRIGHT AND LICENSE' } @lines ), 'Copyright section injected' );

done_testing;

0 comments on commit 4e4e474

Please sign in to comment.