private LiquidExpressionResult DoLookup(ITemplateContext ctx, LiquidHash liquidHash, ILiquidValue indexProperty)
        {
            String propertyNameString = ValueCaster.RenderAsString(indexProperty);

            if (propertyNameString.ToLower().Equals("size"))
            {
                return(LiquidExpressionResult.Success(LiquidNumeric.Create(liquidHash.Keys.Count)));
            }

            var valueAt = liquidHash.ValueAt(indexProperty.Value.ToString());

            if (valueAt.HasValue)
            {
                return(LiquidExpressionResult.Success(valueAt));
            }
            else
            {
                return(LiquidExpressionResult.ErrorOrNone(ctx, indexProperty.ToString()));
            }
        }
Esempio n. 2
0
        private static LiquidExpressionResult Convert <TDest>(LiquidHash liquidHash)
            where TDest : ILiquidValue
        {
            var destType = typeof(TDest);

            // So, according to https://github.com/Shopify/liquid/wiki/Liquid-for-Designers, a hash value will be iterated
            // as an array with two indices.
            if (destType == typeof(LiquidCollection))
            {
                var newArray  = new LiquidCollection();
                var dictarray = liquidHash.Keys.Select(
                    k => (Option <ILiquidValue>) new Some <ILiquidValue>(new LiquidCollection {
                    LiquidString.Create(k),
                    liquidHash[k]
                })).ToList();
                foreach (var item in dictarray)
                {
                    newArray.Add(item);
                }
                return(LiquidExpressionResult.Success(newArray));
            }
            // TODO: Should this return the default value for whatever TDest is requested?
            return(LiquidExpressionResult.Error("Can't convert from a LiquidHash to " + destType));
        }
Esempio n. 3
0
 private static bool CheckIsEmpty(LiquidHash val)
 {
     return(!val.Any());
 }
Esempio n. 4
0
 private static bool CheckIsBlank(LiquidHash val)
 {
     return(!val.Any());
 }