source: main/trunk/greenstone2/perllib/cpan/Mojolicious/Command/generate/plugin.pm@ 32205

Last change on this file since 32205 was 32205, checked in by ak19, 6 years ago

First set of commits to do with implementing the new 'paged_html' output option of PDFPlugin that uses using xpdftools' new pdftohtml. So far tested only on Linux (64 bit), but things work there so I'm optimistically committing the changes since they work. 2. Committing the pre-built Linux binaries of XPDFtools for both 32 and 64 bit built by the XPDF group. 2. To use the correct bitness variant of xpdftools, setup.bash now exports the BITNESS env var, consulted by gsConvert.pl. 3. All the perl code changes to do with using xpdf tools' pdftohtml to generate paged_html and feed it in the desired form into GS(3): gsConvert.pl, PDFPlugin.pm and its parent ConvertBinaryPFile.pm have been modified to make it all work. xpdftools' pdftohtml generates a folder containing an html file and a screenshot for each page in a PDF (as well as an index.html linking to each page's html). However, we want a single html file that contains each individual 'page' html's content in a div, and need to do some further HTML style, attribute and structure modifications to massage the xpdftool output to what we want for GS. In order to parse and manipulate the HTML 'DOM' to do this, we're using the Mojo::DOM package that Dr Bainbridge found and which he's compiled up. Mojo::DOM is therefore also committed in this revision. Some further changes and some display fixes are required, but need to check with the others about that.

File size: 3.6 KB
Line 
1package Mojolicious::Command::generate::plugin;
2use Mojo::Base 'Mojolicious::Command';
3
4use Mojo::Util qw(camelize class_to_path);
5use Mojolicious;
6
7has description => 'Generate Mojolicious plugin directory structure';
8has usage => sub { shift->extract_usage };
9
10sub run {
11 my ($self, $name) = @_;
12 $name ||= 'MyPlugin';
13
14 # Class
15 my $class = $name =~ /^[a-z]/ ? camelize $name : $name;
16 $class = "Mojolicious::Plugin::$class";
17 my $app = class_to_path $class;
18 my $dir = join '-', split('::', $class);
19 $self->render_to_rel_file('class', "$dir/lib/$app", $class, $name);
20
21 # Test
22 $self->render_to_rel_file('test', "$dir/t/basic.t", $name);
23
24 # Makefile
25 $self->render_to_rel_file('makefile', "$dir/Makefile.PL", $class, $app);
26}
27
281;
29
30=encoding utf8
31
32=head1 NAME
33
34Mojolicious::Command::generate::plugin - Plugin generator command
35
36=head1 SYNOPSIS
37
38 Usage: APPLICATION generate plugin [OPTIONS] [NAME]
39
40 mojo generate plugin
41 mojo generate plugin TestPlugin
42
43 Options:
44 -h, --help Show this summary of available options
45
46=head1 DESCRIPTION
47
48L<Mojolicious::Command::generate::plugin> generates directory structures for
49fully functional L<Mojolicious> plugins.
50
51This is a core command, that means it is always enabled and its code a good
52example for learning to build new commands, you're welcome to fork it.
53
54See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
55available by default.
56
57=head1 ATTRIBUTES
58
59L<Mojolicious::Command::generate::plugin> inherits all attributes from
60L<Mojolicious::Command> and implements the following new ones.
61
62=head2 description
63
64 my $description = $plugin->description;
65 $plugin = $plugin->description('Foo');
66
67Short description of this command, used for the command list.
68
69=head2 usage
70
71 my $usage = $plugin->usage;
72 $plugin = $plugin->usage('Foo');
73
74Usage information for this command, used for the help screen.
75
76=head1 METHODS
77
78L<Mojolicious::Command::generate::plugin> inherits all methods from
79L<Mojolicious::Command> and implements the following new ones.
80
81=head2 run
82
83 $plugin->run(@ARGV);
84
85Run this command.
86
87=head1 SEE ALSO
88
89L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
90
91=cut
92
93__DATA__
94
95@@ class
96% my ($class, $name) = @_;
97package <%= $class %>;
98use Mojo::Base 'Mojolicious::Plugin';
99
100our $VERSION = '0.01';
101
102sub register {
103 my ($self, $app) = @_;
104}
105
1061;
107<% %>__END__
108
109<% %>=encoding utf8
110
111<% %>=head1 NAME
112
113<%= $class %> - Mojolicious Plugin
114
115<% %>=head1 SYNOPSIS
116
117 # Mojolicious
118 $self->plugin('<%= $name %>');
119
120 # Mojolicious::Lite
121 plugin '<%= $name %>';
122
123<% %>=head1 DESCRIPTION
124
125L<<%= $class %>> is a L<Mojolicious> plugin.
126
127<% %>=head1 METHODS
128
129L<<%= $class %>> inherits all methods from
130L<Mojolicious::Plugin> and implements the following new ones.
131
132<% %>=head2 register
133
134 $plugin->register(Mojolicious->new);
135
136Register plugin in L<Mojolicious> application.
137
138<% %>=head1 SEE ALSO
139
140L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
141
142<% %>=cut
143
144@@ test
145% my $name = shift;
146use Mojo::Base -strict;
147
148use Test::More;
149use Mojolicious::Lite;
150use Test::Mojo;
151
152plugin '<%= $name %>';
153
154get '/' => sub {
155 my $c = shift;
156 $c->render(text => 'Hello Mojo!');
157};
158
159my $t = Test::Mojo->new;
160$t->get_ok('/')->status_is(200)->content_is('Hello Mojo!');
161
162done_testing();
163
164@@ makefile
165% my ($class, $path) = @_;
166use strict;
167use warnings;
168
169use ExtUtils::MakeMaker;
170
171WriteMakefile(
172 NAME => '<%= $class %>',
173 VERSION_FROM => 'lib/<%= $path %>',
174 AUTHOR => 'A Good Programmer <[email protected]>',
175 PREREQ_PM => {'Mojolicious' => '<%= $Mojolicious::VERSION %>'},
176 test => {TESTS => 't/*.t'}
177);
Note: See TracBrowser for help on using the repository browser.