Ambrosia
view release on metacpan or search on metacpan
share/Managers/buildApp.pm view on Meta::CPAN
package Managers::buildApp;
use strict;
use warnings;
use File::Path;
use File::Copy;
use XML::LibXSLT ();
use XML::LibXML ();
use XML::LibXML::XPathContext ();
use Ambrosia::Config;
use Ambrosia::Context;
use Ambrosia::Meta;
class sealed {
private => [qw/parser source xslt application/],
extends => [qw/Ambrosia::BaseManager/]
};
our $VERSION = 0.010;
sub _init
{
my $self = shift;
$self->SUPER::_init(@_);
$self->parser = XML::LibXML->new();
$self->xslt = XML::LibXSLT->new();
my $source = $self->source = $self->parser->parse_file(Context->param('data'));
$self->application = ($source->getElementsByTagName('Application'))[0]->cloneNode(0);
$self->application->addChild(($source->getElementsByTagName('Config'))[0]->cloneNode(1));
$self->application->addChild(($source->getElementsByTagName('DataSource'))[0]->cloneNode(1));
$self->application->addChild(($source->getElementsByTagName('Relations'))[0]->cloneNode(1));
$self->application->addChild(($source->getElementsByTagName('MenuGroups'))[0]->cloneNode(1));
}
our $encoding;
sub prepare
{
my $self = shift;
return unless $self->validateDocument();
Context->repository->set(quiet => 1);
my $appName = config->ID;
my %hDir = $self->makeDirectorys($appName);
$encoding = config->Charset || 'utf-8';
############################################################################
my $tmplPath = (config->TemplatePath || '.');
$self->makeEntityCode($hDir{dirEntity}, $tmplPath . '/Templates/Common/Entity.xsl', '.pm');
$self->makeEntityCode($hDir{dirValidators}, $tmplPath . '/Templates/Common/Validator.xsl', 'Validator.pm');
$self->makeManagerCode($hDir{dirManagers}, $tmplPath . '/Templates/Common/SaveManager.xsl', 'SaveManager.pm', 0, '@Type!="BIND" and @Type!="VIEW"');
$self->makeManagerCode($hDir{dirManagers}, $tmplPath . '/Templates/Common/EditManager.xsl', 'EditManager.pm', 0, '@Type!="BIND" and @Type!="VIEW"');
$self->makeManagerCode($hDir{dirManagers}, $tmplPath . '/Templates/Common/GetTreeManager.xsl', 'EditManager.pm', 1, '@Type!="BIND"');
$self->makeManagerCode($hDir{dirManagers}, $tmplPath . '/Templates/Common/ListManager.xsl', 'ListManager.pm', 0, '@Type!="BIND"');
$self->makeManagerCode($hDir{dirManagers}, $tmplPath . '/Templates/Common/TreeManager.xsl', 'TreeManager.pm', 1, '@Type!="BIND"');
my $tpl_path = '';
my $ex = '';
if ( config->TemplateStyle->{htmltemplate} eq 'xslt' )
{
$tpl_path = 'XSLT';
$ex = '.xsl';
}
elsif( config->TemplateStyle->{htmltemplate} eq 'tt' )
{
$tpl_path = 'TOOLKIT';
$ex = '.ttkt.html';
}
if ( config->TemplateStyle->{jsframework} eq 'dojo' )
{
$tpl_path .= '+DOJO';
}
$self->makeEntityCode($hDir{dirTemplates}, $tmplPath . '/Templates/Templates/' . $tpl_path . '/edit_json.xsl', '_edit_json' . $ex, 1, '@Type!="BIND" and @Type!="VIEW"');
copy($tmplPath . '/Templates/Templates/' . $tpl_path . '/message.xsl',
$hDir{dirTemplates} . '/_message.xsl') or die "Copy failed: $! ['${tmplPath}/Templates/Templates/${tpl_path}/message.xsl']";
copy($tmplPath . '/Templates/incUtils.xsl',
$hDir{dirTemplates} . '/_inc_utils.xsl') or die "Copy failed: $! ['${tmplPath}/Templates/incUtils.xsl']";
{#make main.xsl
my $style_doc = $self->parser->parse_file($tmplPath . '/Templates/Templates/' . $tpl_path . '/main.xsl');
($style_doc->getElementsByLocalName('output'))[0]->setAttribute( encoding => $encoding );
my $stylesheet = $self->xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($self->source);
my $fn = $hDir{dirTemplates} . '/main.xsl';
if ( -e $fn )
{
( run in 1.891 second using v1.01-cache-2.11-cpan-5837b0d9d2c )