Template-Plexsite

 view release on metacpan or  search on metacpan

script/build-menu.pl  view on Meta::CPAN

use strict;
use warnings;
no warnings "experimental";


#Url table maps input file paths relative to input root, to 
#output urls usable by a web client

#	$root is the root of the project. All inputs are ultimately relative to this location
#	$html_root is the output dir which contains your site/rendered/copied files
#
# The $location entry in a Plexsite template specified as an abs path. which is the OUTPUT url
# This is appended to the $html_root to give the location on disk

# local resources in a template are specifed relative to the template
#
#
# When processing a template a transformed url table is passed as a variable.
# The transformation makes all output urls relative to the current output level
#
#
# Each plt is preprocessed with it's own variable set
# A reference to a global url_table and nav hashes allows relative building


use Log::ger;
use Log::ger::Output "Screen";
use Log::ger::Util;

use Log::OK {
	lvl=>"info",
	opt=>"verbose"
};

Log::ger::Util::set_level(Log::OK::LEVEL);


use feature qw<say>;
use File::Basename qw<basename dirname>;
use File::Spec::Functions qw<rel2abs abs2rel>;
use Cwd qw<realpath>;
use File::Path qw<mkpath>;
use File::Copy;
use Data::Dumper;

use Template::Plex;
use Template::Plexsite;

use JSON;

#use GetOpt::Long;
use feature ":all";

my $html_root="site";

#Takes a list or multiple input templates
#Generates a table mapping template path to  output path and tag name

my %tag_table; #maps tags to outputs
my %url_table; #maps input filename to output urls

#Do preprocess

my @stages=("preprocess","process");


my %opts;
$opts{base}="Template::Plexsite";
$opts{use}=["Template::Plexsite"];
$opts{root}="src";

my %nav=(
	_data=>{
		label=>"TOP",
		href=>$url_table{"templates/about.plex"}
	}
);
\my $root=\$opts{root};


my $stage_count=1;
Log::OK::INFO and log_info "Stage $stage_count: Building url table from inputs";
$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;



( run in 1.329 second using v1.01-cache-2.11-cpan-af0e5977854 )