// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using Rauchy.Regionerate.Domain.Entities;
namespace Rauchy.Regionerate.Shared.Components.Rendering
{
public static class RenderingCentral
{
#region Methods (1)
// Public Methods (1)
// [rgn] Public Methods (1)
public static string Render( Code code, CodeLayout.Configuration configuration )
{
if ( code is Region )
{
Region region = code as Region;
ICodeRenderer renderer = RegionRenderer.CreateNew( region.Style, configuration );
return renderer.Render( region );
}
else if ( code is ExistingRegion )
{
string renderedText = Environment.NewLine + Environment.NewLine;
string codeText = code.ToString();
string trimmedCodeText = codeText.TrimNewLinesFromStart();
renderedText += trimmedCodeText;
return renderedText;
}
else if ( code is ContainerTypeCode )
{
ContainerTypeCode containerTypeCode = code as ContainerTypeCode;
ICodeRenderer renderer = new ContainerTypeRenderer( configuration );
return renderer.Render( containerTypeCode );
}
else
{
string codeString = code.ToString();
string startTrimmedCodeString = codeString.TrimNewLinesFromStart();
string trimmedCode = startTrimmedCodeString.TrimEnd();
if ( trimmedCode.Length == 0 )
{
return code.ToString();
}
else
{
return trimmedCode + Environment.NewLine;
}
}
}
#endregion Methods
}
}