public void Compile_EmptyCompilers() { var context = CreateContext(new IFieldCompiler[0]); var field = new Field(Item.Empty, null) {Value = "Lorem Ipsum"}; field.Compile(context); Assert.That(field.IsCompiled, Is.False); }
public override bool CanCompile(IFieldCompileContext context, Field field) { var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (!(textNode is JsonTextNode)) { return false; } return string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.ValueHint.Contains("Layout"); }
public override bool CanCompile(IFieldCompileContext context, Field field) { // avoid being called by Json var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (!(textNode is XmlTextNode)) { return false; } return string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.ValueHint.Contains("Layout") || field.FieldName == "__Renderings" || field.FieldName == "Final __Renderings"; }
public override string Compile(IFieldCompileContext context, Field field) { var indicator = GetIndicatorToken(context.Configuration); // Trim indicator var wip = field.Value.Substring(indicator.Length); var transformer = new MarkdownSharp.Markdown(); wip = transformer.Transform(wip); return wip; }
public override string Compile(IFieldCompileContext context, Field field) { var value = field.Value.Trim(); var item = field.Item.Project.FindQualifiedItem<IProjectItem>(value); if (item == null) { context.Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value); return string.Empty; } return item.Uri.Guid.Format(); }
public override bool CanCompile(IFieldCompileContext context, Field field) { if(string.IsNullOrEmpty(field.Value)) { return false; } var fieldTypeCheck = string.Equals(field.TemplateField.Type, "rich text", StringComparison.OrdinalIgnoreCase); var indicator = GetIndicatorToken(context.Configuration); var indicatorCheck = indicator == null ? true : field.Value.StartsWith(indicator); return fieldTypeCheck && indicatorCheck; }
public override string Compile(IFieldCompileContext context, Field field) { var qualifiedName = field.Value.Trim(); if (string.IsNullOrEmpty(qualifiedName)) { return string.Empty; } var item = field.Item.Project.FindQualifiedItem(qualifiedName); if (item == null) { context.Trace.TraceError(Msg.C1044, Texts.Image_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName); return string.Empty; } return $"<image mediapath=\"\" alt=\"\" width=\"\" height=\"\" hspace=\"\" vspace=\"\" showineditor=\"\" usethumbnail=\"\" src=\"\" mediaid=\"{item.Uri.Guid.Format()}\" />"; }
public override string Compile(IFieldCompileContext context, Field field) { var qualifiedName = field.Value.Trim(); if (string.IsNullOrEmpty(qualifiedName)) { return string.Empty; } var item = field.Item.Project.FindQualifiedItem<IProjectItem>(qualifiedName); if (item == null) { context.Trace.TraceError(Msg.C1049, Texts.Link_field_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName); return string.Empty; } return $"<link text=\"\" linktype=\"internal\" url=\"\" anchor=\"\" title=\"\" class=\"\" target=\"\" querystring=\"\" id=\"{item.Uri.Guid.Format()}\" />"; }
public override string Compile(IFieldCompileContext context, Field field) { var textNode = TraceHelper.GetTextNode(field.ValueProperty); if (textNode == TextNode.Empty) { return field.Value; } var textSnapshot = textNode.Snapshot as ITextSnapshot; if (textSnapshot == null) { return field.Value; } var layoutCompileContext = new LayoutCompileContext(context, FileSystem, field, textSnapshot); var compiler = new JsonLayoutCompiler(); return compiler.Compile(layoutCompileContext, textNode); }
public override bool CanCompile(IFieldCompileContext context, Field field) { if (!field.Value.StartsWith("~", StringComparison.Ordinal)) { return false; } if (field.ValueProperty.Flags.HasFlag(SourcePropertyFlags.IsFileName)) { return true; } // guess: may actually not be a file name if (field.FieldName == "Path") { return true; } return false; }
public void Compile_NoMatchingCompiler() { var compilers = new IFieldCompiler[] { new CheckboxFieldCompiler() }; var project = new Project(null, null, null, null, null, null); var template = CreateTemplate(project); var context = CreateContext(compilers); var item = new Item(project, TextNode.Empty, Guid.NewGuid(), "master", "item", "/sitecore/item", template.ItemIdOrPath); project.AddOrMerge(item); var field = new Field(item, null) { FieldName = "Text", Value = "Lorem Ipsum" }; field.Compile(context); Assert.That(field.IsCompiled, Is.False); }
public override string Compile(IFieldCompileContext context, Field field) { var value = field.Value.Trim(); if (!string.Equals(value, "true", StringComparison.OrdinalIgnoreCase) && !string.Equals(value, "false", StringComparison.OrdinalIgnoreCase) && field.Item.Snapshots.All(s => s.Capabilities.HasFlag(SnapshotCapabilities.SupportsTrueAndFalseForBooleanFields))) { context.Trace.TraceError(Msg.C1043, Texts.Checkbox_field_value_must_be__true__or__false__, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value); } if (string.Equals(value, "true", StringComparison.OrdinalIgnoreCase)) { return "1"; } if (value == "1") { return "1"; } return string.Empty; }
public override string Compile(IFieldCompileContext context, Field field) { var value = field.Value.Trim(); if (string.IsNullOrEmpty(value)) { return string.Empty; } // check if value is an ISO date if (value.FromIsoToDateTime() != DateTime.MinValue) { return value; } DateTime dateTime; if (!DateTime.TryParse(value, context.Culture, DateTimeStyles.None, out dateTime)) { context.Trace.TraceError(Msg.C1058, "Date field must contain a valid date value", TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value); return string.Empty; } return dateTime.ToString(@"yyyyMMdd") + "T000000Z"; }
public override string Compile(IFieldCompileContext context, Field field) { var value = field.Value.Trim(); if (value.IndexOf('|') < 0) { var item = field.Item.Project.FindQualifiedItem<IProjectItem>(value); if (item == null) { context.Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value); return string.Empty; } return item.Uri.Guid.Format(); } var sb = new StringBuilder(); foreach (var itemPath in value.Split(Constants.Pipe, StringSplitOptions.RemoveEmptyEntries)) { var item = field.Item.Project.FindQualifiedItem<IProjectItem>(itemPath); if (item == null) { context.Trace.TraceError(Msg.C1046, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), itemPath); } else { if (sb.Length > 0) { sb.Append('|'); } sb.Append(item.Uri.Guid.Format()); } } return sb.ToString(); }
public override string Compile(IFieldCompileContext context, Field field) { var htmlTemplate = field.Value.Trim(); if (string.IsNullOrEmpty(htmlTemplate)) { return string.Empty; } var value = htmlTemplate; var rendering = field.Item.Project.ProjectItems.OfType<Rendering>().FirstOrDefault(i => string.Equals(i.FilePath, value, StringComparison.OrdinalIgnoreCase)); if (rendering == null) { context.Trace.TraceError(Msg.C1047, Texts.Rendering_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value); } var layoutItem = field.Item.Project.ProjectItems.OfType<Item>().FirstOrDefault(i => i.ItemIdOrPath == "/sitecore/layout/Layouts/MvcLayout"); if (layoutItem == null) { context.Trace.TraceError(Msg.C1048, Texts.Layout_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), "/sitecore/layout/Layouts/MvcLayout"); } if (rendering == null || layoutItem == null) { return string.Empty; } var renderingItemUri = rendering.RenderingItemUri; if (renderingItemUri == ProjectItemUri.Empty) { return string.Empty; } var renderingId = renderingItemUri.Guid.Format(); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.Formatting = Formatting.Indented; output.WriteStartElement("r"); var deviceItems = field.Item.Project.ProjectItems.OfType<Item>().Where(i => string.Equals(i.TemplateIdOrPath, "/sitecore/templates/System/Layout/Device", StringComparison.OrdinalIgnoreCase) || string.Equals(i.TemplateIdOrPath, "{B6F7EEB4-E8D7-476F-8936-5ACE6A76F20B}", StringComparison.OrdinalIgnoreCase)); foreach (var deviceItem in deviceItems) { if (!deviceItem.ItemIdOrPath.StartsWith("/sitecore/layout/Devices/")) { continue; } output.WriteStartElement("d"); output.WriteAttributeString("id", deviceItem.Uri.Guid.Format()); output.WriteAttributeString("l", layoutItem.Uri.Guid.Format()); output.WriteStartElement("r"); output.WriteAttributeString("id", renderingId); output.WriteAttributeString("ph", "Page.Body"); output.WriteEndElement(); output.WriteEndElement(); } output.WriteEndElement(); return writer.ToString(); }
public void Compile_ExclusiveCompiler() { var compilers = new IFieldCompiler[] { new CheckboxFieldCompiler(), new ReplaceCompiler("alpha") }; var project = new Project(null, null, null, null, null, null); var template = CreateTemplate(project); var context = CreateContext(compilers); var item = new Item(project, TextNode.Empty, Guid.NewGuid(), "master", "item", "/sitecore/item", template.ItemName); project.AddOrMerge(item); var field = new Field(item, null) { FieldName = "Checkbox", Value = "True" }; field.Compile(context); Assert.That(field.IsCompiled, Is.True); Assert.That(field.CompiledValue, Is.EqualTo("1")); }
public override bool CanCompile(IFieldCompileContext context, Field field) { return (field.ValueProperty.Flags & SourcePropertyFlags.IsFileName) == SourcePropertyFlags.IsFileName & field.Value.StartsWith("~", StringComparison.Ordinal); }
public override string Compile(IFieldCompileContext context, Field field) { return Value; }
public override bool CanCompile(IFieldCompileContext context, Field field) { return true; }
public abstract string Compile(IFieldCompileContext context, Field field);
public override bool CanCompile(IFieldCompileContext context, Field field) { return string.Equals(field.TemplateField.Type, "image", StringComparison.OrdinalIgnoreCase); }
public override string Compile(IFieldCompileContext context, Field field) { return field.Value.TrimStart('~'); }
public Field Field(Item item, ITextNode textNode, string fieldName, string fieldValue) { var field = new Field(item, textNode); field.FieldNameProperty.SetValue(fieldName); field.ValueProperty.SetValue(fieldValue); return field; }
public override bool CanCompile(IFieldCompileContext context, Field field) { return field.ValueHint.Contains("HtmlTemplate"); }
public abstract bool CanCompile(IFieldCompileContext context, Field field);
public override bool CanCompile(IFieldCompileContext context, Field field) { // if the value contains a dot (.) it is probably a file name return field.Value.IndexOf("/sitecore", StringComparison.OrdinalIgnoreCase) >= 0 && field.Value.IndexOf('.') < 0 && !field.Item.IsImport; }
public override bool CanCompile(IFieldCompileContext context, Field field) { var type = field.TemplateField.Type; return string.Equals(type, "reference", StringComparison.OrdinalIgnoreCase); }