Exemplo n.º 1
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     chain = new RenderChain(chain, this);
     context = new Context(context, null, this.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as Object));
     var helper = dust.Helpers[this.Name];
     return helper.Render(dust, chain, context, model);
 }
Exemplo n.º 2
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     XDustNode block = chain.GetBlock(this.Name);
     if (null != block)
     {
         return block.Render(dust, chain, context, model);
     }
     else
     {
         return base.Render(dust, chain, context, model);
     }
 }
Exemplo n.º 3
0
 public override Object PrepareModel(RenderChain chain, Context context, Object model)
 {
     IScriptable scriptable = Scriptable.From(model);
     if (scriptable["@idx"] != null)
     {
         return scriptable["@idx"].ToString();
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 4
0
 public override object PrepareModel(RenderChain chain, Context context, object model)
 {
     IScriptable scriptable = Scriptable.From(model);
     Object sep = scriptable["@sep"];
     if (sep != null && (bool)sep)
     {
         return base.PrepareModel(chain, context, model);
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 5
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     chain = new RenderChain(chain, this);
     Object originalModel = model;
     model = this.Context.Resolve(context, model);
     String result = String.Empty;
     if (null != model)
     {
         if (model is XDustNode)
         {
             result = ((XDustNode)model).Render(dust, chain, context, originalModel);
         }
         else if (model is ContextResolver)
         {
             Object temp = ((ContextResolver)model).Resolve(context, originalModel);
             if (null != temp)
             {
                 result = temp.ToString();
             }
         }
         else if (model is IScriptable)
         {
             Object temp = ((IScriptable)model).Value;
             if (null != temp)
             {
                 result = temp.ToString();
             }
         }
         else
         {
             result = model.ToString();
         }
         if (this.Filters.Count > 0)
         {
             foreach (String flag in this.Filters)
             {
                 result = dust.Filters[flag].Invoke(result);
             }
         }
         else
         {
             SecurityElement.Escape(result);
         }
     }
     return result;
 }
Exemplo n.º 6
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     if (null != this.Scope)
     {
         model = this.Scope.Resolve(context, model);
     }
     chain = new RenderChain(chain, this);
     String name;
     if (this.Include is XDustNodeList)
     {
         name = ((XDustNodeList)this.Include).Render(dust, chain, context, model);
     }
     else
     {
         name = this.Include.ToString();
     }
     XDustNode template = dust.Load(null, name);
     return template.Render(dust, chain, context, model);
 }
Exemplo n.º 7
0
 public virtual String RenderBody(XDust dust, String name, RenderChain chain, Context context, Object model)
 {
     StringBuilder sb = new StringBuilder();
     XDustNodeList body = this.Bodies.ContainsKey(name) ? this.Bodies[name] : null;
     context = new Context(context, model, this.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as Object));
     if (null != this.Scope)
     {
         model = this.Scope.Resolve(context, model);
     }
     else if (null != this.Context)
     {
         model = this.Context.Resolve(context, model);
     }
     if (null != body)
     {
         chain = new RenderChain(chain, body);
         if (this.AllowIteration && (model is IEnumerable<Object> || (model is Scriptable && ((Scriptable)model).IsEnumerable)))
         {
             var list = model is IEnumerable<Object> ? (IEnumerable<Object>)model : ((Scriptable)model).AsEnumerable;
             var length = list.Count();
             if (name == XDustLogicNode.ELSE && length < 1)
             {
                 sb.Append(body.Render(dust, chain, context, null));
             }
             else
             {
                 for (var i = 0; i < length; i++)
                 {
                     Context iterModel = this.PrepareModel(dust, chain, context, list.ElementAt(i));
                     iterModel.Parameters["@idx"] = i;
                     iterModel.Parameters["@sep"] = i != length - 1;
                     sb.Append(body.Render(dust, chain, context, iterModel));
                 }
             }
         }
         else
         {
             Context iterModel = this.PrepareModel(dust, chain, context, model);
             sb.Append(body.Render(dust, chain, context, iterModel));
         }
     }
     return sb.ToString();
 }
Exemplo n.º 8
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     chain = new RenderChain(chain, this);
     context = new Context(context, null, this.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as Object));
     var bodyName = this.ChooseBodyName(context, model);
     return this.RenderBody(dust, bodyName, chain, context, model);
 }
Exemplo n.º 9
0
 public virtual Context PrepareModel(XDust dust, RenderChain chain, Context context, Object model)
 {
     var parameters = new Dictionary<String, Object>();
     if (null != this.Parameters)
     {
         foreach (var kvp in this.Parameters)
         {
             parameters[kvp.Key] = kvp.Value.Render(dust, chain, context, context);
         }
     }
     Context result = new Context(context, model, parameters);
     return result;
 }
Exemplo n.º 10
0
 public abstract String Render(XDust dust, RenderChain chain, Context context, Object model);
Exemplo n.º 11
0
 public override Context PrepareModel(XDust dust, RenderChain chain, Context context, object model)
 {
     return new Context(context, context, this.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as Object));
 }
Exemplo n.º 12
0
 public String Render(XDust dust, RenderChain chain, Context context, Object model)
 {
     return this.RootNode.Render(dust, chain, context, model);
 }
Exemplo n.º 13
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     return String.Empty;
 }
Exemplo n.º 14
0
 public RenderChain(RenderChain head, XDustNode tail)
 {
     this.Head = head;
     this.Tail = tail;
 }
Exemplo n.º 15
0
 public override String Render(XDust dust, RenderChain chain, Context context, object model)
 {
     return this.Character;
 }
Exemplo n.º 16
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     this.Close();
     return this.Value;
 }