Template-Plexsite

 view release on metacpan or  search on metacpan

lib/Template/Plexsite.pm  view on Meta::CPAN

		$name=~s/\.plex$|\.plx$//;  #Ending in plex/plx extension
		$name=~s/(?:\.plex|\.plx)(?=\.)//;  #Not ending in plex/plx extension
	}

  my $no_locale=$config{output}{no_locale};
	my @comps=( 
    $no_locale?():($config{locale}//()),   #add locale only if we want it
    $config{output}{location}||(),                     #If no location ensure an empty list
                                                        #to force root
    $name);
	my $path=catfile @comps;
}


#When called updates the computed table entry output field
#CALLED FROM WITHING A TEMLPATE
sub output {
	my $self=shift;
	my %options=@_;
	my $output=$self->args->{output}||={};

	for(keys %options){

    # Clean up the location so it doesn't start with a slash
    # otherwise it breaks the output_path function
    #
    if($_ eq "location"){
      $options{$_}=~s|^/||;   
    }
    
		$output->{$_}=$options{$_};
	}
  #$output->{order}//=0;
	#update the table entry
	my $table=$self->args->{table}->table;
	my $entry=$table->{$self->args->{plt}};
	$entry->{output}=$self->output_path;
}

#Sets the values for a navigation item in a tree like structure
#CALLED FROM WITHIN A TEMPLATE
sub navi {
  my($self,%options)=@_;
  #Options include:
  # path: the path in the navitaiton tree
  # href: the explicit href for anchor. If not supplied defaul it the current page?
  # order:  relative ordering to other items at the same level
  # label:  whats actually shown 
  # icon:  graphics

  

  # URL table
	my $table=$self->args->{table}->table;

  # Table entry
	my $entry=$table->{$self->args->{plt}};

  \my %config=$entry->{template}{config};
  # Split the path and navigate to the level
  my @part=split m|/|, $options{path};

  my $parent=$config{nav}; #Root of nav object
  my $inc_path="";
  for my $part (@part){
    $parent = $parent->{$part}//={
      _data => {
        path=>$inc_path
      }
    };
    $inc_path .= "/";
  }


  #Copy the values
  my $data=$parent->{_data};
  for my ($k, $v) (%options){
      $data->{$k}=$v;
  }

  # Set the order to match render order if one wasn't supplied
  $data->{order}//=$entry->{template}{config}{output}{order};

  # If no href use the plt or the target
  $data->{href}//=$self->args->{target}//$self->args->{plt};

  #If just a fragment fix it to the plt path or target path
  if($data->{href} =~ /^#/){
    # Fragment ... append plt path
    $data->{href}=($self->args->{target}//$self->args->{plt}).$data->{href};
  }
}


sub lander {
	my $self=shift;
	my %options=@_;

	my $table=$self->args->{table}->table;
	my $entry=$table->{$self->args->{plt}};
	$entry->{lander}=\%options;

	
}

#Only works for plt templates
# Like a load call, but uses the information about the locale to 
# load a sub template
sub locale {
	my ($self, $lang_code)=@_;
	return $self->[locale_sub_template_] if $self->[locale_sub_template_];

	Log::OK::TRACE and log_trace __PACKAGE__." locale";
	my $dir=$self->meta->{_input_path};
	my $basename=basename $self->meta->{file};
	unless($lang_code){
		$lang_code=$self->args->{locale};
	}
	my $lang_template;
	if($lang_code){
		$lang_template=catfile $dir,$lang_code//(), $basename;



( run in 0.698 second using v1.01-cache-2.11-cpan-71847e10f99 )