예제 #1
0
 public static string Render(Context context, string input)
 {
     var reader = new StringReader(input);
     Assembly assembly = Assemble(reader);
     RazorTemplate<Context> template = CreateTemplateInstance(assembly, context);
     return template.Render();
     
 }
예제 #2
0
 public static void Render(Context context, Stream input, Stream output)
 {
     var reader = new StreamReader(input);
     var writer = new StreamWriter(output);
     
     Assembly assembly = Assemble(reader);
     RazorTemplate<Context> template = CreateTemplateInstance(assembly, context);
     writer.Write(template.Render());
     writer.Flush();
     
 }
예제 #3
0
        public static Statement InterpretStatement(Context context, string text)
        {
            // example statement:
            // select *.md -recursive >>  markdown >> template template.html >> save .html

            Statement statement = new Statement();

            string[] sentences = text.Split(new string[] { ">>" }, StringSplitOptions.RemoveEmptyEntries);
            statement.Selector = InterpretSelector(context, sentences.First());
            foreach (string s in sentences.Skip(1))
            {
                IProcessor processor = InterpretProcessor(context, s);
                if (processor != null)
                {
                    statement.PipeLine.Add(processor);
                }
                
            }
            return statement;
        }
예제 #4
0
 public static IWork InterpretDocument(string text, Context context)
 {
     Bulk bulk = new Bulk();
     StringReader reader = new StringReader(text);
     bool ok; 
     do
     {
         string statement = reader.ReadLine();
         bool skip = (string.IsNullOrWhiteSpace(statement)) || (statement.StartsWith("//"));
         ok = (statement != null);
         if (skip) continue;
         
         if (ok)
         {
             IWork work = InterpretStatement(context, statement);
             bulk.Append(work);
         }
     }
     while (ok);
     return bulk;
 }
예제 #5
0
        public static ISelector Create(Context context, string mask, bool recursive = false, bool fromoutput = false)
        {
            FileFilter filter = new FileFilter();
            filter.Context = context;
            filter.Filter = mask;
            filter.Recursive = recursive;
            filter.FromOutput = fromoutput;

            return filter;
        }
예제 #6
0
 public static ISelector Create(Context context, IEnumerable<string> args)
 {
     return Selector.Create(context, args.ToArray());
 }
예제 #7
0
        public static ISelector Create(Context context, params string[] args)
        {
            string p1 = args.FirstOrDefault();
            string mask = args.Skip(1).Where(a => !a.StartsWith("-")).FirstOrDefault(); // first non option parameter 

            if (p1 == null)
                throw new Exception("No parameters for filter");

            if (p1.StartsWith(STASHPREFIX))
            {
                return new StashFilter(p1, mask);
            }
            else
            {
                FileFilter filter = new FileFilter();
                filter.Filter = p1;
                filter.Recursive = args.Contains("-recursive");
                filter.FromOutput = args.Contains("-output");
                filter.Context = context.Clone();
                filter.Mask = mask;
                return filter;
            }
        }
예제 #8
0
 public static Document GetDocument(Context context, string mask)
 {
     ISelector filter = FileFilter.Create(context, mask, false);
     Document doc = filter.Documents.FirstOrDefault();
     if (doc == null)
     {
         throw new Exception(string.Format("Mask {0} yielded no results", mask));
     }
     else return doc;
 }
예제 #9
0
        public static RazorTemplate<Context> CreateTemplateInstance(Assembly assembly, Context context)
        {
            //Type type = assembly.GetType("RazorOutput.Template");
            Type type = assembly.GetExportedTypes().Single(); // there is only one
            RazorTemplate<Context> template = Activator.CreateInstance(type) as RazorTemplate<Context>;

            var property = type.GetProperty("Model");
            property.SetValue(template, context, null);

            return template;
        }
예제 #10
0
 public Context Clone()
 {
     Context context = new Context(this.Root);
     context.Location = this.Location.Clone();
     return context;
 }
예제 #11
0
        public static IProcessor InterpretProcessor(Context context, string text)
        {
            try
            {
                var words = text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (words.Count() == 0) 
                    return null;
                
                string command = words.First().ToLower();
                var parameters = words.Skip(1);

                switch (command)
                {
                    case "markdown":
                        return new RenderProcessor(new MarkDownRenderer());

                    case "template":
                    {
                        var processor = new TemplateProcessor();
                        //pr.Template = influx.Documents.First(); //Document document = Document.CreateInContext(context, template);
                        processor.Influx = Selector.Create(context, parameters);
                        return processor;
                    }

                    case "razor":
                        return new RenderProcessor(new RazorRenderer());

                    case "copy":
                        return new CopyProcessor();

                    case "save":
                    {
                        string mask = parameters.FirstOrDefault();
                        var processor = new SaveProcessor();
                        processor.Mask = mask;
                        return processor;
                    }

                    case "stash":
                    {
                        string key = words.Skip(1).First();
                        if (!key.StartsWith(Selector.STASHPREFIX)) throw new Exception("Stash name should always begin with " + Selector.STASHPREFIX);
                        return new StashProcessor(key);
                    }

                    case "attach":
                    {
                        IProcessor p = new AttachProcessor();
                        p.Influx = Selector.Create(context, parameters);
                        return p;
                    }

                    case "concatenate":
                        return new ConcatenateProcessor();

                    case "make":
                        return new MakeProcessor();

                    case "makeall":
                    {
                        string folder = parameters.FirstOrDefault();
                        return new MakeForAllProcessor(folder);
                    }

                    case "profiletable":
                        return new ProfileProcessor();

                    case "structure":
                        return new StructureProcessor();

                    case "dict":
                        return new DictTableProcessor();

                    case "valueset":
                        return new ValueSetProcessor();

                    default:
                        throw new Exception("Unknown processing command: " + command);
                }
            }
            catch
            {
                throw new Exception("Invalid processor statement: " + text);
            }
        }
예제 #12
0
        public static ISelector InterpretSelector(Context context, string text)
        {
            try
            {
                var words = text.Split(' ');
                string command = words.First();
                var parameters = words.Skip(1).ToArray();
                return Selector.Create(context, parameters);
            }
            catch
            {
                throw new Exception("Invalid select statement: " + text);
            }

        }
예제 #13
0
 public void Test(Context context)
 {
     Document.CreateInContext(context, "template.html");
 }
예제 #14
0
 public TestProcessor(Context context, string filename)
 {
     // todo: move to influx !!!!
     template = Document.CreateInContext(context, filename);
 }
예제 #15
0
 public static Document CreateInContext(Context context, string filename)
 {
     Document document = new Document();
     document.Context = context.Clone();
     string dir = Path.GetDirectoryName(filename);
     document.Context.MoveTo(dir);
     document.SetFilename(filename);
     return document;
 }
예제 #16
0
 public static Document CreateFromFullPath(Context context, string fullpath)
 {
     Document document = new Document();
     document.Context = Context.CreateFromSource(context.Root, fullpath);
     document.SetFilename(fullpath);
     return document;
 }