private void RenderEntry(Entry entry) { if (entry == null) { return; } if (entry.Name != "position" && entry.Type != "effect" && entry.Type != "method" && entry.Type != "property" && entry.Name != "jQuery.Widget") { RenderObject(entry); } if (((entry.Type != "method" && entry.Type != "property") || (entry.Name != "effect" && entry.Name != "show" && entry.Name != "hide" && entry.Name != "toggle")) && entry.Name != "jQuery.Widget") { RenderOptions(entry); } RenderEvents(entry); }
/// <summary> /// Gets namespace for an entry /// </summary> /// <param name="entry">Entry to be generated</param> /// <returns>The namespace</returns> public static string GetNamespace(Entry entry) { string nmspace = "jQueryApi.UI"; if (entry == null) { return nmspace; } if (entry.Name.ToLowerInvariant() == "widget" || entry.Categories.Any(c => c.ToLowerInvariant() == "utilities")) { return nmspace; } if (entry.Categories.Length == 0) { return nmspace; } return nmspace + "." + PascalCase(entry.Categories[0]); }
private void RenderOptions(Entry entry) { if (entry.Events.Count == 0 && entry.Options.Count == 0) { return; } string className = Utils.PascalCase(entry.Name) + @"Options"; string content = @"using System; using System.Html; using System.Runtime.CompilerServices; namespace {3} {{ [Imported] [IgnoreNamespace] [Serializable] public sealed class {0} {{ {1}{2} }} }}"; StringBuilder eventsContent = new StringBuilder(); foreach (Event @event in entry.Events.OrderBy(e => e.Name)) { if (!string.IsNullOrEmpty(@event.Description)) { eventsContent.Append( @" /// <summary> /// " + Utils.FormatXmlComment(@event.Description.Replace("<entryname />", entry.Name)) + @" /// </summary>"); } string eventType; if (@event.Arguments.All(a => a.Properties.Count == 0)) { eventType = "jQueryUIEventHandler<object>"; } else { eventType = "jQueryUIEventHandler<" + Utils.PascalCase(entry.Name) + Utils.PascalCase(@event.Name) + "Event" + ">"; } eventsContent.AppendLine( @" [ScriptName(""" + @event.Name + @""")] public " + eventType + " On" + Utils.PascalCase(@event.Name) + @" { get; set; }"); } StringBuilder optionsContent = new StringBuilder(); foreach (var option in entry.Options .OrderBy(o => o.Name) .GroupBy(o => o.Name)) { if (!string.IsNullOrEmpty(option.Min(o => o.Description))) { optionsContent.Append( @" /// <summary> /// " + Utils.FormatXmlComment(option.Min(o => o.Description).Replace("<entryname />", entry.Name)) + @" /// </summary>"); } optionsContent.AppendLine(@" public " + Utils.MapDataType(option.Select(o => o.Type), className, option.Min(o => o.Description)) + @" " + Utils.PascalCase(option.Key) + @" { get; set; }"); } Utils.CreateFile(Path.Combine(DestinationPath, entry.Categories[0] == "methods" ? "." : Utils.PascalCase(entry.Categories[0]), Utils.PascalCase(entry.Name)), className , string.Format(content , className , optionsContent.ToString() , eventsContent.ToString() , Utils.GetNamespace(entry))); }
private void RenderObject(Entry entry) { string className = Utils.PascalCase(entry.Name) + @"Object"; string content = @"using System; using System.Html; using System.Runtime.CompilerServices; namespace {5} {{ /// <summary> /// {1} /// </summary> /// <remarks> /// {2} /// </remarks> [Imported] [IgnoreNamespace]{4} public sealed class {0} {{ private {0}() {{ }}{3} [ScriptSkip] public static explicit operator jQueryObject({0} o) {{ return null; }} [ScriptSkip] public static explicit operator {0}(jQueryObject o) {{ return null; }} }} }}"; StringBuilder methodsContent = new StringBuilder(); foreach (var method in entry.Methods // exclude the jQuery methods as they will be inherit .OrderBy(m => m.Name)) { methodsContent.AppendLine(); methodsContent.AppendLine(); methodsContent.AppendLine(" /// <summary>"); methodsContent.AppendLine(" /// " + Utils.FormatXmlComment(method.Description.Replace("<entryname />", entry.Name))); methodsContent.AppendLine(" /// </summary>"); methodsContent.AppendLine(" [InlineCode(\"{this}." + entry.Name + "('" + method.Name + "'" + string.Join("", method.Arguments.Select(a => ", {" + a.Name + "}")) + ")\")]"); methodsContent.Append(" public " + (string.IsNullOrEmpty(method.ReturnType) ? "void" : Utils.MapDataType(method.ReturnType, className, "")) + " " + Utils.PascalCase(method.Name) + "("); List<string> args = new List<string>(); foreach (Argument arg in method.Arguments) { args.Add(Utils.MapDataType(arg.Type, className, arg.Description) + " " + (arg.Name == "event" ? "@event" : arg.Name)); } methodsContent.AppendLine(string.Join(", ", args) + ") {"); if (!string.IsNullOrEmpty(method.ReturnType)) { methodsContent.AppendLine(" return " + Utils.GetDefaultValue(method.ReturnType) + ";"); } methodsContent.AppendLine(" }"); } foreach (var option in entry.Options .OrderBy(o => o.Name) .GroupBy(o => o.Name)) { string name = (entry.Methods.Any(m => m.Name == option.Key) ? "Option" : "") + Utils.PascalCase(option.Key); string description = option.Min(o => o.Description); methodsContent.AppendLine(); methodsContent.AppendLine(); if (!string.IsNullOrEmpty(description)) { methodsContent.AppendLine(" /// <summary>"); methodsContent.AppendLine(" /// " + Utils.FormatXmlComment(description.Replace("<entryname />", entry.Name))); methodsContent.AppendLine(" /// </summary>"); } methodsContent.AppendLine(" public " + Utils.MapDataType(option.Select(o => o.Type), className, option.Min(o => o.Description)) + " " + name + " {"); methodsContent.AppendLine(" [InlineCode(\"{this}." + entry.Name + "('option', '" + option.Key + "')\")]"); methodsContent.AppendLine(" get;"); methodsContent.AppendLine(" [InlineCode(\"{this}." + entry.Name + "('option', '" + option.Key + "', {value})\")]"); methodsContent.AppendLine(" set;"); methodsContent.AppendLine(" }"); } foreach (Event @event in entry.Events.OrderBy(e => e.Name)) { string eventType; if (@event.Arguments.All(a => a.Properties.Count == 0)) { eventType = "jQueryUIEventHandler<object>"; } else { eventType = "jQueryUIEventHandler<" + Utils.PascalCase(entry.Name) + Utils.PascalCase(@event.Name) + "Event" + ">"; } methodsContent.AppendLine(); methodsContent.AppendLine(); methodsContent.AppendLine(" /// <summary>"); methodsContent.AppendLine(" /// " + Utils.FormatXmlComment(@event.Description.Replace("<entryname />", entry.Name))); methodsContent.AppendLine(" /// </summary>"); methodsContent.AppendLine(" public event " + eventType + " On" + Utils.PascalCase(@event.Name) + " {"); methodsContent.AppendLine(" [InlineCode(\"{this}.bind('" + @event.Name + "', {value})\")]"); methodsContent.AppendLine(" add {"); methodsContent.AppendLine(" }"); methodsContent.AppendLine(" [InlineCode(\"{this}.unbind('" + @event.Name + "', {value})\")]"); methodsContent.AppendLine(" remove {"); methodsContent.AppendLine(" }"); methodsContent.AppendLine(" }"); } string formatedContent = string.Format(content , className , Utils.FormatXmlComment(entry.Description.Replace("<entryname />", entry.Name)) , Utils.FormatXmlComment(entry.LongDescription.Replace("<entryname />", entry.Name)) , methodsContent.ToString() , string.Empty , Utils.GetNamespace(entry)); Utils.CreateFile(Path.Combine(DestinationPath, Utils.PascalCase(entry.Categories[0]), Utils.PascalCase(entry.Name)), className, formatedContent); }
private void RenderEvents(Entry entry) { if (entry.Events.Count == 0) { return; } string content = @"using System; using System.Html; using System.Runtime.CompilerServices; namespace {2} {{ [Imported] [IgnoreNamespace] [Serializable] public sealed class {0} {{{1} }} }}"; string property = @" public {1} {0} {{ get; set; }}"; string className; foreach (var @event in entry.Events .OrderBy(e => e.Name)) { string eventType = Utils.PascalCase(entry.Name) + Utils.PascalCase(@event.Name); foreach (Argument arg in @event.Arguments) { if (arg.Name != "ui") continue; if (arg.Properties.Count == 0) continue; className = Utils.PascalCase(eventType) + "Event"; StringBuilder properties = new StringBuilder(); foreach (Property prop in arg.Properties.OrderBy(p => p.Name)) { properties.Append(string.Format(property, Utils.PascalCase(prop.Name), Utils.MapDataType(prop.Type, className, prop.Description))); } Utils.CreateFile(Path.Combine(DestinationPath, Utils.PascalCase(entry.Categories[0]), Utils.PascalCase(entry.Name)) , className , string.Format(content, className, properties.ToString(), Utils.GetNamespace(entry))); } } }
private IEnumerable<Entry> ParseEntry(XmlNode xmlEntry) { if (xmlEntry == null) { yield break; } Entry entry = new Entry(); entry.Name = GetAttributeStringValue(xmlEntry, "name"); entry.Type = GetAttributeStringValue(xmlEntry, "type"); entry.Description = GetNodeInnerXml(xmlEntry, "desc", entry.Name); entry.LongDescription = GetNodeInnerXml(xmlEntry, "longdesc", entry.Name); entry.Created = GetNodeInnerXml(xmlEntry, "created", entry.Name); XmlNode xmlExample = xmlEntry.SelectSingleNode(".//example"); if (xmlExample != null) { entry.Example = ParseExample(xmlExample); } entry.Categories = ParseCategories(GetNodeList(xmlEntry, ".//category")); entry.Events = ParseEvents(GetNodeList(xmlEntry, ".//events//event"), entry.Name); entry.Methods = ParseMethods(GetNodeList(xmlEntry, ".//methods/*"), entry.Name); if (entry.Type == "effect") { entry.Options = new[] { new Option { Name = "easing", Description = "The easing to use for the effect", Type = "string" } } .Concat(ParseArguments(GetNodeList(xmlEntry, "arguments/argument")).Select(a => new Option { Name = a.Name, Description = a.Description, Type = a.Type })) .ToList(); } else if (entry.Type == "method") { var signatures = GetNodeList(xmlEntry, "signature"); if (signatures.Count > 1) { foreach (XmlNode sign in signatures) { var innerEntry = entry.Clone(); innerEntry.Arguments = ParseArguments(GetNodeList(sign, "argument")); innerEntry.Options = ParseArguments(GetNodeList(sign, "argument[@name='options']/property")).Select(a => new Option { Name = a.Name, Description = a.Description, Type = a.Type }).ToList(); yield return innerEntry; } yield break; } else { entry.Arguments = ParseArguments(GetNodeList(xmlEntry, "signature/argument")); entry.Options = ParseArguments(GetNodeList(xmlEntry, "signature/argument[@name='options']/property")).Select(a => new Option { Name = a.Name, Description = a.Description, Type = a.Type }).ToList(); } } else { entry.Options = ParseOptions(GetNodeList(xmlEntry, ".//options//option"), entry.Name); } yield return entry; }