public override void RenderChildren(IParrotWriter writer, Nodes.Statement statement, IRendererFactory rendererFactory, IDictionary <string, object> documentHost, object model, string defaultTag = null) { if (string.IsNullOrEmpty(defaultTag)) { defaultTag = DefaultChildTag; } //get model from parameter //required - do not remove if (statement.Parameters != null && statement.Parameters.Count == 1) { var localModel = GetLocalModel(documentHost, statement, model); if (localModel is IEnumerable) { //create locals object to handle local values to the method Locals locals = new Locals(documentHost); IList <object> items = ToList(model as IEnumerable); for (int i = 0; i < items.Count; i++) { var localItem = items[i]; locals.Push(IteratorItem(i, items)); base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, localItem); locals.Pop(); } } } else { base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, model); } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); //Assert that we're looping over something IEnumerable loop = localModel as IEnumerable; if (loop == null) { throw new InvalidCastException("model is not IEnumerable"); } //create a local copy IList<object> items = ToList(loop); //create locals object to handle local values to the method Locals locals = new Locals(documentHost); for (int i = 0; i < items.Count; i++) { var item = items[i]; foreach (var child in statement.Children) { var renderer = rendererFactory.GetRenderer(child.Name); locals.Push(IteratorItem(i, items)); renderer.Render(writer, rendererFactory, child, documentHost, item); locals.Pop(); } } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { //get the parameter var partial = GetLocalModel(documentHost, statement, model) as string; if (string.IsNullOrEmpty(partial)) { throw new ArgumentNullException("partial"); } //ok...we need to load the layoutpage //then pass the node's children into the layout page //then return the result var engine = (Host as AspNetHost).ViewEngine; var result = engine.FindView(null, partial, null, false); if (result != null) { var parrotView = (result.View as ParrotView); using (var stream = parrotView.LoadStream()) { var document = parrotView.LoadDocument(stream); DocumentView view = new DocumentView(Host, rendererFactory, documentHost, document); view.Render(writer); } } }
public void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var modelValueProviderFactory = _host.ModelValueProviderFactory; string result = ""; if (statement is StringLiteral) { foreach (var value in (statement as StringLiteral).Values) { result += GetModelValue( modelValueProviderFactory, documentHost, model, value.Type, value.Data ); } } else { result = GetModelValue(modelValueProviderFactory, documentHost, model, StringLiteralPartType.Encoded, statement.Name); } writer.Write(result); }
public override void RenderChildren(IParrotWriter writer, Nodes.Statement statement, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, object model, string defaultTag = null) { if (string.IsNullOrEmpty(defaultTag)) { defaultTag = DefaultChildTag; } //get model from parameter //required - do not remove if (statement.Parameters != null && statement.Parameters.Count == 1) { var localModel = GetLocalModel(documentHost, statement, model); if (localModel is IEnumerable) { //create locals object to handle local values to the method Locals locals = new Locals(documentHost); IList<object> items = ToList(model as IEnumerable); for (int i = 0; i < items.Count; i++) { var localItem = items[i]; locals.Push(IteratorItem(i, items)); base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, localItem); locals.Pop(); } } } else { base.RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, model); } }
public void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { var modelValueProviderFactory = _host.ModelValueProviderFactory; string result = ""; if (statement is StringLiteral) { foreach (var value in (statement as StringLiteral).Values) { result += GetModelValue( modelValueProviderFactory, documentHost, model, value.Type, value.Data ); } } else { result = GetModelValue(modelValueProviderFactory, documentHost, model, StringLiteralPartType.Encoded, statement.Name); } writer.Write(result); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); //Assert that we're looping over something IEnumerable loop = localModel as IEnumerable; if (loop == null) { throw new InvalidCastException("model is not IEnumerable"); } //create a local copy IList <object> items = ToList(loop); //create locals object to handle local values to the method Locals locals = new Locals(documentHost); for (int i = 0; i < items.Count; i++) { var item = items[i]; foreach (var child in statement.Children) { var renderer = rendererFactory.GetRenderer(child.Name); locals.Push(IteratorItem(i, items)); renderer.Render(writer, rendererFactory, child, documentHost, item); locals.Pop(); } } }
public void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { var value = "html"; //default value of "html" var parameter = statement.Parameters.FirstOrDefault(); if (parameter != null) { Type modelType = model != null?model.GetType() : null; var modelValueProvider = Host.ModelValueProviderFactory.Get(modelType); object result; if (modelValueProvider.GetValue(documentHost, model, statement.Parameters[0].Value, out result)) { value = result.ToString(); } } if (_docTypes.ContainsKey(value)) { value = _docTypes[value](); } documentHost.Add("doctype", value); writer.Write(string.Format("<!DOCTYPE {0}>", value)); }
public void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var value = "html"; //default value of "html" var parameter = statement.Parameters.FirstOrDefault(); if (parameter != null) { Type modelType = model != null ? model.GetType() : null; var modelValueProvider = Host.ModelValueProviderFactory.Get(modelType); object result; if (modelValueProvider.GetValue(documentHost, model, statement.Parameters[0].Value, out result)) { value = result.ToString(); } } if (_docTypes.ContainsKey(value)) { value = _docTypes[value](); } documentHost.Add("doctype", value); writer.Write(string.Format("<!DOCTYPE {0}>", value)); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { //get the parameter List<object> parameters = new List<object>() { writer, documentHost }; if (statement.Parameters != null && statement.Parameters.Any()) { //assume only the first is the path //second is the argument (model) //TODO: fix this parameters.AddRange((List<object>)GetLocalModel(documentHost, statement, model)); } else { //layout = "_layout"; throw new InvalidOperationException("Missing parameters"); } var call = _renderAction.SingleOrDefault(r => r.GetParameters().Count() == parameters.Count); if (call != null) { call.Invoke(this, parameters.ToArray()); } else { //throw an exception } }
public ParrotView(IHost host, IRendererFactory rendererFactory, ParrotViewLocator parrotViewLocator, Func<TextReader> contents, IParrotWriter writer) { _host = host; _rendererFactory = rendererFactory; _parrotViewLocator = parrotViewLocator; _contents = contents; _writer = writer; _rendererFactory.RegisterFactory(new LayoutRenderer(_host, _parrotViewLocator)); }
protected override void CreateTag(IParrotWriter writer, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, object model, Statement statement) { string tagName = string.IsNullOrWhiteSpace(statement.Name) ? DefaultChildTag : statement.Name; TagBuilder builder = new TagBuilder(tagName); //add attributes RenderAttributes(rendererFactory, documentHost, model, statement, builder); writer.Write(builder.ToString(TagRenderMode.SelfClosing)); }
protected override void CreateTag(IParrotWriter writer, IRendererFactory rendererFactory, IDictionary <string, object> documentHost, object model, Statement statement) { string tagName = string.IsNullOrWhiteSpace(statement.Name) ? DefaultChildTag : statement.Name; TagBuilder builder = new TagBuilder(tagName); //add attributes RenderAttributes(rendererFactory, documentHost, model, statement, builder); writer.Write(builder.ToString(TagRenderMode.SelfClosing)); }
public void Render(ViewContext viewContext, IParrotWriter writer) { //View contents using (var stream = LoadStream()) { var contents = Parse(viewContext, stream); string output = contents; writer.Write(output); } }
public void Render(IParrotWriter writer) { foreach (var element in _document.Children) { var renderer = _rendererFactory.GetRenderer(element.Name); var model = DocumentHost.GetValueOrDefault(ModelName); renderer.BeforeRender(writer, _rendererFactory, element, DocumentHost, model); renderer.Render(writer, _rendererFactory, element, DocumentHost, model); renderer.AfterRender(writer, _rendererFactory, element, DocumentHost, model); } }
protected void RenderChildren(IParrotWriter writer, StatementList children, IRendererFactory rendererFactory, IDictionary <string, object> documentHost, string defaultTag, object model) { Func <string, string> tagName = s => string.IsNullOrEmpty(s) ? defaultTag : s; foreach (var child in children) { child.Name = tagName(child.Name); var renderer = rendererFactory.GetRenderer(child.Name); renderer.Render(writer, rendererFactory, child, documentHost, model); } }
public void Render(dynamic model, IParrotWriter writer) { //View contents using (var stream = _contents()) { var contents = stream.ReadToEnd(); contents = Parse(model, contents); string output = contents; writer.Write(output); } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var childrenQueue = documentHost.GetValueOrDefault(LayoutRenderer.LayoutChildren) as Queue<StatementList>; if (childrenQueue == null) { //TODO: replace this with a real exception throw new Exception("Children elements empty"); } var children = childrenQueue.Dequeue(); RenderChildren(writer, children, rendererFactory, documentHost, DefaultChildTag, model); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { //get the parameter List<string> parameters = new List<string>(); if (statement.Parameters != null && statement.Parameters.Any()) { //assume only the first is the path //second is the argument (model) //TODO: fix this //statement.Parameters[0].Value; parameters.AddRange(statement.Parameters.Select(p => p.CalculatedValue)); documentHost.Add(parameters[0], parameters[1]); } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { string layout = ""; if (statement.Parameters != null && statement.Parameters.Any()) { Type modelType = model != null ? model.GetType() : null; var modelValueProvider = Host.ModelValueProviderFactory.Get(modelType); //var parameterLayout = GetLocalModelValue(documentHost, statement, modelValueProvider, model) ?? "_layout"; var parameterLayout = GetLocalModel(documentHost, statement, model) ?? "_layout"; //assume only the first is the path //second is the argument (model) layout = parameterLayout.ToString(); } //ok...we need to load the view //then pass the model to it and //then return the result var result = _parrotViewLocator.LocateView(layout); if (result != null) { var parrotView = new ParrotView(_host, rendererFactory, _parrotViewLocator, result.Contents, writer); string contents = result.Contents().ReadToEnd(); var document = parrotView.LoadDocument(contents); //Create a new DocumentView and DocumentHost if (!documentHost.ContainsKey("_LayoutChildren_")) { documentHost.Add("_LayoutChildren_", new Queue<StatementList>()); } (documentHost["_LayoutChildren_"] as Queue<StatementList>).Enqueue(statement.Children); DocumentView view = new DocumentView(_host, rendererFactory, documentHost, document); view.Render(writer); } else { throw new Exception(string.Format("Layout {0} could not be found", layout)); } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); string statementToOutput = "default"; if (localModel != null) { statementToOutput = localModel.ToString(); } //check that there is a parameter foreach (var child in statement.Children) { string value; var valueWriter = Host.CreateWriter(); //get string value var renderer = rendererFactory.GetRenderer(child.Name); if (renderer is StringLiteralRenderer) { renderer.Render(valueWriter, rendererFactory, child, documentHost, model); value = valueWriter.Result(); } else { value = child.Name; } if (value.Equals(statementToOutput, StringComparison.OrdinalIgnoreCase)) { //render only the child RenderChildren(writer, child, rendererFactory, documentHost, model); return; } } var defaultChild = statement.Children.SingleOrDefault(s => s.Name.Equals("default", StringComparison.OrdinalIgnoreCase)); if (defaultChild != null) { RenderChildren(writer, defaultChild, rendererFactory, documentHost, model); } }
private void RenderAction(IParrotWriter writer, IDictionary<string, object> documentHost, string action, string controllerName, string area, params string[] additional) { RouteValueDictionary routeValues = new RouteValueDictionary(); routeValues["action"] = action; if (!string.IsNullOrWhiteSpace(controllerName)) { routeValues["controller"] = controllerName; } if (!string.IsNullOrWhiteSpace(area)) { routeValues["area"] = area; } var viewContext = documentHost["ViewContext"] as ViewContext; IViewDataContainer container = new ViewPage(); var helper = new HtmlHelper(viewContext, container); writer.Write(helper.Action(action, routeValues).ToHtmlString()); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); string statementToOutput = "default"; if (localModel != null) { statementToOutput = localModel.ToString(); } //check that there is a parameter foreach (var child in statement.Children) { string value; var valueWriter = Host.CreateWriter(); //get string value var renderer = rendererFactory.GetRenderer(child.Name); if (renderer is StringLiteralRenderer) { renderer.Render(valueWriter, rendererFactory, child, documentHost, model); value = valueWriter.Result(); } else { value = child.Name; } if (value.Equals(statementToOutput, StringComparison.OrdinalIgnoreCase)) { //render only the child RenderChildren(writer, child, rendererFactory, documentHost, model); return; } } var defaultChild = statement.Children.SingleOrDefault(s => s.Name.Equals("default", StringComparison.OrdinalIgnoreCase)); if (defaultChild != null) { RenderChildren(writer, defaultChild, rendererFactory, documentHost, model); } }
protected virtual void CreateTag(IParrotWriter writer, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, object model, Statement statement) { string tagName = string.IsNullOrWhiteSpace(statement.Name) ? DefaultChildTag : statement.Name; TagBuilder builder = new TagBuilder(tagName); //add attributes RenderAttributes(rendererFactory, documentHost, model, statement, builder); //AppendAttributes(builder, statement.Attributes, documentHost, modelValueProvider); writer.Write(builder.ToString(TagRenderMode.StartTag)); //render children if (statement.Children.Count > 0) { RenderChildren(writer, statement, rendererFactory, documentHost, model); } writer.Write(builder.ToString(TagRenderMode.EndTag)); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { string layout = ""; if (statement.Parameters != null && statement.Parameters.Any()) { Type modelType = model != null ? model.GetType() : null; var modelValueProvider = Host.ModelValueProviderFactory.Get(modelType); var parameterLayout = GetLocalModel(documentHost, statement, model) ?? "_layout"; //assume only the first is the path //second is the argument (model) layout = parameterLayout.ToString(); } //ok...we need to load the view //then pass the model to it and //then return the result var engine = (Host as AspNetHost).ViewEngine; var result = engine.FindView(null, layout, null, false); if (result != null) { var parrotView = (result.View as ParrotView); using (var stream = parrotView.LoadStream()) { var document = parrotView.LoadDocument(stream); //Create a new DocumentView and DocumentHost if (!documentHost.ContainsKey(LayoutChildren)) { documentHost.Add(LayoutChildren, new Queue<StatementList>()); } (documentHost[LayoutChildren] as Queue<StatementList>).Enqueue(statement.Children); DocumentView view = new DocumentView(Host, rendererFactory, documentHost, document); view.Render(writer); } } }
protected virtual void CreateTag(IParrotWriter writer, IRendererFactory rendererFactory, IDictionary <string, object> documentHost, object model, Statement statement) { string tagName = string.IsNullOrWhiteSpace(statement.Name) ? DefaultChildTag : statement.Name; TagBuilder builder = new TagBuilder(tagName); //add attributes RenderAttributes(rendererFactory, documentHost, model, statement, builder); //AppendAttributes(builder, statement.Attributes, documentHost, modelValueProvider); writer.Write(builder.ToString(TagRenderMode.StartTag)); //render children if (statement.Children.Count > 0) { RenderChildren(writer, statement, rendererFactory, documentHost, model); } writer.Write(builder.ToString(TagRenderMode.EndTag)); }
public void BeforeRender(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { //process parameters if (statement.Parameters != null && statement.Parameters.Any()) { foreach (var parameter in statement.Parameters) { if (parameter.Value != null && ((parameter.Value.StartsWith("\"") && parameter.Value.EndsWith("\"")) || (parameter.Value.StartsWith("'") && parameter.Value.EndsWith("'")))) { var stringLiteral = new StringLiteral(parameter.Value); var renderer = rendererFactory.GetRenderer("string"); var w = new StandardWriter(); { renderer.Render(w, rendererFactory, stringLiteral, documentHost, model); } parameter.CalculatedValue = w.Result(); } } } }
public virtual void RenderChildren(IParrotWriter writer, Statement statement, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, object model, string defaultTag = null) { if (string.IsNullOrEmpty(defaultTag)) { defaultTag = DefaultChildTag; } if (model is IEnumerable && statement.Parameters.Any()) { foreach (object item in model as IEnumerable) { var localItem = item; RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, localItem); } } else { RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, model); } }
public void BeforeRender(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { //process parameters if (statement.Parameters != null && statement.Parameters.Any()) { foreach (var parameter in statement.Parameters) { if (parameter.Value != null && ((parameter.Value.StartsWith("\"") && parameter.Value.EndsWith("\"")) || (parameter.Value.StartsWith("'") && parameter.Value.EndsWith("'")))) { var stringLiteral = new StringLiteral(parameter.Value); var renderer = rendererFactory.GetRenderer("string"); var w = new StandardWriter(); { renderer.Render(w, rendererFactory, stringLiteral, documentHost, model); } parameter.CalculatedValue = w.Result(); } } } }
public virtual void RenderChildren(IParrotWriter writer, Statement statement, IRendererFactory rendererFactory, IDictionary <string, object> documentHost, object model, string defaultTag = null) { if (string.IsNullOrEmpty(defaultTag)) { defaultTag = DefaultChildTag; } if (model is IEnumerable && statement.Parameters.Any()) { foreach (object item in model as IEnumerable) { var localItem = item; RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, localItem); } } else { RenderChildren(writer, statement.Children, rendererFactory, documentHost, defaultTag, model); } }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { //get the input type string type = GetType(statement, rendererFactory, documentHost, model); switch (type) { case "checkbox": case "radio": //special handling for "checked" //is there a checked attribute for (int i = 0; i < statement.Attributes.Count; i++) { if (statement.Attributes[i].Key == "checked") { string attributeValue = RenderAttribute(statement.Attributes[i], rendererFactory, documentHost, model); switch (attributeValue) { case "true": statement.Attributes[i] = new Nodes.Attribute(statement.Attributes[i].Key, new StringLiteral("\"checked\"")); //.Value = "checked"; break; case "false": case "null": //remove this attribute statement.Attributes.RemoveAt(i); i -= 1; break; } } } break; } base.Render(writer, rendererFactory, statement, documentHost, model); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { //get the input type string type = GetType(statement, rendererFactory, documentHost, model); switch (type) { case "checkbox": case "radio": //special handling for "checked" //is there a checked attribute for (int i = 0; i < statement.Attributes.Count; i++) { if (statement.Attributes[i].Key == "checked") { string attributeValue = RenderAttribute(statement.Attributes[i], rendererFactory, documentHost, model); switch (attributeValue) { case "true": statement.Attributes[i] = new Nodes.Attribute(statement.Attributes[i].Key, new StringLiteral("\"checked\"")); //.Value = "checked"; break; case "false": case "null": //remove this attribute statement.Attributes.RemoveAt(i); i -= 1; break; } } } break; } base.Render(writer, rendererFactory, statement, documentHost, model); }
public override void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); CreateTag(writer, rendererFactory, documentHost, localModel, statement); }
private void RenderAction(IParrotWriter writer, IDictionary<string, object> documentHost, string action) { RenderAction(writer, documentHost, action, null); }
public void AfterRender(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { }
public virtual void Render(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary <string, object> documentHost, object model) { var localModel = GetLocalModel(documentHost, statement, model); CreateTag(writer, rendererFactory, documentHost, localModel, statement); }
public void AfterRender(IParrotWriter writer, IRendererFactory rendererFactory, Statement statement, IDictionary<string, object> documentHost, object model) { }
private void RenderAction(IParrotWriter writer, IDictionary<string, object> documentHost, string action, string controllerName) { RenderAction(writer, documentHost, action, controllerName, null); }
protected void RenderChildren(IParrotWriter writer, StatementList children, IRendererFactory rendererFactory, IDictionary<string, object> documentHost, string defaultTag, object model) { Func<string, string> tagName = s => string.IsNullOrEmpty(s) ? defaultTag : s; foreach (var child in children) { child.Name = tagName(child.Name); var renderer = rendererFactory.GetRenderer(child.Name); renderer.Render(writer, rendererFactory, child, documentHost, model); } }