182 lines
5.8 KiB
Plaintext
182 lines
5.8 KiB
Plaintext
|
I am wanting you to create a python3 programm to take as input a Mojolicious Template file and output the same contents, but formatted in a way to make it structure easily understandable by a human.
|
||
|
This involves identifying all html tags, mojolicious command and helper commands and also all perl constructs and indenting them in a such a way that subservient html and other statements are indented like an html prettifier, taking into account that the file may also include perl program statements which also should be properly formatted and indented to show the structure like perltidy. All "%" in the first non space character position in the line should be followed by a space unless followed by a specific mojolicious character such as "=".
|
||
|
you can use any python3 libraries that you see fit.
|
||
|
here is an example of a mojolicious template file which needs re-structuring:
|
||
|
```
|
||
|
% layout 'default', title => "Sme server 2 - yum_install";
|
||
|
% content_for 'module' => begin
|
||
|
<div id='module' class='module yuminstall-panel'>
|
||
|
% if (config->{debug} == 1) {
|
||
|
<p>
|
||
|
%= dumper $c->current_route
|
||
|
%= dumper $yum_datas
|
||
|
</p>
|
||
|
% }
|
||
|
|
||
|
<h1><%= $title%></h1>
|
||
|
|
||
|
% if ( $notif ) {
|
||
|
<br><div class=sme-error>
|
||
|
%= $notif
|
||
|
</div>
|
||
|
%}
|
||
|
<br>
|
||
|
|
||
|
%= form_for 'yumd' => (method => 'POST') => begin
|
||
|
|
||
|
%=l 'yum_HEADER_AVAILABLE_SOFTWARE'
|
||
|
<br><br>
|
||
|
% if ($c->non_empty('available','group')) {
|
||
|
%=l 'yum_DESC_AVAILABLE_GROUPS'
|
||
|
<p><span class=label>
|
||
|
%=l 'yum_LABEL_AVAILABLE_GROUPS'
|
||
|
</span><span class=data>
|
||
|
% param 'SelectedGroups' => $c->get_names2('updates','group') unless param 'SelectedGroups';
|
||
|
%= select_field 'SelectedGroups' => $c->get_options2('available', 'group'), class => 'input', multiple => "1"
|
||
|
</span></p>
|
||
|
%}
|
||
|
<br>
|
||
|
% if ($c->non_empty('available','packages')) {
|
||
|
%=l 'yum_DESC_AVAILABLE_PACKAGES'
|
||
|
<p><span class=label>
|
||
|
%=l 'yum_LABEL_AVAILABLE_PACKAGES'
|
||
|
</span><span class=data>
|
||
|
% param 'SelectedPackages' => $c->get_names2('updates','package') unless param 'SelectedPackages';
|
||
|
%= select_field 'SelectedPackages' => $c->get_options2('available', 'package'), class => 'input', multiple => "1"
|
||
|
</span></p>
|
||
|
%}
|
||
|
<!-- $c->print_skip_header() -->
|
||
|
%= hidden_field 'trt' => 'INST'
|
||
|
<br><br>
|
||
|
<!-- <div class='center'>-->
|
||
|
%= submit_button $c->l('yum_INSTALL_SOFTWARE'), class => 'action'
|
||
|
<!--</div>-->
|
||
|
% end
|
||
|
</div>
|
||
|
% end
|
||
|
|
||
|
```
|
||
|
and here is the same example restructured:
|
||
|
```
|
||
|
% layout 'default', title => "Sme server 2 - yum_install";
|
||
|
% content_for 'module' => begin
|
||
|
<div id='module' class='module yuminstall-panel'>
|
||
|
% if (config->{debug} == 1) {
|
||
|
<p>
|
||
|
%= dumper $c->current_route
|
||
|
%= dumper $yum_datas
|
||
|
</p>
|
||
|
% }
|
||
|
<h1><%= $title%></h1>
|
||
|
% if ( $notif ) {<br>
|
||
|
<div class=sme-error>
|
||
|
%= $notif
|
||
|
</div>
|
||
|
%}
|
||
|
<br>
|
||
|
%= form_for 'yumd' => (method => 'POST') => begin
|
||
|
%=l 'yum_HEADER_AVAILABLE_SOFTWARE'
|
||
|
<br><br>
|
||
|
% if ($c->non_empty('available','group')) {
|
||
|
%=l 'yum_DESC_AVAILABLE_GROUPS'
|
||
|
<p><span class=label>
|
||
|
%=l 'yum_LABEL_AVAILABLE_GROUPS'
|
||
|
</span><span class=data>
|
||
|
% param 'SelectedGroups' => $c->get_names2('updates','group') unless param 'SelectedGroups';
|
||
|
%= select_field 'SelectedGroups' => $c->get_options2('available', 'group'), class => 'input', multiple => "1"
|
||
|
</span></p>
|
||
|
%}
|
||
|
<br>
|
||
|
% if ($c->non_empty('available','packages')) {
|
||
|
%=l 'yum_DESC_AVAILABLE_PACKAGES'
|
||
|
<p><span class=label>
|
||
|
%=l 'yum_LABEL_AVAILABLE_PACKAGES'
|
||
|
</span><span class=data>
|
||
|
% param 'SelectedPackages' => $c->get_names2('updates','package') unless param 'SelectedPackages';
|
||
|
%= select_field 'SelectedPackages' => $c->get_options2('available', 'package'), class => 'input', multiple => "1"
|
||
|
</span></p>
|
||
|
%}
|
||
|
<!-- $c->print_skip_header() -->
|
||
|
%= hidden_field 'trt' => 'INST'
|
||
|
<br><br>
|
||
|
<!-- <div class='center'>-->
|
||
|
%= submit_button $c->l('yum_INSTALL_SOFTWARE'), class => 'action'
|
||
|
<!--</div>-->
|
||
|
% end
|
||
|
</div>
|
||
|
% end
|
||
|
```
|
||
|
Give me the whole program with the following second example unformatted template file ready to run as a test
|
||
|
|
||
|
```
|
||
|
<div id='dom_upd'>
|
||
|
% my $btn = l('ADD');
|
||
|
%= form_for '/domains2' => (method => 'POST') => begin
|
||
|
<p>
|
||
|
<h2>
|
||
|
% if ( $dom_datas->{trt} eq "ADD" ) {
|
||
|
%=l 'dom_CREATE_TITLE'
|
||
|
% } else {
|
||
|
%=l 'dom_MODIFY_TITLE'
|
||
|
% $btn = l('MODIFY');
|
||
|
% }
|
||
|
</h2>
|
||
|
</p>
|
||
|
<p><br>
|
||
|
<span class=label>
|
||
|
%=l 'DOMAIN_NAME', class => 'label'
|
||
|
</span><span class=data>
|
||
|
% if ( $dom_datas->{trt} eq "ADD" ) {
|
||
|
% param 'Domain' => $dom_datas->{domain} unless param 'Domain';
|
||
|
%= text_field 'Domain', class => 'input'
|
||
|
% } else {
|
||
|
%= hidden_field 'Domain' => $dom_datas->{domain}
|
||
|
%= $dom_datas->{domain}, class => 'data'
|
||
|
% }
|
||
|
</span>
|
||
|
</p>
|
||
|
<p><br>
|
||
|
<span class=label>
|
||
|
%=l 'DESCRIPTION_BRIEF', class => 'label'
|
||
|
</span><span class=data>
|
||
|
% param 'Description' => $dom_datas->{description} unless param 'Description';
|
||
|
%= text_field 'Description', class => 'input'
|
||
|
</span>
|
||
|
</p>
|
||
|
<p><br>
|
||
|
%=l 'dom_CONTENT_FIELD_DESCRIPTION'
|
||
|
<br>
|
||
|
<span class=label>
|
||
|
%= $c->l('dom_CONTENT', '');
|
||
|
</span><span class=data>
|
||
|
% param 'Content' => $dom_datas->{content} unless param 'Content';
|
||
|
%= select_field 'Content', $c->content_options_list(), class => 'input'
|
||
|
</span>
|
||
|
</p>
|
||
|
<p><br>
|
||
|
%=l 'dom_DESC_NAMESERVERS'
|
||
|
<br>
|
||
|
<span class=label>
|
||
|
%=l 'dom_LABEL_NAMESERVERS', class => 'label'
|
||
|
</span><span class=data>
|
||
|
% param 'Nameservers' => $dom_datas->{nameservers} unless param 'Nameservers';
|
||
|
%= select_field 'Nameservers', $c->nameserver_options_list(), class => 'input'
|
||
|
</span>
|
||
|
</p>
|
||
|
<p><br>
|
||
|
%= submit_button "$btn", class => 'action'
|
||
|
</p>
|
||
|
%= hidden_field 'trt' => $dom_datas->{trt}
|
||
|
%end
|
||
|
</div>
|
||
|
```
|
||
|
|
||
|
Further thoughts:
|
||
|
|
||
|
Some files have this iosrt of structure are <%
|
||
|
...perl...
|
||
|
%>
|
||
|
The perl needs to be formatted accordingly.
|
||
|
|
||
|
and Delete all blank lines and put all final tags (where the content is indented) on a line on its own.
|
||
|
Example is</p> </span> </dev> and others
|