コード例 #1
0
ファイル: XDustHelperNode.cs プロジェクト: dannichols/x-dust
 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);
 }
コード例 #2
0
ファイル: XDustIndexNode.cs プロジェクト: dannichols/x-dust
 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;
     }
 }
コード例 #3
0
ファイル: XDustBlockNode.cs プロジェクト: dannichols/x-dust
 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);
     }
 }
コード例 #4
0
ファイル: XDustSepNode.cs プロジェクト: dannichols/x-dust
 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;
     }
 }
コード例 #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;
 }
コード例 #6
0
ファイル: XDustPartialNode.cs プロジェクト: dannichols/x-dust
 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);
 }
コード例 #7
0
ファイル: XDustExistsNode.cs プロジェクト: dannichols/x-dust
 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));
 }
コード例 #8
0
ファイル: ContextResolver.cs プロジェクト: dannichols/x-dust
 public Object Resolve(Context context, Object model)
 {
     Object copy = new Context(context, model, null);
     if (null != model)
     {
         if (model is IEnumerable<Object>)
         {
             copy = new List<Object>((IEnumerable<Object>)model);
         }
         else
         {
             foreach (var segment in this.Path)
             {
                 var ctx = (Context)copy;
                 if (!String.IsNullOrEmpty(segment))
                 {
                     if (segment == ".")
                     {
                         if (ctx.Tail.IsValue)
                         {
                             copy = ctx.Tail.Value;
                             break;
                         }
                         else
                         {
                             ctx.Head = null;
                         }
                     }
                     else
                     {
                         var value = ctx.Get(segment);
                         if (value != null)
                         {
                             ctx = new Context(copy, value, null);
                             if (ctx.Tail.IsValue)
                             {
                                 copy = ctx.Tail;
                             }
                             else
                             {
                                 copy = ctx;
                             }
                         }
                         else
                         {
                             copy = null;
                             break;
                         }
                     }
                 }
                 else
                 {
                     copy = ctx.Tail;
                     break;
                 }
             }
         }
     }
     else
     {
         copy = null;
     }
     return copy;
 }
コード例 #9
0
ファイル: XDustLogicNode.cs プロジェクト: dannichols/x-dust
 public virtual String ChooseBodyName(Context context, Object model)
 {
     Object resolved = this.Context.Resolve(context, model);
     return this.IsTruthy(resolved) ? XDustLogicNode.BLOCK : XDustLogicNode.ELSE;
 }
コード例 #10
0
ファイル: XDustLogicNode.cs プロジェクト: dannichols/x-dust
 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();
 }
コード例 #11
0
ファイル: XDustLogicNode.cs プロジェクト: dannichols/x-dust
 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);
 }
コード例 #12
0
ファイル: XDustLogicNode.cs プロジェクト: dannichols/x-dust
 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;
 }
コード例 #13
0
ファイル: XDustNode.cs プロジェクト: dannichols/x-dust
 public abstract String Render(XDust dust, RenderChain chain, Context context, Object model);
コード例 #14
0
ファイル: XDustTextNode.cs プロジェクト: dannichols/x-dust
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     this.Close();
     return this.Value;
 }
コード例 #15
0
ファイル: XDustTemplate.cs プロジェクト: dannichols/x-dust
 public String Render(XDust dust, RenderChain chain, Context context, Object model)
 {
     return this.RootNode.Render(dust, chain, context, model);
 }
コード例 #16
0
 public override string ChooseBodyName(Context context, object model)
 {
     Object resolved = this.Context.Resolve(context, model);
     return this.IsTruthy(resolved) ? XDustLogicNode.ELSE : XDustLogicNode.BLOCK;
 }
コード例 #17
0
 public override string Render(XDust dust, RenderChain chain, Context context, object model)
 {
     return String.Empty;
 }
コード例 #18
0
 public override String Render(XDust dust, RenderChain chain, Context context, object model)
 {
     return this.Character;
 }