示例#1
0
        public string GetOutput(Dictionary<string, object> parameters, Functors functors)
        {
            if (elements == null || elements.Count == 0)
                throw new Exception("No elements to process. Has this template been compiled?");

            var sb = new StringBuilder();
            foreach (var element in elements)
            {
                sb.Append(element.GetOutput(parameters, functors));
            }
            return sb.ToString();
        }
示例#2
0
 public string GetOutput(Dictionary<string, object> parameters, Functors functors)
 {
     if (isVariable)
     {
         object data = null;
         if (!parameters.TryGetValue(name, out data))
             throw new Exception("Unable to find: " + name + " in the parameters!");
         return data.ToString();
     }
     else
         return name;
 }
示例#3
0
        public string GetOutput(Dictionary<string, object> parameters, Functors functors)
        {
            if (methodParams == null || methodParams.Length == 0)
                return functors.Call(methodName);
            else
            {
                string[] stringParams = new string[methodParams.Length];
                for (int i = 0; i < methodParams.Length; i++)
                {
                    stringParams[i] = methodParams[i].GetOutput(parameters, functors);
                }

                //Now that we have transformed the Template Elements into strings, use them as the params
                return functors.Call(methodName, stringParams);

            }
        }
示例#4
0
        static void Main()
        {
            const string constTemplate = @"//
            //This file was auto-generated by Simplate
            //Your changes will be changed. You have been warned...
            //
            public static class {{ className }}
            {
            {{foreach item in items}}
            public const string {{ pascal(item) }} = ""{{ item }}"";
            {{end foreach}}

            Great!
            }";

            var items = new string[] { "green", "blue", "red", "black", "elvis" };
            var functors = new Functors();
            functors.Add("camel", StringExtensions.ToCamelCase);
            functors.Add("pascal", StringExtensions.ToPascalCase);
            functors.Add("test", Test);
            var para = new Dictionary<string, object>();
            para.Add("items", items);
            para.Add("className", "Tests");

            //Console.WriteLine(tk.GetOutput(para, functors));

            //using (StreamWriter sw = new StreamWriter(@"E:\test.txt"))
            //{
            //    sw.Write(tk.GetOutput(para, functors));
            //}

            //Test a simple constant template
            Simplate ct = Simplate.Compile(constTemplate);
            string ctoutput = ct.GetOutput(para, functors);
            Console.WriteLine(ctoutput);
            Console.WriteLine("----------------------------------");
            //Test using a Template within a template
            //
            functors = new Functors();
            functors.Add("tinyTemplate", TinyTemplate);
            Simplate testNested = Simplate.Compile(bigT);
            string outp = testNested.GetOutput(para, functors);
            Console.WriteLine(outp);
        }
示例#5
0
        public string GetOutput(Dictionary<string, object> parameters, Functors functors)
        {
            object data = null;
            if (!parameters.TryGetValue(collectionName, out data))
                throw new Exception("Unable to find: " + collectionName + " in the parameters!");

            ICollection collection = data as ICollection;
            if (collection == null)
                throw new Exception("Item with key: " + collectionName + "must be iterable!");

            var sb = new StringBuilder();
            foreach (var item in collection)
            {
                parameters[variableName] = item;
                foreach (var element in elements)
                {
                    sb.Append(element.GetOutput(parameters, functors));
                }
            }
            //Remove the data we added
            parameters[variableName] = null;

            return sb.ToString();
        }
示例#6
0
 public string GetOutput(Dictionary<string, object> parameters, Functors functors)
 {
     throw new NotImplementedException();
 }