#!/usr/bin/perl
# ----------------------------------------------------------------------------
# This software is Copyright (C) 2007, All Rights Reserved
# ----------------------------------------------------------------------------
# This program is protected by local and international copyright laws. Any
# use of this program is subject to the the terms of the license agreement
# included as part of this distribution archive. Any other uses are strictly
# prohibited without the written permission of the Vendor and all
# other rights are reserved.
# -----------------------------------------------------------------------------
# Warning : Modifying this program violates your license agreement!
# -----------------------------------------------------------------------------

package IT::ArtMan::CustomMenus::Publish::SinglePages;

# load modules
use strict;

use IT::Globals;

# ------------------------------------------------------------------------------
# Function    : publish
# Description :
# Usage       : &IT::ArtMan::CustomMenus::Publish::SinglePages::publish($rule, $publishUpdatedOnly, $stepRef, $subStepRef);
# ------------------------------------------------------------------------------

sub publish {
  my $rule               = shift || die "no rule specified!\n";
  my $publishUpdatedOnly = shift;
  my $stepRef            = shift || die "no currentStepRef defined!\n";
  my $subStepRef         = shift || die "no currentSubStepRef defined!\n";
  my $publishAll         = !$publishUpdatedOnly;

  # does rule need publishing?
  my $ruleNeedsPublish   = $publishAll || $rule->{'alwaysPublish'};

  # display status message
  if ($ruleNeedsPublish)   { &IT::MultiStepOperations::addStatusMessage("Publishing: $rule->{'name'} ($rule->{'type'})\n"); }
  else                     { &IT::MultiStepOperations::addStatusMessage("No updates for: $rule->{'name'} ($rule->{'type'})\n"); }

  # publish page
  if ($ruleNeedsPublish) {
    my $currentArticle  = {};
    my $currentCategory = {};
    my $placeholders    = &IT::ArtMan::CustomMenus::Publish::createPlaceholders($currentCategory, $currentArticle, $rule->{'template'}, $rule->{'num'});
    my $html            = &template($rule->{'template'}, $placeholders);
    my $filepath        = &IT::ArtMan::CustomMenus::Publish::getFilePathAndCreateDirFor($rule, $currentCategory, $currentArticle);
    &IT::File::writeFileFast($filepath, $html);
  }

  #
  my $isStepComplete = 1;
  return $isStepComplete;
}

# ----------------------------------------------------------------------------
# end of file
1;

