# NOTE: Derived from web_diary_dir/lib/TDS/Collection.pm.
# Changes made here will be lost when autosplit again.
# See AutoSplit.pm.
package TDS::Collection;

#line 522 "web_diary_dir/lib/TDS/Collection.pm (autosplit into web_diary_dir/lib/auto/TDS/Collection/AsHTML.al)"
sub AsHTML($;$)
{
    my ($self, $params) = @_;

    $params->{topic} = $TDS::Status->topic;
    $params->{mode} = $TDS::Status->mode;
#    print "AsHTML...\n";
    my $html;

    # for all diarys
    require TDS::Cache;
    my $cache;
    
    my @htmls;
    my $s = (times)[0];
    for (@{$self->diarys}){
	if (ref $_ eq 'TDS::Tdf::Parser'){
	    my $parser = $_;
	    my $daily_html = $parser->top->AsHTML($params);
	    # auto complete
	    if ($AutoReplace){
		require TDS::Replacer;
		;TDS::Replacer->ReplaceLine(\$daily_html);
	    }
	    if ($TDS::Cache::EnableCache){
		require TDS::Cache::Daily;
		$cache = 
		    new TDS::Cache::Daily('reverse'=>$ReverseInRecent &&
					  $TDS::Status->mode =~ /RECENT/);
		$cache->Set($params->{'year'},
			    $params->{'month'},
			    $params->{'day'});
		if ($params->{'has_secret'}){
		    $cache->has_secret(1);
		    $TDS::Status->has_secret(1);
		}
		# if it has secret part, then do NOT write cache
		# return if $self->is_author && $self->has_secret;
		$cache->WriteCache($daily_html);
	    }
	    $html .= $daily_html;
##	    push(@htmls, $daily_html);
	} elsif (ref $_ eq 'TDS::Cache::Daily'){
#	    $html .= "cached" . ($_->prefix) . ($_->html);
	    $html .= $_->ReadCache;
##	    push(@htmls, $_->html);
	} else {
	    die "BUG: Collection::AsHTML: illegal reference";
	}
    }

    unless ($html){
	$html = $self->NoContentHook;
    }
    my $e = (times)[0];
##    warn times, " col AsHTML elasp: ", $e - $s;
    return $html;
##    return join('', @htmls);
}

# end of TDS::Collection::AsHTML
1;
