Skip to content

Commit

Permalink
Rename generator script to kelp-generator
Browse files Browse the repository at this point in the history
This allows easier perldoc access to both the class and the script.
  • Loading branch information
bbrtj committed Jun 23, 2024
1 parent c11f548 commit bdb4de2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
- Fixed templates named '0' not getting rendered
- Fixed template correctly providing an 'app' object by default:
* This object was available in Kelp::Response template but was not getting properly reblessed (see 'context' above)
* Kelp template now also inserts this parameter to render variables unless it is already provided
* Generation template now also inserts this parameter to render variables unless it is already provided
- Fixed ::Null modules containing testing behavior - now they really do nothing
- Repeatedly fetching parameters from json request with the param method is now much faster
- Kelp::Module::Logger now sorts keys in Data::Dumper output
- Kelp can now be debugged using KELP_DEBUG environmental variable
- Performance of accessors and request/response building was improved
- 'Kelp' script has been renamed to 'kelp-generator' and documented
- Documentation was vastly improved

[Encoding]
Expand Down
69 changes: 53 additions & 16 deletions bin/Kelp → bin/kelp-generator
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Kelp::Base -strict;
use Getopt::Long;
use Kelp::Generator;
use Path::Tiny;
use Pod::Usage;

my $path = '.';
my $verbose = 1;
Expand All @@ -21,15 +22,15 @@ GetOptions(
"help" => \$help
);

my $name = $ARGV[0] || do { $help = 1; '' };
my $name = $ARGV[0];
my $generator = Kelp::Generator->new;

if ( $help ) {
my @usage = <DATA>;
say @usage;
if ( !$name || $help ) {
say 'Error - no application name.' unless $help;
pod2usage(-verbose => 1, -exitval => 'NOEXIT');
say 'Available application types:';
say for map { ' ' x 4 . $_ } $generator->list_templates;
exit;
exit ($help ? 0 : 1);
}

# Remove the slash at the end
Expand Down Expand Up @@ -74,14 +75,50 @@ sub _say {
}
}

__DATA__
Usage: Kelp [options] <name>
Options:
--path=s Path where to create the files
--type=s Type of application to create (default: kelp)
--types List available application types
--(no)verbose Display information
--force Force overwriting existing files
--tabs Use tabs for indentation instead of spaces
--help This help screen
__END__
=pod
=head1 NAME
kelp-generator - Generate Kelp applications
=head1 SYNOPSIS
kelp-generator [options] <application-name>
=head1 OPTIONS
=over 4
=item B<--path=s>
Path where to create the files
=item B<--type=s>
Type of application to create (default: kelp)
=item B<--(no)verbose>
Display more or less information
=item B<--force>
Force overwriting existing files
=item B<--tabs>
Use tabs for indentation instead of spaces
=item B<--help>
This help screen
=back
=head1 DESCRIPTION
B<This program> will generate a Kelp project from one of the registered
templates. C<< <application-name> >> will be used as the name of the package.
6 changes: 3 additions & 3 deletions lib/Kelp/Generator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Kelp::Generator - Generation templates
This is a class for discovery and parsing of generation templates for Kelp. A
generation template is a set of files that can be parsed using
L<Template::Tiny> and inserted into a given directory. This class only handles
the discovery and parsing of these templates. The Kelp script or custom script
should handle saving them in a destination directory.
the discovery and parsing of these templates. The C<kelp-generator> script or
custom script should handle saving them in a destination directory.
=head1 TEMPLATE CREATION
Expand All @@ -118,7 +118,7 @@ This means that CPAN modules can add templates to L<Kelp/templates> and they
will be discovered as long as they have been installed in the same root
directory as Kelp without changing the contents of the package variable. Any
template that can be discovered in the default directory will be usable in the
Kelp script.
C<kelp-generator> script.
=head2 Contents
Expand Down
12 changes: 6 additions & 6 deletions lib/Kelp/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,28 @@ here is a quick one:

run;

=head2 Using the C<Kelp> script
=head2 Using the C<kelp-generator> script

The easiest way to create the directory structure and a general application
skeleton is by using the C<Kelp> script, which comes with this package.
skeleton is by using the C<kelp-generator> script, which comes with this package.

> Kelp MyApp
> kelp-generator MyApp

This will create C<lib/MyApp.pm>, C<app.psgi> and some other files (explained
below).

To create a L<Kelp::Less> app file, use:

> Kelp --type=less MyApp
> kelp-generator --type=less MyApp

Get help by typing:

> Kelp --help
> kelp-generator --help

=head2 Directory structure

Before you begin writing the internals of your app, you need to create the
directory structure either by hand, or by using the above described C<Kelp>
directory structure either by hand, or by using the above described C<kelp-generator>
utility script.

.
Expand Down
7 changes: 6 additions & 1 deletion t/bin_tests.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ sub test_app
my $params = shift;
my $kelp_dir = tempdir(CLEANUP => 1);
push @INC, "$kelp_dir/lib";
system("$Config{perlpath} $Bin/../bin/Kelp --path=$kelp_dir --noverbose $params");
system("$Config{perlpath} $Bin/../bin/kelp-generator --path=$kelp_dir --noverbose $params");

my ($total, $failed) = execute_tests(tests => ["$kelp_dir/t/main.t"]);
ok($total->{bad} == 0 && $total->{max} > 0, "Generated app tests OK")
or diag explain $failed;
}

my $help = `$Config{perlpath} $Bin/../bin/kelp-generator --help`;
like $help, qr/\Qkelp-generator [options] <application-name>\E/, 'help head ok';
like $help, qr/\QAvailable application types:\E/, 'help templates ok';

done_testing;

0 comments on commit bdb4de2

Please sign in to comment.