public void CanWriteAndReadFromMemoryStreamWriter()
        {
            MemoryStreamWriter writer = new MemoryStreamWriter();
            writer.Write("Hello world");

            Assert.AreEqual("Hello world", writer.ToString());
        }
Example #2
0
 /// <summary>
 /// Primarily intended for testing.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 internal string Render(Context context)
 {
     using (MemoryStreamWriter result = new MemoryStreamWriter())
     {
         Render(context, result);
         return result.ToString();
     }
 }
Example #3
0
 public override void Render(Context context, StreamWriter result)
 {
     using (MemoryStreamWriter temp = new MemoryStreamWriter())
     {
         base.Render(context, temp);
         context.Scopes.Last()[_to] = temp.ToString();
     }
 }
Example #4
0
        public override void Render(Context context, StreamWriter result)
        {
            context.Stack(() =>
            {
                MemoryStreamWriter temp = new MemoryStreamWriter();
                RenderAll(NodeList, context, temp);
                string tempString = temp.ToString();

                if (tempString != (context.Registers["ifchanged"] as string))
                {
                    context.Registers["ifchanged"] = tempString;
                    result.Write(tempString);
                }
            });
        }
Example #5
0
        public void TestRenderToStreamWriter()
        {
            Template template = Template.Parse("{{test}}");

            using (MemoryStreamWriter streamWriter = new MemoryStreamWriter())
            {
                template.Render(streamWriter, new RenderParameters { LocalVariables = Hash.FromAnonymousObject(new { test = "worked" })});

                Assert.AreEqual("worked", streamWriter.ToString());
            }
        }
Example #6
0
        public override void Render(Context context, StreamWriter result)
        {
            object coll = context[_collectionName];

            if (!(coll is IEnumerable))
                return;
            IEnumerable<object> collection = ((IEnumerable) coll).Cast<object>();

            if (_attributes.ContainsKey("limit") || _attributes.ContainsKey("offset"))
            {
                int limit = _attributes.ContainsKey("limit") ? Convert.ToInt32("limit") : -1;
                int offset = _attributes.ContainsKey("offset") ? Convert.ToInt32("offset") : 0;
                collection = collection.Skip(offset).Take(limit);
            }

            collection = collection.ToList();
            int length = collection.Count();

            int cols = Convert.ToInt32(context[_attributes["cols"]]);

            int row = 1;
            int col = 0;

            result.WriteLine("<tr class=\"row1\">");
            context.Stack(() => collection.EachWithIndex((item, index) =>
            {
                context[_variableName] = item;
                context["tablerowloop"] = Hash.FromAnonymousObject(new
                {
                    length = length,
                    index = index + 1,
                    index0 = index,
                    col = col + 1,
                    col0 = col,
                    rindex = length - index,
                    rindex0 = length - index - 1,
                    first = (index == 0),
                    last = (index == length - 1),
                    col_first = (col == 0),
                    col_last = (col == cols - 1)
                });

                ++col;

                MemoryStreamWriter temp = new MemoryStreamWriter();
                RenderAll(NodeList, context, temp);
                result.Write("<td class=\"col{0}\">{1}</td>", col, temp.ToString());

                if (col == cols && index != length - 1)
                {
                    col = 0;
                    ++row;
                    result.WriteLine("</tr>");
                    result.Write("<tr class=\"row{0}\">", row);
                }
            }));
            result.WriteLine("</tr>");
        }