コード例 #1
0
ファイル: Razor.cs プロジェクト: Xperterra/Fhir.Publication
 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
ファイル: Razor.cs プロジェクト: Xperterra/Fhir.Publication
 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
ファイル: Make.cs プロジェクト: Xperterra/Fhir.Publication
        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
ファイル: Make.cs プロジェクト: Xperterra/Fhir.Publication
 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
ファイル: Razor.cs プロジェクト: Xperterra/Fhir.Publication
        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
ファイル: Context.cs プロジェクト: Xperterra/Fhir.Publication
 public Context Clone()
 {
     Context context = new Context(this.Root);
     context.Location = this.Location.Clone();
     return context;
 }
コード例 #11
0
ファイル: Make.cs プロジェクト: Xperterra/Fhir.Publication
        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
ファイル: Make.cs プロジェクト: Xperterra/Fhir.Publication
        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;
 }