Ado
view release on metacpan or search on metacpan
lib/Ado/Command/generate/crud.pm view on Meta::CPAN
=head2 C|controller_namespace=s
Optional. The namespace for the controller classes to be generated.
Defaults to C<app-E<gt>routes-E<gt>namespaces-E<gt>[0]>, usually
L<Ado::Control>. If you decide to use another namespace for the controllers,
do not forget to add it to the list C<app-E<gt>routes-E<gt>namespaces>
in C<etc/ado.conf> or your plugin configuration file.
=head2 H|home_dir=s
Defaults to C<$ENV{MOJO_HOME}> (which is Ado home directory).
Used to set the root directory to which the files
will be dumped when L<generating an Ado plugin|Ado::Command::generate::adoplugin>.
=head2 L|lib=s
Defaults to C<lib> relative to the C<--home_dir> directory.
If you installed L<Ado> in some custom path and you wish to generate your controllers into
e.g. C<site_lib>, use this option. Do not forget to add this
directory to C<$ENV{PERL5LIB}>, so the classes can be found and loaded.
=head2 M|model_namespace=s
Optional. The namespace for the model classes to be generated.
Defaults to L<Ado::Model>. If you wish however to use another namespace
for another database, you will have to add another item for
L<Mojolicious::Plugin::DSC> to the list of loaded plugins in C<etc/ado.conf>
or in your plugin configuration. Yes, multiple database connections/schemas
are supported.
=head2 T|templates_root=s
Defaults to C<app-E<gt>renderer-E<gt>paths-E<gt>[0]>. This is usually
C<site_templates> directory. If you want to use another directory,
do not forget to add it to the C<app-E<gt>renderer-E<gt>paths> list
in your configuration file.
=head2 t|tables=s@
Mandatory. List of tables separated by commas for which controllers should be generated.
=head1 ATTRIBUTES
L<Ado::Command::generate::crud> inherits all attributes from
L<Ado::Command::generate> and implements the following new ones.
=head2 description
my $description = $command->description;
$command = $command->description('Foo!');
Short description of this command, used for the command list.
=head2 routes
$self->routtes();
Returns an ARRAY reference containing routes, prepared after C<$self-E<gt>args-E<gt>{tables}>.
Altough L<Ado> already has defined generic routes for CRUD,
this attribute contains more specific routes, that will secure the C<create>,
C<update> and C<delete> actions, so they are available only to an
authenticated user. This attribute is used for generating routes in
L<Ado::Command::generate::adoplugin>.
After generating a plugin you should end up with a
L<RESTful|http://en.wikipedia.org/wiki/REST>
service. The generated code uses
L<Mojolicious::Controller/respond_to>. For details see
L<Mojolicious::Guides::Rendering/Content-negotiation>.
=head2 usage
my $usage = $command->usage;
$command = $command->usage('Foo!');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Ado::Command::generate::crud> inherits all methods from
L<Ado::Command> and implements the following new ones.
=head2 initialise
sub run {
my ($self) = shift->initialise(@_);
#...
}
Parses arguments and prepares the command to be run. Calling this method for the second time has no effect.
Returns C<$self>.
=head2 run
Ado::Command::generate::crud->new(app=>$app)->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Ado::Command::generate::adoplugin>,
L<Ado::Command::generate::apache2vhost>,
L<Ado::Command::generate::apache2htaccess>, L<Ado::Command::generate>,
L<Mojolicious::Command::generate>, L<Getopt::Long>,
L<Ado::Command> L<Ado::Manual>,
L<Mojolicious>, L<Mojolicious::Guides::Cookbook/DEPLOYMENT>
=head1 AUTHOR
ÐÑаÑÐ¸Ð¼Ð¸Ñ ÐеÑов (Krasimir Berov)
=head1 COPYRIGHT AND LICENSE
Copyright 2014 ÐÑаÑÐ¸Ð¼Ð¸Ñ ÐеÑов (Krasimir Berov).
This program is free software, you can redistribute it and/or
modify it under the terms of the
GNU Lesser General Public License v3 (LGPL-3.0).
You may copy, distribute and modify the software provided that
modifications are open source. However, software that includes
the license may release under a different license.
See http://opensource.org/licenses/lgpl-3.0.html for more information.
=cut
__DATA__
@@ class
% my $a = shift;
package <%= $a->{class} %>;
use Mojo::Base '<%= $a->{controller_namespace} %>';
our $VERSION = '0.01';
# Generate class on the fly from the database.
# No worries - this is cheap, one-time generation.
# See documentation for Ado::Model::class_from_table
my $table_class = Ado::Model->table_to_class(
namespace => '<%= $a->{model_namespace} %>',
table => '<%= $a->{t} %>',
type => 'TABLE'
);
# List resourses from table <%= $a->{t} %>.
sub list {
my $c = shift;
$c->require_formats('json','html') || return;
my $args = Params::Check::check(
{ limit => {
lib/Ado/Command/generate/crud.pm view on Meta::CPAN
return shift->render(message => '"delete" is not implemented...');
}
1;
<% %>__END__
<% %>=encoding utf8
<% %>=head1 NAME
<%= $a->{class} %> - a controller for resource <%= $a->{t} %>.
<% %>=head1 SYNOPSIS
<% %>=cut
@@ list_template
% $a = shift;
%% my $columns = $table_class->COLUMNS;
<table>
<thead>
<tr>
%% foreach my $column( @$columns ){
<th><%%= $column %></th>
%% }
</tr>
</thead>
<tbody>
%% foreach my $row (@{$list->{json}{data}}) {
<tr>
%% foreach my $column( @$columns ){
<td><%%= $row->{$column} %></td>
%% }
</tr>
%% }
</tbody>
%%#== $c->dumper($list);
</table>
@@ create_template
% $a = shift;
<article>
Create your form for creating a resource here.
</article>
@@ read_template
% $a = shift;
<article id="<%%= $article->{id} %>">
<h1><%%= $article->{title} %></h1>
<section><%%= $article->{body} %></section>
</article>
@@ update_template
% $a = shift;
<article>
Create your form for updating a resource here.
</article>
@@ delete_template
% $a = shift;
<article>
<section class="ui error form segment"><%%= $message %></section>
</article>
( run in 1.828 second using v1.01-cache-2.11-cpan-98e64b0badf )