Template-Plexsite
view release on metacpan or search on metacpan
script/build-menu.pl view on Meta::CPAN
$stage_count++;
#First pass config stages for each input file
my %templates;
my %configs;
for(@ARGV){
#Skip if input is not a plt dir
next unless /plt$/;
\my %config={};
#Convert path to relative path from root
my $input=abs2rel realpath($_), $root;
$config{url_table}=\%url_table;
$config{html_root}=$html_root;
$config{locale}="en";
$config{nav}=\%nav;
#$config{input};
$config{menu}=undef;
Log::OK::INFO and log_info "Processing $_";
$config{output}={};#undef;#"/dev/null";
$config{input}=$input;
$configs{$input}=\%config;
#Test the type of index file
my ($index_file)= <"$root/$input/index.*" >;
my $target;
my $src;
if($index_file=~/html/){
$src="index.html.plex";
$target="index.html";
}
elsif($index_file=~/css/){
$src="index.css.plex";
$target="index.css";
}
else{
$target="index.unkown";
}
#Inputs are dirs with plt extensions. A index.html page exists inside
my $template=plex $input."/".$src, $configs{$input}, %opts;
my $result=$template->setup;#render;
#If Output variable is set, we can add it to the list
if($config{output}{location}){
#Process menu entry if required
#
if($config{menu}){
Log::OK::DEBUG and log_debug "Template sets a menu entry. Adding to navication";
#Split the menu item
my @parts=split m|/|, $config{menu}{path};
Log::OK::DEBUG and log_debug "Menu path will be: ", join ", ", @parts;
my $parent=$config{nav};
for(@parts){
$parent = $parent->{$_}//={};
}
$parent->{_data}{href}//=$input;
for( keys $config{menu}->%*){
next if $_ eq "path";
$parent->{_data}{$_}=$config{menu}{$_};
}
}
#add entry to output file table
$url_table{$input}=$config{locale}."/".$config{output}{location}."/".$target;
$templates{$input}=$template;
}
NONE:
}
#Log::OK::INFO and log_info Dumper \%url_table;
#Process url table to generate multiple tables base on dir levels
for my $val (values %url_table){
$val =~ s|^/||;
};
#Prepare layout here to add any resources to the url table
my %layout_config;
$layout_config{slot}="";
$layout_config{url_table}=\%url_table;
$layout_config{nav}=\%nav;
$layout_config{locale}="en";
$layout_config{output}="";
my $layout=plex "templates/page.plex", \%layout_config, %opts;
#Run any initialisation code for page layout the layout
$layout->setup;#render;
## Create url tables which create outputs relative to output directories
# The relative table is passed to the template at that dir level to allow
# correct relative resolving of resources
my %dir_table;
for my $input_path(keys %url_table){
my $output_path=$url_table{$input_path};
my $dir=dirname $output_path;
next if $dir_table{$dir};
my $base=basename $output_path;
for my $input_path (keys %url_table){
my $output_path=$url_table{$input_path};
my $rel=abs2rel $output_path, $dir;
( run in 0.643 second using v1.01-cache-2.11-cpan-71847e10f99 )