public ITemplateDefinition AddRegion(IRegion region) { BodyActions.Add(r => region.WritePageArea(r, PageArea.Body, null, (rc, pa) => WriteResult.Continue())); // TODO: Write region AddConsumerNeeds(region as IDataConsumer); return(this); }
public ITemplateDefinition AddLayout(ILayout layout) { BodyActions.Add(r => layout.WritePageArea(r, PageArea.Body, (rc, pa, rn) => WriteResult.Continue())); // TODO: Write layout regions AddConsumerNeeds(layout as IDataConsumer); return(this); }
private void WriteElementOpenTag(string tag, params string[] attributePairs) { if (_element != null) { _elementStack.Push(_element); } _element = new Element { Tag = tag }; if (attributePairs != null && attributePairs.Length > 0) { if (attributePairs.Length % 2 != 0) { throw new TemplateBuilderException("Element attributes must be in pairs " + "of name and value, but an odd number of parameters were passed"); } _element.Attributes = attributePairs.ToList(); } var element = _element; BodyActions.Add(r => r.Html.WriteOpenTag(element.Tag, element.Attributes.ToArray())); }
public ITemplateDefinition AddComponent(IComponent component) { BodyActions.Add(r => component.WritePageArea(r, PageArea.Body)); AddConsumerNeeds(component as IDataConsumer); return(this); }
private void WriteElementCloseTag() { var element = _element; BodyActions.Add(r => r.Html.WriteCloseTag(element.Tag)); _element = _elementStack.Count > 0 ? _elementStack.Pop() : null; }
public ITemplateDefinition AddData <T>(string scopeName = null) { // TODO: Figure out how to do this BodyActions.Add(r => { // r.Data.Set(typeof(T), value, scopeName); }); return(this); }
public ITemplate Build() { HeadActions.ToTemplate(_template); ScriptActions.ToTemplate(_template); StyleActions.ToTemplate(_template); BodyActions.ToTemplate(_template); InitializationActions.ToTemplate(_template); return(_template); }
private ITemplateDefinition ExtractProperty(Type dataType, PropertyInfo property, string scopeName = null, string propertyScopeName = null) { BodyActions.Add(r => { var obj = r.Data.Get(dataType, propertyScopeName); var value = property.GetValue(obj, null); r.Data.Set(property.PropertyType, value, scopeName); }); return(this); }
public ITemplateDefinition AddTemplate(string templatePath) { _nameManager.AddResolutionHandler(NameResolutionPhase.ResolveElementReferences, nm => { AddConsumerNeeds(nm.ResolveTemplate(templatePath) as IDataConsumer); }); HeadActions.Add(r => { var t = _nameManager.ResolveTemplate(templatePath); if (t != null) { t.WritePageArea(r, PageArea.Head); } }); ScriptActions.Add(r => { var t = _nameManager.ResolveTemplate(templatePath); if (t != null) { t.WritePageArea(r, PageArea.Scripts); } }); StyleActions.Add(r => { var t = _nameManager.ResolveTemplate(templatePath); if (t != null) { t.WritePageArea(r, PageArea.Styles); } }); BodyActions.Add(r => { var t = _nameManager.ResolveTemplate(templatePath); if (t != null) { t.WritePageArea(r, PageArea.Body); } }); InitializationActions.Add(r => { var t = _nameManager.ResolveTemplate(templatePath); if (t != null) { t.WritePageArea(r, PageArea.Initialization); } }); return(this); }
public ITemplateDefinition AddTemplate(ITemplate template) { HeadActions.Add(r => template.WritePageArea(r, PageArea.Head)); ScriptActions.Add(r => template.WritePageArea(r, PageArea.Scripts)); StyleActions.Add(r => template.WritePageArea(r, PageArea.Styles)); BodyActions.Add(r => template.WritePageArea(r, PageArea.Body)); InitializationActions.Add(r => template.WritePageArea(r, PageArea.Initialization)); AddConsumerNeeds(template as IDataConsumer); return(this); }
public ITemplateDefinition AddDataField <T>(Func <T, string> formatFunc, string scopeName = null) { BodyActions.Add(r => { var data = r.Data.Get <T>(scopeName); var formattedValue = formatFunc(data); r.Html.WriteText(formattedValue); }); AddDependency(typeof(T), scopeName); return(this); }
public ITemplateDefinition AddRegion(string regionName) { var placeholder = BodyActions.AddPlaceholder(); _nameManager.AddResolutionHandler(NameResolutionPhase.ResolveElementReferences, nm => { var e = nm.ResolveRegion(regionName, _package); placeholder(r => e.WritePageArea(r, PageArea.Body, null, (rc, pa) => WriteResult.Continue())); // TODO: Write region AddConsumerNeeds(e as IDataConsumer); }); return(this); }
public ITemplateDefinition AddComponent(string componentName) { var placeholder = BodyActions.AddPlaceholder(); _nameManager.AddResolutionHandler(NameResolutionPhase.ResolveElementReferences, nm => { var e = nm.ResolveComponent(componentName, _package); placeholder(r => e.WritePageArea(r, PageArea.Body)); AddConsumerNeeds(e as IDataConsumer); }); return(this); }
public ITemplateDefinition RepeatStart(Type dataTypeToRepeat, string scopeName, string listScopeName) { var repeat = new Repeat(dataTypeToRepeat, listScopeName, scopeName); BodyActions.Add(repeat.Enact); if (_repeat != null) { _repeatStack.Push(_repeat); } _repeat = repeat; return(this); }
public ITemplateDefinition AddText(string assetName, string defaultText, bool isPreFormatted) { BodyActions.Add(r => { var html = r.Html; var localizedString = _assetManager.GetLocalizedText(r, assetName, defaultText); if (html.IncludeComments && !isPreFormatted) { localizedString = localizedString.Replace('\r', '\n'); var endsWithLineBreak = localizedString.EndsWith("\n"); var lines = localizedString .Split('\n') .Where(s => !string.IsNullOrEmpty(s)) .ToList(); for (var i = 0; i < lines.Count; i++) { var line = lines[i]; if (i < lines.Count - 1 || endsWithLineBreak) { html.WriteTextLine(line); } else { html.WriteText(line); } } } else { if (isPreFormatted) { html.WritePreformatted(localizedString); } else { html.WriteText(localizedString); } } }); return(this); }
private ITemplateDefinition AddDataField(Type dataType, PropertyInfo property, IDataFieldFormatter dataFormatter = null, string scopeName = null) { BodyActions.Add(r => { string formattedValue; var data = r.Data.Get(dataType, scopeName); if (data == null) { if (dataFormatter == null) { formattedValue = null; } else { formattedValue = dataFormatter.Format(property, null); } } else { var propertyValue = property.GetValue(data, null); if (dataFormatter == null) { formattedValue = propertyValue == null ? null : propertyValue.ToString(); } else { formattedValue = dataFormatter.Format(property, propertyValue); } } if (!string.IsNullOrEmpty(formattedValue)) { r.Html.WriteText(formattedValue); } }); AddDependency(dataType, scopeName); return(this); }
public ITemplateDefinition SetElementAttribute(string attributeName, Type dataType, string propertyName, IDataFieldFormatter dataFormatter = null, string scopeName = null) { if (_element == null) { throw new TemplateBuilderException("You cannot set element attributes " + "here since there is no current element. Call AddElementOpen() before setting element attributes."); } _element.Attributes.Add(attributeName); _element.Attributes.Add(attributeName); var element = _element; var attributeIndex = _element.Attributes.Count - 1; var property = dataType.GetProperties().FirstOrDefault(p => string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase)); if (property == null) { throw new TemplateBuilderException("Type " + dataType.DisplayName() + " does not have a public '" + propertyName + "' property"); } BodyActions.AddPrior(r => { var data = r.Data.Get(dataType, scopeName); var propertyValue = property.GetValue(data, null); var formattedValue = dataFormatter == null ? propertyValue.ToString() : dataFormatter.Format(property, propertyValue); element.Attributes[attributeIndex] = formattedValue; }); var dataConsumer = _template as IDataConsumer; if (dataConsumer != null) { dataConsumer.HasDependency(dataType, scopeName); } return(this); }
public ITemplateDefinition AddHtml(string html) { BodyActions.Add(r => r.Html.Write(html)); return(this); }
public ITemplateDefinition AddSelfClosingElement(string tag, params string[] attributePairs) { BodyActions.Add(r => r.Html.WriteOpenTag(tag, true, attributePairs)); return(this); }
public ITemplateDefinition AddLineBreak() { BodyActions.Add(r => r.Html.WriteLine()); return(this); }
public ITemplateDefinition AddElement(string tag, string content, params string[] attributePairs) { BodyActions.Add(r => r.Html.WriteElement(tag, content, attributePairs)); return(this); }