public override void Parse(ItemParseContext context, ITextNode textNode) { var itemNameTextNode = GetItemNameTextNode(context.ParseContext, textNode); var itemIdOrPath = PathHelper.CombineItemPath(context.ParentItemPath, itemNameTextNode.Value); var guid = StringHelper.GetGuid(context.ParseContext.Project, textNode.GetAttributeValue("Id", itemIdOrPath)); var databaseName = textNode.GetAttributeValue("Database", context.DatabaseName); var template = context.ParseContext.Factory.Template(context.ParseContext.Project, guid, textNode, databaseName, itemNameTextNode.Value, itemIdOrPath); template.ItemNameProperty.AddSourceTextNode(itemNameTextNode); template.BaseTemplatesProperty.Parse(textNode, Constants.Templates.StandardTemplate); template.IconProperty.Parse(textNode); template.ShortHelpProperty.Parse(textNode); template.LongHelpProperty.Parse(textNode); template.IsEmittable = !string.Equals(textNode.GetAttributeValue(Constants.Fields.IsEmittable), "False", StringComparison.OrdinalIgnoreCase); template.IsImport = string.Equals(textNode.GetAttributeValue(Constants.Fields.IsExtern, context.IsExtern.ToString()), "True", StringComparison.OrdinalIgnoreCase); template.References.AddRange(context.ParseContext.ReferenceParser.ParseReferences(template, template.BaseTemplatesProperty)); // create standard values item var standardValuesItemIdOrPath = itemIdOrPath + "/__Standard Values"; var standardValuesGuid = StringHelper.GetGuid(context.ParseContext.Project, standardValuesItemIdOrPath); var standardValuesItem = context.ParseContext.Factory.Item(context.ParseContext.Project, textNode, standardValuesGuid, databaseName, "__Standard Values", standardValuesItemIdOrPath, itemIdOrPath); standardValuesItem.IsImport = template.IsImport; // todo: should be Uri template.StandardValuesItem = standardValuesItem; // parse fields and sections var sections = textNode.GetSnapshotLanguageSpecificChildNode("Sections"); if (sections != null) { foreach (var sectionTreeNode in sections.ChildNodes) { ParseSection(context, template, sectionTreeNode); } } // setup HtmlTemplate var htmlFileTextNode = textNode.GetAttribute("Layout.HtmlFile"); if (htmlFileTextNode != null && !string.IsNullOrEmpty(htmlFileTextNode.Value)) { var field = context.ParseContext.Factory.Field(template.StandardValuesItem, htmlFileTextNode); field.FieldNameProperty.SetValue("__Renderings"); field.ValueProperty.SetValue(htmlFileTextNode.Value); field.ValueHintProperty.SetValue("HtmlTemplate"); template.StandardValuesItem.Fields.Add(field); } context.ParseContext.Project.AddOrMerge(template); context.ParseContext.Project.AddOrMerge(standardValuesItem); }
public override void Parse(ItemParseContext context, ITextNode textNode) { var itemNameTextNode = GetItemNameTextNode(context.ParseContext, textNode); var itemIdOrPath = PathHelper.CombineItemPath(context.ParentItemPath, itemNameTextNode.Value); var guid = StringHelper.GetGuid(context.ParseContext.Project, textNode.GetAttributeValue("Id", itemIdOrPath)); var databaseName = textNode.GetAttributeValue("Database", context.DatabaseName); var template = context.ParseContext.Factory.Template(context.ParseContext.Project, guid, textNode, databaseName, itemNameTextNode.Value, itemIdOrPath); template.ItemNameProperty.AddSourceTextNode(itemNameTextNode); template.BaseTemplatesProperty.Parse(textNode, Constants.Templates.StandardTemplate); template.IconProperty.Parse(textNode); template.ShortHelpProperty.Parse(textNode); template.LongHelpProperty.Parse(textNode); // todo: yuck template.IsEmittable = !string.Equals(textNode.GetAttributeValue(Constants.Fields.IsEmittable), "False", StringComparison.OrdinalIgnoreCase); template.IsImport = string.Equals(textNode.GetAttributeValue(Constants.Fields.IsImport, context.IsImport.ToString()), "True", StringComparison.OrdinalIgnoreCase); template.References.AddRange(context.ParseContext.ReferenceParser.ParseReferences(template, template.BaseTemplatesProperty)); // create standard values item var standardValuesItemIdOrPath = itemIdOrPath + "/__Standard Values"; var standardValuesGuid = StringHelper.GetGuid(context.ParseContext.Project, standardValuesItemIdOrPath); var standardValuesItem = context.ParseContext.Factory.Item(context.ParseContext.Project, textNode, standardValuesGuid, databaseName, "__Standard Values", standardValuesItemIdOrPath, itemIdOrPath); standardValuesItem.IsImport = template.IsImport; // todo: should be Uri template.StandardValuesItem = standardValuesItem; // parse fields and sections var sections = textNode.GetSnapshotLanguageSpecificChildNode("Sections"); if (sections != null) { foreach (var sectionTreeNode in sections.ChildNodes) { ParseSection(context, template, sectionTreeNode); } } context.ParseContext.PipelineService.Resolve<TemplateParserPipeline>().Execute(context, template, textNode); context.ParseContext.Project.AddOrMerge(template); context.ParseContext.Project.AddOrMerge(standardValuesItem); }
public override IEnumerable<ITextNode> Parse(SnapshotParseContext snapshotParseContext, ITextNode textNode) { var mutableTextNode = textNode as IMutableTextNode; if (mutableTextNode == null) { throw new InvalidOperationException("Text node cannot be modified"); } var textNodes = new List<ITextNode>(); if (!textNode.Attributes.Any() && textNode.ChildNodes.Any()) { foreach (var childNode in textNode.ChildNodes) { var collection = Parse(snapshotParseContext, childNode); if (collection != null) { textNodes.AddRange(collection); } } return textNodes; } var fileName = textNode.GetAttributeValue("File"); if (string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(textNode.Value)) { fileName = textNode.Value; } if (string.IsNullOrEmpty(fileName)) { throw new InvalidOperationException("'File' attribute expected"); } // todo: enable this check /* if (!string.Equals(Path.GetExtension(fileName), Path.GetExtension(textNode.Snapshot.SourceFile.AbsoluteFileName), StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Include file has a different format (Json/Xml/Yaml)"); } */ var placeholderTextNodes = new Dictionary<string, List<ITextNode>>(snapshotParseContext.PlaceholderTextNodes); var placeholdersTextNode = textNode.GetSnapshotLanguageSpecificChildNode("Placeholders"); if (placeholdersTextNode != null) { foreach (var childNode in placeholdersTextNode.ChildNodes) { var placeholderKey = childNode.GetAttributeValue("Key"); placeholderTextNodes[placeholderKey] = childNode.ChildNodes.ToList(); } } mutableTextNode.ChildNodeCollection.Clear(); var tokens = new Dictionary<string, string>(snapshotParseContext.Tokens).AddRange(textNode.Attributes.ToDictionary(a => a.Key, a => a.Value)); var context = new SnapshotParseContext(snapshotParseContext.SnapshotService, tokens, placeholderTextNodes); textNodes.Add(snapshotParseContext.SnapshotService.LoadIncludeFile(context, textNode.Snapshot, fileName)); return textNodes; }