diff --git a/mustache-sharp.test/FormatCompilerTester.cs b/mustache-sharp.test/FormatCompilerTester.cs index a05cb60..f3c3b13 100644 --- a/mustache-sharp.test/FormatCompilerTester.cs +++ b/mustache-sharp.test/FormatCompilerTester.cs @@ -4,7 +4,7 @@ using System.IO; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace mustache.test +namespace Mustache.Test { /// /// Tests the FormatParser class. diff --git a/mustache-sharp.test/Properties/AssemblyInfo.cs b/mustache-sharp.test/Properties/AssemblyInfo.cs index ea38851..ca24713 100644 --- a/mustache-sharp.test/Properties/AssemblyInfo.cs +++ b/mustache-sharp.test/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.0.7.2")] -[assembly: AssemblyFileVersion("0.0.7.2")] +[assembly: AssemblyVersion("0.1.0.0")] +[assembly: AssemblyFileVersion("0.1.0.0")] diff --git a/mustache-sharp.test/mustache-sharp.test.csproj b/mustache-sharp.test/mustache-sharp.test.csproj index 81de5b3..0457468 100644 --- a/mustache-sharp.test/mustache-sharp.test.csproj +++ b/mustache-sharp.test/mustache-sharp.test.csproj @@ -1,63 +1,63 @@ - - - - Debug - AnyCPU - - - 2.0 - {7F607362-0680-4751-B1DC-621219294AE3} - Library - Properties - mustache.test - mustache-sharp.test - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - False - - - - - - - - - {D71B378F-A4BA-4263-A4F0-07A49A0C528D} - mustache-sharp - - - - + + + + Debug + AnyCPU + + + 2.0 + {7F607362-0680-4751-B1DC-621219294AE3} + Library + Properties + Mustache.Test + mustache-sharp.test + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + False + + + + + + + + + {D71B378F-A4BA-4263-A4F0-07A49A0C528D} + mustache-sharp + + + + \ No newline at end of file diff --git a/mustache-sharp/ArgumentCollection.cs b/mustache-sharp/ArgumentCollection.cs index a216ab3..0bdafe2 100644 --- a/mustache-sharp/ArgumentCollection.cs +++ b/mustache-sharp/ArgumentCollection.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -namespace mustache +namespace Mustache { /// /// Associates parameters to their argument values. diff --git a/mustache-sharp/CompoundGenerator.cs b/mustache-sharp/CompoundGenerator.cs index a6fb146..aa7227f 100644 --- a/mustache-sharp/CompoundGenerator.cs +++ b/mustache-sharp/CompoundGenerator.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; -namespace mustache +namespace Mustache { /// /// Builds text by combining the output of other generators. diff --git a/mustache-sharp/ConditionTagDefinition.cs b/mustache-sharp/ConditionTagDefinition.cs index 14e1d82..3363626 100644 --- a/mustache-sharp/ConditionTagDefinition.cs +++ b/mustache-sharp/ConditionTagDefinition.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -namespace mustache +namespace Mustache { /// /// Defines a tag that conditionally prints its content. diff --git a/mustache-sharp/ContentTagDefinition.cs b/mustache-sharp/ContentTagDefinition.cs index 2fe16df..5fea260 100644 --- a/mustache-sharp/ContentTagDefinition.cs +++ b/mustache-sharp/ContentTagDefinition.cs @@ -1,38 +1,38 @@ -using System; - -namespace mustache -{ - /// - /// Defines a tag that can contain inner text. - /// - public abstract class ContentTagDefinition : TagDefinition - { - /// - /// Initializes a new instance of a ContentTagDefinition. - /// - /// The name of the tag being defined. - protected ContentTagDefinition(string tagName) - : base(tagName) - { - } - - /// - /// Initializes a new instance of a ContentTagDefinition. - /// - /// The name of the tag being defined. - /// Specifies whether the tag is a built-in tag. - internal ContentTagDefinition(string tagName, bool isBuiltin) - : base(tagName, isBuiltin) - { - } - - /// - /// Gets or sets whether the tag can have content. - /// - /// True if the tag can have a body; otherwise, false. - protected override bool GetHasContent() - { - return true; - } - } -} +using System; + +namespace Mustache +{ + /// + /// Defines a tag that can contain inner text. + /// + public abstract class ContentTagDefinition : TagDefinition + { + /// + /// Initializes a new instance of a ContentTagDefinition. + /// + /// The name of the tag being defined. + protected ContentTagDefinition(string tagName) + : base(tagName) + { + } + + /// + /// Initializes a new instance of a ContentTagDefinition. + /// + /// The name of the tag being defined. + /// Specifies whether the tag is a built-in tag. + internal ContentTagDefinition(string tagName, bool isBuiltin) + : base(tagName, isBuiltin) + { + } + + /// + /// Gets or sets whether the tag can have content. + /// + /// True if the tag can have a body; otherwise, false. + protected override bool GetHasContent() + { + return true; + } + } +} diff --git a/mustache-sharp/Context.cs b/mustache-sharp/Context.cs index 6e754b6..2a6c249 100644 --- a/mustache-sharp/Context.cs +++ b/mustache-sharp/Context.cs @@ -1,6 +1,6 @@ using System; -namespace mustache +namespace Mustache { /// /// Represents a context within a template. diff --git a/mustache-sharp/ContextParameter.cs b/mustache-sharp/ContextParameter.cs index 2cc19b3..57fbe52 100644 --- a/mustache-sharp/ContextParameter.cs +++ b/mustache-sharp/ContextParameter.cs @@ -1,6 +1,6 @@ using System; -namespace mustache +namespace Mustache { /// /// Holds information describing a parameter that creates a new context. diff --git a/mustache-sharp/EachTagDefinition.cs b/mustache-sharp/EachTagDefinition.cs index 3d798d7..54ca2b6 100644 --- a/mustache-sharp/EachTagDefinition.cs +++ b/mustache-sharp/EachTagDefinition.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; -namespace mustache +namespace Mustache { /// /// Defines a tag that can iterate over a collection of items and render diff --git a/mustache-sharp/ElifTagDefinition.cs b/mustache-sharp/ElifTagDefinition.cs index 38b5601..0d5b221 100644 --- a/mustache-sharp/ElifTagDefinition.cs +++ b/mustache-sharp/ElifTagDefinition.cs @@ -1,35 +1,35 @@ -using System; -using System.Collections.Generic; - -namespace mustache -{ - /// - /// Defines a tag that conditionally renders its content if preceding if and elif tags fail. - /// - internal sealed class ElifTagDefinition : ConditionTagDefinition - { - /// - /// Initializes a new instance of an ElifTagDefinition. - /// - public ElifTagDefinition() - : base("elif") - { - } - - /// - /// Gets whether the tag only exists within the scope of its parent. - /// - protected override bool GetIsContextSensitive() - { - return true; - } - - /// - /// Gets the tags that indicate the end of the current tags context. - /// - protected override IEnumerable GetClosingTags() - { - return new string[] { "if" }; - } - } -} +using System; +using System.Collections.Generic; + +namespace Mustache +{ + /// + /// Defines a tag that conditionally renders its content if preceding if and elif tags fail. + /// + internal sealed class ElifTagDefinition : ConditionTagDefinition + { + /// + /// Initializes a new instance of an ElifTagDefinition. + /// + public ElifTagDefinition() + : base("elif") + { + } + + /// + /// Gets whether the tag only exists within the scope of its parent. + /// + protected override bool GetIsContextSensitive() + { + return true; + } + + /// + /// Gets the tags that indicate the end of the current tags context. + /// + protected override IEnumerable GetClosingTags() + { + return new string[] { "if" }; + } + } +} diff --git a/mustache-sharp/ElseTagDefinition.cs b/mustache-sharp/ElseTagDefinition.cs index 08f5aff..04635ab 100644 --- a/mustache-sharp/ElseTagDefinition.cs +++ b/mustache-sharp/ElseTagDefinition.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace mustache +namespace Mustache { /// /// Defines a tag that renders its content if all preceding if and elif tags. diff --git a/mustache-sharp/FormatCompiler.cs b/mustache-sharp/FormatCompiler.cs index c81e6dc..1f211d2 100644 --- a/mustache-sharp/FormatCompiler.cs +++ b/mustache-sharp/FormatCompiler.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using mustache.Properties; +using Mustache.Properties; -namespace mustache +namespace Mustache { /// /// Parses a format string and returns a text generator. diff --git a/mustache-sharp/Generator.cs b/mustache-sharp/Generator.cs index f182251..f0b51b8 100644 --- a/mustache-sharp/Generator.cs +++ b/mustache-sharp/Generator.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; -namespace mustache +namespace Mustache { /// /// Generates text by substituting an object's values for placeholders. diff --git a/mustache-sharp/IGenerator.cs b/mustache-sharp/IGenerator.cs index ca883b5..5f16d18 100644 --- a/mustache-sharp/IGenerator.cs +++ b/mustache-sharp/IGenerator.cs @@ -1,19 +1,19 @@ -using System; -using System.IO; - -namespace mustache -{ - /// - /// Applies the values of an object to the format plan, generating a string. - /// - internal interface IGenerator - { - /// - /// Generates the text when applying the format plan. - /// - /// The current lexical scope of the keys. - /// The text writer to send all text to. - /// The generated text. - void GetText(KeyScope scope, TextWriter writer); - } -} +using System; +using System.IO; + +namespace Mustache +{ + /// + /// Applies the values of an object to the format plan, generating a string. + /// + internal interface IGenerator + { + /// + /// Generates the text when applying the format plan. + /// + /// The current lexical scope of the keys. + /// The text writer to send all text to. + /// The generated text. + void GetText(KeyScope scope, TextWriter writer); + } +} diff --git a/mustache-sharp/IfTagDefinition.cs b/mustache-sharp/IfTagDefinition.cs index 1287f09..f03e1f8 100644 --- a/mustache-sharp/IfTagDefinition.cs +++ b/mustache-sharp/IfTagDefinition.cs @@ -1,27 +1,27 @@ -using System; - -namespace mustache -{ - /// - /// Defines a tag that renders its content depending on the truthyness - /// of its argument, with optional elif and else nested tags. - /// - internal sealed class IfTagDefinition : ConditionTagDefinition - { - /// - /// Initializes a new instance of a IfTagDefinition. - /// - public IfTagDefinition() - : base("if") - { - } - - /// - /// Gets whether the tag only exists within the scope of its parent. - /// - protected override bool GetIsContextSensitive() - { - return false; - } - } -} +using System; + +namespace Mustache +{ + /// + /// Defines a tag that renders its content depending on the truthyness + /// of its argument, with optional elif and else nested tags. + /// + internal sealed class IfTagDefinition : ConditionTagDefinition + { + /// + /// Initializes a new instance of a IfTagDefinition. + /// + public IfTagDefinition() + : base("if") + { + } + + /// + /// Gets whether the tag only exists within the scope of its parent. + /// + protected override bool GetIsContextSensitive() + { + return false; + } + } +} diff --git a/mustache-sharp/InlineGenerator.cs b/mustache-sharp/InlineGenerator.cs index d244a05..c1fb2c7 100644 --- a/mustache-sharp/InlineGenerator.cs +++ b/mustache-sharp/InlineGenerator.cs @@ -1,32 +1,32 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace mustache -{ - /// - /// Generates the text for a tag that only exists on a single line. - /// - internal sealed class InlineGenerator : IGenerator - { - private readonly TagDefinition _definition; - private readonly ArgumentCollection _arguments; - - /// - /// Initializes a new instance of an InlineGenerator. - /// - /// The tag to render the text for. - /// The arguments passed to the tag. - public InlineGenerator(TagDefinition definition, ArgumentCollection arguments) - { - _definition = definition; - _arguments = arguments; - } - - void IGenerator.GetText(KeyScope scope, TextWriter writer) - { - Dictionary arguments = _arguments.GetArguments(scope); - _definition.GetText(writer, arguments); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; + +namespace Mustache +{ + /// + /// Generates the text for a tag that only exists on a single line. + /// + internal sealed class InlineGenerator : IGenerator + { + private readonly TagDefinition _definition; + private readonly ArgumentCollection _arguments; + + /// + /// Initializes a new instance of an InlineGenerator. + /// + /// The tag to render the text for. + /// The arguments passed to the tag. + public InlineGenerator(TagDefinition definition, ArgumentCollection arguments) + { + _definition = definition; + _arguments = arguments; + } + + void IGenerator.GetText(KeyScope scope, TextWriter writer) + { + Dictionary arguments = _arguments.GetArguments(scope); + _definition.GetText(writer, arguments); + } + } +} diff --git a/mustache-sharp/InlineTagDefinition.cs b/mustache-sharp/InlineTagDefinition.cs index b658b51..04d45d4 100644 --- a/mustache-sharp/InlineTagDefinition.cs +++ b/mustache-sharp/InlineTagDefinition.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; -namespace mustache +namespace Mustache { /// /// Defines a tag that cannot contain inner text. diff --git a/mustache-sharp/KeyFoundEventArgs.cs b/mustache-sharp/KeyFoundEventArgs.cs index e3c2251..7a97e61 100644 --- a/mustache-sharp/KeyFoundEventArgs.cs +++ b/mustache-sharp/KeyFoundEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace mustache +namespace Mustache { /// /// Holds the information about a key that was found. diff --git a/mustache-sharp/KeyGenerator.cs b/mustache-sharp/KeyGenerator.cs index 2675ccb..6dbe146 100644 --- a/mustache-sharp/KeyGenerator.cs +++ b/mustache-sharp/KeyGenerator.cs @@ -1,51 +1,51 @@ -using System; -using System.IO; -using System.Text; - -namespace mustache -{ - /// - /// Substitutes a key placeholder with the textual representation of the associated object. - /// - internal sealed class KeyGenerator : IGenerator - { - private readonly string _key; - private readonly string _format; - - /// - /// Initializes a new instance of a KeyGenerator. - /// - /// The key to substitute with its value. - /// The alignment specifier. - /// The format specifier. - public KeyGenerator(string key, string alignment, string formatting) - { - _key = key; - _format = getFormat(alignment, formatting); - } - - private static string getFormat(string alignment, string formatting) - { - StringBuilder formatBuilder = new StringBuilder(); - formatBuilder.Append("{0"); - if (!String.IsNullOrWhiteSpace(alignment)) - { - formatBuilder.Append(","); - formatBuilder.Append(alignment.TrimStart('+')); - } - if (!String.IsNullOrWhiteSpace(formatting)) - { - formatBuilder.Append(":"); - formatBuilder.Append(formatting); - } - formatBuilder.Append("}"); - return formatBuilder.ToString(); - } - - void IGenerator.GetText(KeyScope scope, TextWriter writer) - { - object value = scope.Find(_key); - writer.Write(_format, value); - } - } -} +using System; +using System.IO; +using System.Text; + +namespace Mustache +{ + /// + /// Substitutes a key placeholder with the textual representation of the associated object. + /// + internal sealed class KeyGenerator : IGenerator + { + private readonly string _key; + private readonly string _format; + + /// + /// Initializes a new instance of a KeyGenerator. + /// + /// The key to substitute with its value. + /// The alignment specifier. + /// The format specifier. + public KeyGenerator(string key, string alignment, string formatting) + { + _key = key; + _format = getFormat(alignment, formatting); + } + + private static string getFormat(string alignment, string formatting) + { + StringBuilder formatBuilder = new StringBuilder(); + formatBuilder.Append("{0"); + if (!String.IsNullOrWhiteSpace(alignment)) + { + formatBuilder.Append(","); + formatBuilder.Append(alignment.TrimStart('+')); + } + if (!String.IsNullOrWhiteSpace(formatting)) + { + formatBuilder.Append(":"); + formatBuilder.Append(formatting); + } + formatBuilder.Append("}"); + return formatBuilder.ToString(); + } + + void IGenerator.GetText(KeyScope scope, TextWriter writer) + { + object value = scope.Find(_key); + writer.Write(_format, value); + } + } +} diff --git a/mustache-sharp/KeyNotFoundEventArgs.cs b/mustache-sharp/KeyNotFoundEventArgs.cs index 2a54208..f29b69e 100644 --- a/mustache-sharp/KeyNotFoundEventArgs.cs +++ b/mustache-sharp/KeyNotFoundEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace mustache +namespace Mustache { /// /// Holds the information needed to handle a missing key. diff --git a/mustache-sharp/KeyScope.cs b/mustache-sharp/KeyScope.cs index 9f5bf02..7e176d9 100644 --- a/mustache-sharp/KeyScope.cs +++ b/mustache-sharp/KeyScope.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using mustache.Properties; +using Mustache.Properties; -namespace mustache +namespace Mustache { /// /// Represents a scope of keys. diff --git a/mustache-sharp/MasterTagDefinition.cs b/mustache-sharp/MasterTagDefinition.cs index b733def..4cfd990 100644 --- a/mustache-sharp/MasterTagDefinition.cs +++ b/mustache-sharp/MasterTagDefinition.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace mustache +namespace Mustache { /// /// Defines a pseudo tag that wraps the entire content of a format string. diff --git a/mustache-sharp/NestedContext.cs b/mustache-sharp/NestedContext.cs index 7838c38..090706a 100644 --- a/mustache-sharp/NestedContext.cs +++ b/mustache-sharp/NestedContext.cs @@ -1,49 +1,49 @@ -using System; -using System.IO; - -namespace mustache -{ - /// - /// Holds the objects to use when processing a child context of another tag. - /// - public sealed class NestedContext - { - /// - /// Initializes a new instance of a NestedContext. - /// - public NestedContext() - { - } - - /// - /// Gets or sets the writer to use when generating the child context. - /// - /// Setting the writer to null will indicate that the tag's writer should be used. - public TextWriter Writer - { - get; - set; - } - - /// - /// Gets or sets whether the text sent to the returned writer needs to be added - /// to the parent tag's writer. This should be false if the parent writer is - /// being returned or is being wrapped. - /// - public bool WriterNeedsConsidated - { - get; - set; - } - - /// - /// Gets or sets the scope to use when generating the child context. - /// - /// Setting the scope to null will indicate that the current scope should be used. - public KeyScope KeyScope - { - get; - set; - } - } -} +using System; +using System.IO; + +namespace Mustache +{ + /// + /// Holds the objects to use when processing a child context of another tag. + /// + public sealed class NestedContext + { + /// + /// Initializes a new instance of a NestedContext. + /// + public NestedContext() + { + } + + /// + /// Gets or sets the writer to use when generating the child context. + /// + /// Setting the writer to null will indicate that the tag's writer should be used. + public TextWriter Writer + { + get; + set; + } + + /// + /// Gets or sets whether the text sent to the returned writer needs to be added + /// to the parent tag's writer. This should be false if the parent writer is + /// being returned or is being wrapped. + /// + public bool WriterNeedsConsidated + { + get; + set; + } + + /// + /// Gets or sets the scope to use when generating the child context. + /// + /// Setting the scope to null will indicate that the current scope should be used. + public KeyScope KeyScope + { + get; + set; + } + } +} diff --git a/mustache-sharp/PlaceholderFoundEventArgs.cs b/mustache-sharp/PlaceholderFoundEventArgs.cs index 9f55b04..e415512 100644 --- a/mustache-sharp/PlaceholderFoundEventArgs.cs +++ b/mustache-sharp/PlaceholderFoundEventArgs.cs @@ -1,7 +1,7 @@ using System; -using mustache.Properties; +using Mustache.Properties; -namespace mustache +namespace Mustache { /// /// Holds the information descibing a key that is found in a template. diff --git a/mustache-sharp/Properties/AssemblyInfo.cs b/mustache-sharp/Properties/AssemblyInfo.cs index c413d0b..ce96e76 100644 --- a/mustache-sharp/Properties/AssemblyInfo.cs +++ b/mustache-sharp/Properties/AssemblyInfo.cs @@ -34,6 +34,6 @@ using System.Runtime.CompilerServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.7.2")] -[assembly: AssemblyFileVersion("0.0.7.2")] +[assembly: AssemblyVersion("0.1.0.0")] +[assembly: AssemblyFileVersion("0.1.0.0")] [assembly: InternalsVisibleTo("mustache-sharp.test")] \ No newline at end of file diff --git a/mustache-sharp/Properties/Resources.Designer.cs b/mustache-sharp/Properties/Resources.Designer.cs index 27739af..3257d4e 100644 --- a/mustache-sharp/Properties/Resources.Designer.cs +++ b/mustache-sharp/Properties/Resources.Designer.cs @@ -1,135 +1,135 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.296 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace mustache.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("mustache.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to An attempt was made to define a parameter with a null or an invalid identifier.. - /// - internal static string BlankParameterName { - get { - return ResourceManager.GetString("BlankParameterName", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to An attempt was made to define a tag with a null or an invalid identifier.. - /// - internal static string BlankTagName { - get { - return ResourceManager.GetString("BlankTagName", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A parameter with the same name already exists within the tag.. - /// - internal static string DuplicateParameter { - get { - return ResourceManager.GetString("DuplicateParameter", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The {0} tag has already been registered.. - /// - internal static string DuplicateTagDefinition { - get { - return ResourceManager.GetString("DuplicateTagDefinition", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The key {0} could not be found.. - /// - internal static string KeyNotFound { - get { - return ResourceManager.GetString("KeyNotFound", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Expected a matching {0} tag but none was found.. - /// - internal static string MissingClosingTag { - get { - return ResourceManager.GetString("MissingClosingTag", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Encountered an unknown tag. It was either not registered or exists in a different context.. - /// - internal static string UnknownTag { - get { - return ResourceManager.GetString("UnknownTag", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The wrong number of arguments were passed to an {0} tag.. - /// - internal static string WrongNumberOfArguments { - get { - return ResourceManager.GetString("WrongNumberOfArguments", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.296 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Mustache.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Mustache.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to An attempt was made to define a parameter with a null or an invalid identifier.. + /// + internal static string BlankParameterName { + get { + return ResourceManager.GetString("BlankParameterName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to An attempt was made to define a tag with a null or an invalid identifier.. + /// + internal static string BlankTagName { + get { + return ResourceManager.GetString("BlankTagName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A parameter with the same name already exists within the tag.. + /// + internal static string DuplicateParameter { + get { + return ResourceManager.GetString("DuplicateParameter", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The {0} tag has already been registered.. + /// + internal static string DuplicateTagDefinition { + get { + return ResourceManager.GetString("DuplicateTagDefinition", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The key {0} could not be found.. + /// + internal static string KeyNotFound { + get { + return ResourceManager.GetString("KeyNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Expected a matching {0} tag but none was found.. + /// + internal static string MissingClosingTag { + get { + return ResourceManager.GetString("MissingClosingTag", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Encountered an unknown tag. It was either not registered or exists in a different context.. + /// + internal static string UnknownTag { + get { + return ResourceManager.GetString("UnknownTag", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The wrong number of arguments were passed to an {0} tag.. + /// + internal static string WrongNumberOfArguments { + get { + return ResourceManager.GetString("WrongNumberOfArguments", resourceCulture); + } + } + } +} diff --git a/mustache-sharp/PropertyDictionary.cs b/mustache-sharp/PropertyDictionary.cs index dc5264d..4d4f3fa 100644 --- a/mustache-sharp/PropertyDictionary.cs +++ b/mustache-sharp/PropertyDictionary.cs @@ -1,237 +1,237 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; - -namespace mustache -{ - /// - /// Provides methods for creating instances of PropertyDictionary. - /// - internal sealed class PropertyDictionary : IDictionary - { - private static readonly Dictionary> _cache = new Dictionary>(); - - private readonly object _instance; - private readonly Dictionary _typeCache; - - /// - /// Initializes a new instance of a PropertyDictionary. - /// - /// The instance to wrap in the PropertyDictionary. - public PropertyDictionary(object instance) - { - _instance = instance; - if (instance == null) - { - _typeCache = new Dictionary(); - } - else - { - _typeCache = getCacheType(_instance); - } - } - - private static Dictionary getCacheType(object instance) - { - Type type = instance.GetType(); - Dictionary typeCache; - if (!_cache.TryGetValue(type, out typeCache)) - { - typeCache = new Dictionary(); - BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy; - foreach (PropertyInfo propertyInfo in type.GetProperties(flags)) - { - if (!propertyInfo.IsSpecialName) - { - typeCache.Add(propertyInfo.Name, propertyInfo); - } - } - _cache.Add(type, typeCache); - } - return typeCache; - } - - /// - /// Gets the underlying instance. - /// - public object Instance - { - get { return _instance; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - void IDictionary.Add(string key, object value) - { - throw new NotSupportedException(); - } - - /// - /// Determines whether a property with the given name exists. - /// - /// The name of the property. - /// True if the property exists; otherwise, false. - public bool ContainsKey(string key) - { - return _typeCache.ContainsKey(key); - } - - /// - /// Gets the name of the properties in the type. - /// - public ICollection Keys - { - get { return _typeCache.Keys; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - bool IDictionary.Remove(string key) - { - throw new NotSupportedException(); - } - - /// - /// Tries to get the value for the given property name. - /// - /// The name of the property to get the value for. - /// The variable to store the value of the property or the default value if the property is not found. - /// True if a property with the given name is found; otherwise, false. - /// The name of the property was null. - public bool TryGetValue(string key, out object value) - { - PropertyInfo propertyInfo; - if (!_typeCache.TryGetValue(key, out propertyInfo)) - { - value = null; - return false; - } - value = getValue(propertyInfo); - return true; - } - - /// - /// Gets the values of all of the properties in the object. - /// - public ICollection Values - { - get - { - ICollection propertyInfos = _typeCache.Values; - List values = new List(); - foreach (PropertyInfo propertyInfo in propertyInfos) - { - object value = getValue(propertyInfo); - values.Add(value); - } - return values.AsReadOnly(); - } - } - - /// - /// Gets or sets the value of the property with the given name. - /// - /// The name of the property to get or set. - /// The value of the property with the given name. - /// The property name was null. - /// The type does not have a property with the given name. - /// The property did not support getting or setting. - /// - /// The object does not match the target type, or a property is a value type but the value is null. - /// - public object this[string key] - { - get - { - PropertyInfo propertyInfo = _typeCache[key]; - return getValue(propertyInfo); - } - [EditorBrowsable(EditorBrowsableState.Never)] - set - { - throw new NotSupportedException(); - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - void ICollection>.Add(KeyValuePair item) - { - throw new NotSupportedException(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - void ICollection>.Clear() - { - throw new NotSupportedException(); - } - - bool ICollection>.Contains(KeyValuePair item) - { - PropertyInfo propertyInfo; - if (!_typeCache.TryGetValue(item.Key, out propertyInfo)) - { - return false; - } - object value = getValue(propertyInfo); - return Equals(item.Value, value); - } - - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) - { - List> pairs = new List>(); - ICollection> collection = _typeCache; - foreach (KeyValuePair pair in collection) - { - PropertyInfo propertyInfo = pair.Value; - object value = getValue(propertyInfo); - pairs.Add(new KeyValuePair(pair.Key, value)); - } - pairs.CopyTo(array, arrayIndex); - } - - /// - /// Gets the number of properties in the type. - /// - public int Count - { - get { return _typeCache.Count; } - } - - /// - /// Gets or sets whether updates will be ignored. - /// - bool ICollection>.IsReadOnly - { - get { return true; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - bool ICollection>.Remove(KeyValuePair item) - { - throw new NotSupportedException(); - } - - /// - /// Gets the propety name/value pairs in the object. - /// - /// - public IEnumerator> GetEnumerator() - { - foreach (KeyValuePair pair in _typeCache) - { - object value = getValue(pair.Value); - yield return new KeyValuePair(pair.Key, value); - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - private object getValue(PropertyInfo propertyInfo) - { - return propertyInfo.GetValue(_instance, null); - } - } +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; + +namespace Mustache +{ + /// + /// Provides methods for creating instances of PropertyDictionary. + /// + internal sealed class PropertyDictionary : IDictionary + { + private static readonly Dictionary> _cache = new Dictionary>(); + + private readonly object _instance; + private readonly Dictionary _typeCache; + + /// + /// Initializes a new instance of a PropertyDictionary. + /// + /// The instance to wrap in the PropertyDictionary. + public PropertyDictionary(object instance) + { + _instance = instance; + if (instance == null) + { + _typeCache = new Dictionary(); + } + else + { + _typeCache = getCacheType(_instance); + } + } + + private static Dictionary getCacheType(object instance) + { + Type type = instance.GetType(); + Dictionary typeCache; + if (!_cache.TryGetValue(type, out typeCache)) + { + typeCache = new Dictionary(); + BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy; + foreach (PropertyInfo propertyInfo in type.GetProperties(flags)) + { + if (!propertyInfo.IsSpecialName) + { + typeCache.Add(propertyInfo.Name, propertyInfo); + } + } + _cache.Add(type, typeCache); + } + return typeCache; + } + + /// + /// Gets the underlying instance. + /// + public object Instance + { + get { return _instance; } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + void IDictionary.Add(string key, object value) + { + throw new NotSupportedException(); + } + + /// + /// Determines whether a property with the given name exists. + /// + /// The name of the property. + /// True if the property exists; otherwise, false. + public bool ContainsKey(string key) + { + return _typeCache.ContainsKey(key); + } + + /// + /// Gets the name of the properties in the type. + /// + public ICollection Keys + { + get { return _typeCache.Keys; } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + bool IDictionary.Remove(string key) + { + throw new NotSupportedException(); + } + + /// + /// Tries to get the value for the given property name. + /// + /// The name of the property to get the value for. + /// The variable to store the value of the property or the default value if the property is not found. + /// True if a property with the given name is found; otherwise, false. + /// The name of the property was null. + public bool TryGetValue(string key, out object value) + { + PropertyInfo propertyInfo; + if (!_typeCache.TryGetValue(key, out propertyInfo)) + { + value = null; + return false; + } + value = getValue(propertyInfo); + return true; + } + + /// + /// Gets the values of all of the properties in the object. + /// + public ICollection Values + { + get + { + ICollection propertyInfos = _typeCache.Values; + List values = new List(); + foreach (PropertyInfo propertyInfo in propertyInfos) + { + object value = getValue(propertyInfo); + values.Add(value); + } + return values.AsReadOnly(); + } + } + + /// + /// Gets or sets the value of the property with the given name. + /// + /// The name of the property to get or set. + /// The value of the property with the given name. + /// The property name was null. + /// The type does not have a property with the given name. + /// The property did not support getting or setting. + /// + /// The object does not match the target type, or a property is a value type but the value is null. + /// + public object this[string key] + { + get + { + PropertyInfo propertyInfo = _typeCache[key]; + return getValue(propertyInfo); + } + [EditorBrowsable(EditorBrowsableState.Never)] + set + { + throw new NotSupportedException(); + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + void ICollection>.Add(KeyValuePair item) + { + throw new NotSupportedException(); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + void ICollection>.Clear() + { + throw new NotSupportedException(); + } + + bool ICollection>.Contains(KeyValuePair item) + { + PropertyInfo propertyInfo; + if (!_typeCache.TryGetValue(item.Key, out propertyInfo)) + { + return false; + } + object value = getValue(propertyInfo); + return Equals(item.Value, value); + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + List> pairs = new List>(); + ICollection> collection = _typeCache; + foreach (KeyValuePair pair in collection) + { + PropertyInfo propertyInfo = pair.Value; + object value = getValue(propertyInfo); + pairs.Add(new KeyValuePair(pair.Key, value)); + } + pairs.CopyTo(array, arrayIndex); + } + + /// + /// Gets the number of properties in the type. + /// + public int Count + { + get { return _typeCache.Count; } + } + + /// + /// Gets or sets whether updates will be ignored. + /// + bool ICollection>.IsReadOnly + { + get { return true; } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + bool ICollection>.Remove(KeyValuePair item) + { + throw new NotSupportedException(); + } + + /// + /// Gets the propety name/value pairs in the object. + /// + /// + public IEnumerator> GetEnumerator() + { + foreach (KeyValuePair pair in _typeCache) + { + object value = getValue(pair.Value); + yield return new KeyValuePair(pair.Key, value); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + private object getValue(PropertyInfo propertyInfo) + { + return propertyInfo.GetValue(_instance, null); + } + } } \ No newline at end of file diff --git a/mustache-sharp/RegexHelper.cs b/mustache-sharp/RegexHelper.cs index ad2b715..58cf7a3 100644 --- a/mustache-sharp/RegexHelper.cs +++ b/mustache-sharp/RegexHelper.cs @@ -1,7 +1,7 @@ using System; using System.Text.RegularExpressions; -namespace mustache +namespace Mustache { /// /// Provides utility methods that require regular expressions. diff --git a/mustache-sharp/StaticGenerator.cs b/mustache-sharp/StaticGenerator.cs index 39ee8d4..7ed6b4d 100644 --- a/mustache-sharp/StaticGenerator.cs +++ b/mustache-sharp/StaticGenerator.cs @@ -1,54 +1,54 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace mustache -{ - /// - /// Generates a static block of text. - /// - internal sealed class StaticGenerator : IGenerator - { - /// - /// Initializes a new instance of a StaticGenerator. - /// - public StaticGenerator() - { - } - - /// - /// Gets or sets the linked list node containing the current generator. - /// - public LinkedListNode Node - { - get; - set; - } - - /// - /// Gets or sets the static text. - /// - public string Value - { - get; - set; - } - - /// - /// Removes the static text from the final output. - /// - public void Prune() - { - if (Node != null) - { - Node.List.Remove(Node); - Node = null; - } - } - - void IGenerator.GetText(KeyScope scope, TextWriter writer) - { - writer.Write(Value); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; + +namespace Mustache +{ + /// + /// Generates a static block of text. + /// + internal sealed class StaticGenerator : IGenerator + { + /// + /// Initializes a new instance of a StaticGenerator. + /// + public StaticGenerator() + { + } + + /// + /// Gets or sets the linked list node containing the current generator. + /// + public LinkedListNode Node + { + get; + set; + } + + /// + /// Gets or sets the static text. + /// + public string Value + { + get; + set; + } + + /// + /// Removes the static text from the final output. + /// + public void Prune() + { + if (Node != null) + { + Node.List.Remove(Node); + Node = null; + } + } + + void IGenerator.GetText(KeyScope scope, TextWriter writer) + { + writer.Write(Value); + } + } +} diff --git a/mustache-sharp/TagDefinition.cs b/mustache-sharp/TagDefinition.cs index 45fe938..2d3ce02 100644 --- a/mustache-sharp/TagDefinition.cs +++ b/mustache-sharp/TagDefinition.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using mustache.Properties; +using Mustache.Properties; using System.IO; -namespace mustache +namespace Mustache { /// /// Defines the attributes of a custom tag. diff --git a/mustache-sharp/TagParameter.cs b/mustache-sharp/TagParameter.cs index 5b141c5..07235c0 100644 --- a/mustache-sharp/TagParameter.cs +++ b/mustache-sharp/TagParameter.cs @@ -1,54 +1,54 @@ -using System; -using mustache.Properties; - -namespace mustache -{ - /// - /// Defines a parameter belonging to a custom tag. - /// - public sealed class TagParameter - { - private readonly string _name; - - /// - /// Initializes a new instance of a TagParameter. - /// - /// The name of the parameter. - /// The parameter name is null or an invalid identifier. - public TagParameter(string parameterName) - { - if (!RegexHelper.IsValidIdentifier(parameterName)) - { - throw new ArgumentException(Resources.BlankParameterName, "parameterName"); - } - _name = parameterName; - } - - /// - /// Gets the name of the parameter. - /// - public string Name - { - get { return _name; } - } - - /// - /// Gets or sets whether the field is required. - /// - public bool IsRequired - { - get; - set; - } - - /// - /// Gets or sets the default value to use when an argument is not provided - /// for the parameter. - /// - public object DefaultValue - { - get; - set; - } - } -} +using System; +using Mustache.Properties; + +namespace Mustache +{ + /// + /// Defines a parameter belonging to a custom tag. + /// + public sealed class TagParameter + { + private readonly string _name; + + /// + /// Initializes a new instance of a TagParameter. + /// + /// The name of the parameter. + /// The parameter name is null or an invalid identifier. + public TagParameter(string parameterName) + { + if (!RegexHelper.IsValidIdentifier(parameterName)) + { + throw new ArgumentException(Resources.BlankParameterName, "parameterName"); + } + _name = parameterName; + } + + /// + /// Gets the name of the parameter. + /// + public string Name + { + get { return _name; } + } + + /// + /// Gets or sets whether the field is required. + /// + public bool IsRequired + { + get; + set; + } + + /// + /// Gets or sets the default value to use when an argument is not provided + /// for the parameter. + /// + public object DefaultValue + { + get; + set; + } + } +} diff --git a/mustache-sharp/Trimmer.cs b/mustache-sharp/Trimmer.cs index 0b17abe..b6179fe 100644 --- a/mustache-sharp/Trimmer.cs +++ b/mustache-sharp/Trimmer.cs @@ -1,147 +1,147 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace mustache -{ - /// - /// Removes unnecessary lines from the final output. - /// - internal sealed class Trimmer - { - private readonly LinkedList _lines; - private LinkedListNode _currentLine; - - /// - /// Initializes a new instance of a Trimmer. - /// - public Trimmer() - { - _lines = new LinkedList(); - _currentLine = _lines.AddLast(new LineDetails()); - } - - /// - /// Updates the state of the trimmer, indicating that the given text was encountered before an inline tag. - /// - /// The text at the end of the format string. - /// The generator created for the inline tag. - /// A static generator containing the passed text. - public IEnumerable RecordText(string value, bool isTag, bool isOutput) - { - int newLineIndex = value.IndexOf(Environment.NewLine); - if (newLineIndex == -1) - { - StaticGenerator generator = new StaticGenerator() { Value = value }; - _currentLine.Value.Generators.Add(generator); - _currentLine.Value.HasTag |= isTag; - _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(value); - yield return generator; - } - else - { - string[] lines = value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); - - // get the trailing generator - string trailing = lines[0]; - StaticGenerator trailingGenerator = new StaticGenerator() { Value = trailing }; - _currentLine.Value.Generators.Add(trailingGenerator); - _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(trailing); - yield return trailingGenerator; - - // get the middle generators - for (int lineIndex = 1; lineIndex < lines.Length - 1; ++lineIndex) - { - string middle = lines[lineIndex]; - StaticGenerator middleGenerator = new StaticGenerator() { Value = middle }; - LineDetails middleDetails = new LineDetails() { HasTag = false }; - _currentLine = _lines.AddLast(middleDetails); - _currentLine.Value.Generators.Add(middleGenerator); - _currentLine.Value.HasOutput = true; - yield return middleGenerator; - } - - // get the leading generator - string leading = lines[lines.Length - 1]; - StaticGenerator leadingGenerator = new StaticGenerator() { Value = leading }; - LineDetails details = new LineDetails() { HasTag = isTag }; - _currentLine = _lines.AddLast(details); - _currentLine.Value.Generators.Add(leadingGenerator); - _currentLine.Value.HasOutput = !String.IsNullOrWhiteSpace(leading); - yield return leadingGenerator; - } - if (isOutput) - { - _currentLine.Value.HasOutput = true; - } - } - - public void Trim() - { - removeBlankLines(); - separateLines(); - removeEmptyGenerators(); - } - - private void removeBlankLines() - { - LinkedListNode current = _lines.First; - while (current != null) - { - LineDetails details = current.Value; - LinkedListNode temp = current; - current = current.Next; - if (details.HasTag && !details.HasOutput) - { - foreach (StaticGenerator generator in temp.Value.Generators) - { - generator.Prune(); - } - temp.List.Remove(temp); - } - } - } - - private void separateLines() - { - LinkedListNode current = _lines.First; - while (current != _lines.Last) - { - List generators = current.Value.Generators; - StaticGenerator lastGenerator = generators[generators.Count - 1]; - lastGenerator.Value += Environment.NewLine; - current = current.Next; - } - } - - private void removeEmptyGenerators() - { - LinkedListNode current = _lines.First; - while (current != null) - { - foreach (StaticGenerator generator in current.Value.Generators) - { - if (generator.Value.Length == 0) - { - generator.Prune(); - } - } - current = current.Next; - } - } - - private sealed class LineDetails - { - public LineDetails() - { - Generators = new List(); - } - - public bool HasTag { get; set; } - - public List Generators { get; set; } - - public bool HasOutput { get; set; } - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Mustache +{ + /// + /// Removes unnecessary lines from the final output. + /// + internal sealed class Trimmer + { + private readonly LinkedList _lines; + private LinkedListNode _currentLine; + + /// + /// Initializes a new instance of a Trimmer. + /// + public Trimmer() + { + _lines = new LinkedList(); + _currentLine = _lines.AddLast(new LineDetails()); + } + + /// + /// Updates the state of the trimmer, indicating that the given text was encountered before an inline tag. + /// + /// The text at the end of the format string. + /// The generator created for the inline tag. + /// A static generator containing the passed text. + public IEnumerable RecordText(string value, bool isTag, bool isOutput) + { + int newLineIndex = value.IndexOf(Environment.NewLine); + if (newLineIndex == -1) + { + StaticGenerator generator = new StaticGenerator() { Value = value }; + _currentLine.Value.Generators.Add(generator); + _currentLine.Value.HasTag |= isTag; + _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(value); + yield return generator; + } + else + { + string[] lines = value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); + + // get the trailing generator + string trailing = lines[0]; + StaticGenerator trailingGenerator = new StaticGenerator() { Value = trailing }; + _currentLine.Value.Generators.Add(trailingGenerator); + _currentLine.Value.HasOutput |= !String.IsNullOrWhiteSpace(trailing); + yield return trailingGenerator; + + // get the middle generators + for (int lineIndex = 1; lineIndex < lines.Length - 1; ++lineIndex) + { + string middle = lines[lineIndex]; + StaticGenerator middleGenerator = new StaticGenerator() { Value = middle }; + LineDetails middleDetails = new LineDetails() { HasTag = false }; + _currentLine = _lines.AddLast(middleDetails); + _currentLine.Value.Generators.Add(middleGenerator); + _currentLine.Value.HasOutput = true; + yield return middleGenerator; + } + + // get the leading generator + string leading = lines[lines.Length - 1]; + StaticGenerator leadingGenerator = new StaticGenerator() { Value = leading }; + LineDetails details = new LineDetails() { HasTag = isTag }; + _currentLine = _lines.AddLast(details); + _currentLine.Value.Generators.Add(leadingGenerator); + _currentLine.Value.HasOutput = !String.IsNullOrWhiteSpace(leading); + yield return leadingGenerator; + } + if (isOutput) + { + _currentLine.Value.HasOutput = true; + } + } + + public void Trim() + { + removeBlankLines(); + separateLines(); + removeEmptyGenerators(); + } + + private void removeBlankLines() + { + LinkedListNode current = _lines.First; + while (current != null) + { + LineDetails details = current.Value; + LinkedListNode temp = current; + current = current.Next; + if (details.HasTag && !details.HasOutput) + { + foreach (StaticGenerator generator in temp.Value.Generators) + { + generator.Prune(); + } + temp.List.Remove(temp); + } + } + } + + private void separateLines() + { + LinkedListNode current = _lines.First; + while (current != _lines.Last) + { + List generators = current.Value.Generators; + StaticGenerator lastGenerator = generators[generators.Count - 1]; + lastGenerator.Value += Environment.NewLine; + current = current.Next; + } + } + + private void removeEmptyGenerators() + { + LinkedListNode current = _lines.First; + while (current != null) + { + foreach (StaticGenerator generator in current.Value.Generators) + { + if (generator.Value.Length == 0) + { + generator.Prune(); + } + } + current = current.Next; + } + } + + private sealed class LineDetails + { + public LineDetails() + { + Generators = new List(); + } + + public bool HasTag { get; set; } + + public List Generators { get; set; } + + public bool HasOutput { get; set; } + } + } +} diff --git a/mustache-sharp/WithGenerator.cs b/mustache-sharp/WithGenerator.cs index c36131a..9a2c2c8 100644 --- a/mustache-sharp/WithGenerator.cs +++ b/mustache-sharp/WithGenerator.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; -namespace mustache +namespace Mustache { /// /// Defines a tag that changes the scope to the object passed as an argument. diff --git a/mustache-sharp/mustache-sharp.csproj b/mustache-sharp/mustache-sharp.csproj index 3dee76a..d7ecc04 100644 --- a/mustache-sharp/mustache-sharp.csproj +++ b/mustache-sharp/mustache-sharp.csproj @@ -8,7 +8,7 @@ {D71B378F-A4BA-4263-A4F0-07A49A0C528D} Library Properties - mustache + Mustache mustache-sharp v4.0 512 diff --git a/mustache-sharp/mustache-sharp.nuspec b/mustache-sharp/mustache-sharp.nuspec index 7fa8d87..ed5c838 100644 --- a/mustache-sharp/mustache-sharp.nuspec +++ b/mustache-sharp/mustache-sharp.nuspec @@ -1,18 +1,17 @@ - - - - $id$ - $version$ - $title$ - $author$ - $author$ - http://github.com/jehugaleahsa/mustache-sharp - false - $description$ - Initial commit - Copyright 2013 - - mustache handlebars.js text generation building template - - + + + + $id$ + $version$ + $title$ + $author$ + $author$ + http://github.com/jehugaleahsa/mustache-sharp + false + $description$ + Copyright 2013 + + mustache handlebars.js text generation building template + + \ No newline at end of file