Revize 2145
Přidáno uživatelem Ondřej Fibich před asi 11 roky(ů)
freenetis/branches/1.1/application/vendors/axo_doc/utils/generate_axo_doc.pl | ||
---|---|---|
my $VIEW_DIR = $APP_DIR . "/views";
|
||
# XML Writer
|
||
my $xml_writer;
|
||
|
||
|
||
my $XML_FILE = "../axo_doc.xml";
|
||
# comments on?
|
||
my $comments = 0;
|
||
my $comments = 1;
|
||
# cache
|
||
my %xml_old = ();
|
||
|
||
# UTF-8 set
|
||
use open ':encoding(utf8)';
|
||
binmode STDOUT, ":utf8";
|
||
|
||
# render style
|
||
XML::DOM::setTagCompression (\&my_tag_compression);
|
||
sub my_tag_compression
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
# Print error message to stderr and terminate program with error code
|
||
# Params:
|
||
# $message Error message to STDERR
|
||
... | ... | |
sub Parse($$$);
|
||
|
||
# command line options
|
||
if ($#ARGV >= 0)
|
||
if ($#ARGV > 0)
|
||
{
|
||
if ($ARGV[0] eq "-c")
|
||
if ($#ARGV == 1 && ($ARGV[0] eq "-nc"))
|
||
{
|
||
$comments = 1;
|
||
$comments = 0;
|
||
}
|
||
else
|
||
{
|
||
print STDERR "usage: perl generate_axo_doc.pl [-c]\n";
|
||
print STDERR "usage: perl generate_axo_doc.pl [-nc]\n";
|
||
exit(1);
|
||
}
|
||
}
|
||
|
||
# Read olg config
|
||
# Is readable?
|
||
if (!(-r $XML_FILE))
|
||
{
|
||
Error("Cannot read from file: " . $XML_FILE, 2);
|
||
}
|
||
|
||
# Read
|
||
my $parser = new XML::DOM::Parser;
|
||
my $xml_reader = $parser->parsefile($XML_FILE);
|
||
|
||
# Load all elements from old config
|
||
my $readed_items = $xml_reader->getElementsByTagName("object");
|
||
# All items
|
||
for (my $i = 0; $i < $readed_items->getLength; $i++)
|
||
{
|
||
my $readed_item = $readed_items->item($i);
|
||
my $i_name = $readed_item->getAttributeNode("name")->getValue;
|
||
my $i_type = $readed_item->getAttributeNode("type")->getValue;
|
||
# not view
|
||
if (!($i_type eq "view"))
|
||
{
|
||
$xml_old{$i_type . "#" . $i_name . "#"}{"name"} = $i_name;
|
||
$xml_old{$i_type . "#" . $i_name . "#"}{"type"} = $i_type;
|
||
|
||
if (defined($readed_item->getAttributeNode("comment-en")))
|
||
{
|
||
$xml_old{$i_type . "#" . $i_name . "#"}{"comment-en"} =
|
||
$readed_item->getAttributeNode("comment-en")->getValue;
|
||
}
|
||
|
||
if (defined($readed_item->getAttributeNode("comment-cs")))
|
||
{
|
||
$xml_old{$i_type . "#" . $i_name . "#"}{"comment-cs"} =
|
||
$readed_item->getAttributeNode("comment-cs")->getValue;
|
||
}
|
||
|
||
if (defined($readed_item->getAttributeNode("hide")))
|
||
{
|
||
$xml_old{$i_type . "#" . $i_name . "#"}{"hide"} =
|
||
$readed_item->getAttributeNode("hide")->getValue;
|
||
}
|
||
|
||
my $readed_methods = $readed_item->getElementsByTagName("method");
|
||
# All methods of current item
|
||
for (my $u = 0; $u < $readed_methods->getLength; $u++)
|
||
{
|
||
my $readed_method = $readed_methods->item($u);
|
||
my $m_name = $readed_method->getAttributeNode("name")->getValue;
|
||
|
||
$xml_old{$i_type . "#" . $i_name . "#" . $m_name} = $readed_method->toString;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$xml_old{$i_type . "#" . $i_name . "#####view"} = $readed_item->toString;
|
||
}
|
||
}
|
||
$xml_reader->dispose;
|
||
|
||
|
||
# Create XML Writer
|
||
$xml_writer = new XML::Writer(DATA_MODE => 1, DATA_INDENT => 4, UNSAFE => 1);
|
||
my $output_file;
|
||
# Open ouput file for write
|
||
eval
|
||
{
|
||
$output_file = new IO::File(">$XML_FILE");
|
||
$output_file or die();
|
||
};
|
||
# Error in open?
|
||
Error("Cannot write to file: $XML_FILE", 3) if ($@);
|
||
# Set ouput file to writer
|
||
binmode($output_file, ':utf8');
|
||
$xml_writer->setOutput($output_file);
|
||
# Header
|
||
$xml_writer->xmlDecl('UTF-8');
|
||
# Set doctype
|
||
... | ... | |
my $parsed_acl_call_count = 0;
|
||
my $parsed_acl_call_item_count;
|
||
my $parsed_acl_call_item_method_count;
|
||
my $added_new_method_count;
|
||
|
||
# get all php in dir and its subdirs
|
||
find(sub { push @items, $File::Find::name if /\.php$/ }, $dir);
|
||
... | ... | |
$parsed_count = $parsed_count + 1;
|
||
|
||
# Create object tag
|
||
$xml_writer->startTag("object", "name" => $file_name, "type" => $tag);
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#####view"}))
|
||
{
|
||
$xml_writer->raw("\n " . $xml_old{$tag . "#" . $file_name . "#####view"});
|
||
next; # done
|
||
}
|
||
else
|
||
{
|
||
my %attrs = ();
|
||
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#"}))
|
||
{
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#"}{"comment-en"}))
|
||
{
|
||
$attrs{"comment-en"} = $xml_old{$tag . "#" . $file_name . "#"}{"comment-en"};
|
||
}
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#"}{"comment-cs"}))
|
||
{
|
||
$attrs{"comment-cs"} = $xml_old{$tag . "#" . $file_name . "#"}{"comment-cs"};
|
||
}
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#"}{"hide"}))
|
||
{
|
||
$attrs{"hide"} = $xml_old{$tag . "#" . $file_name . "#"}{"hide"};
|
||
}
|
||
}
|
||
|
||
$xml_writer->startTag("object", "name" => $file_name, "type" => $tag, %attrs);
|
||
}
|
||
|
||
# Methods
|
||
my @methods = split(m/function\s+[a-zA-Z0-9_]+\s*\(/g, $source);
|
||
|
||
... | ... | |
{
|
||
# Reset counter
|
||
$parsed_acl_call_item_method_count = 0;
|
||
$added_new_method_count = 0;
|
||
|
||
# If enabled for checking of AXO
|
||
if (("view" eq $tag) || $methods_go_throught[$methods_names_index])
|
||
... | ... | |
{
|
||
if (!("view" eq $tag))
|
||
{
|
||
$xml_writer->startTag("method", "name" => $methods_names[$methods_names_index]);
|
||
if (defined($xml_old{$tag . "#" . $file_name . "#" . $methods_names[$methods_names_index]}))
|
||
{
|
||
$xml_writer->raw("\n " . $xml_old{$tag . "#" . $file_name . "#" . $methods_names[$methods_names_index]});
|
||
}
|
||
else
|
||
{
|
||
$added_new_method_count = $added_new_method_count + 1;
|
||
$xml_writer->startTag("method", "name" => $methods_names[$methods_names_index]);
|
||
}
|
||
}
|
||
|
||
# comment with source code
|
||
if ($comments)
|
||
if ($comments && !(defined($xml_old{$tag . "#" . $file_name . "#" . $methods_names[$methods_names_index]})))
|
||
{
|
||
my $method_body_comments = $method_body;
|
||
$method_body_comments =~ s/[-][-]//mg; # remove --
|
||
... | ... | |
# increase counter
|
||
$parsed_acl_call_count = $parsed_acl_call_count + 1;
|
||
$parsed_acl_call_item_method_count = $parsed_acl_call_item_method_count + 1;
|
||
# Create AXo tag
|
||
$xml_writer->startTag(
|
||
"axo",
|
||
"usage_type" => "unknown",
|
||
"section" => $axo_section,
|
||
"value" => $axo_value,
|
||
"action" => $action,
|
||
"own" => $is_own
|
||
);
|
||
|
||
# End AXO tag
|
||
$xml_writer->endTag();
|
||
if (!(defined($xml_old{$tag . "#" . $file_name . "#" . $methods_names[$methods_names_index]})))
|
||
{
|
||
# Create AXo tag
|
||
$xml_writer->startTag(
|
||
"axo",
|
||
"usage_type" => "unknown",
|
||
"section" => $axo_section,
|
||
"value" => $axo_value,
|
||
"action" => $action,
|
||
"own" => $is_own
|
||
);
|
||
|
||
# End AXO tag
|
||
$xml_writer->endTag();
|
||
}
|
||
}
|
||
|
||
|
||
# end method tag?
|
||
if ($parsed_acl_call_item_method_count > 0)
|
||
{
|
||
if (!("view" eq $tag))
|
||
if (!("view" eq $tag) && !(defined($xml_old{$tag . "#" . $file_name . "#" . $methods_names[$methods_names_index]})))
|
||
{
|
||
$xml_writer->endTag();
|
||
}
|
||
}
|
||
elsif ($tag eq "controller")
|
||
{
|
||
$added_new_method_count = $added_new_method_count + 1;
|
||
$xml_writer->startTag("method", "name" => $methods_names[$methods_names_index]);
|
||
$xml_writer->endTag();
|
||
}
|
||
... | ... | |
$methods_names_index = $methods_names_index + 1;
|
||
}
|
||
|
||
# Hack for raw indent
|
||
if ($added_new_method_count == 0 && $parsed_acl_call_item_method_count > 0) {
|
||
#$xml_writer->raw("\n ");
|
||
}
|
||
|
||
# End tag object
|
||
$xml_writer->endTag();
|
||
|
Také k dispozici: Unified diff
Opravy:
- refs #563: skript pro generovani nove umi mazat neexistujici metody a soubory a pridavat nove