예제 #1
0
        public IEnumerable<Span> Parse(string viewFile)
        {
            var codeLanguage = RazorCodeLanguageFactory.Create(viewFile.FileExtension());

            using (var fileStream = new FileStream(viewFile, FileMode.Open, FileAccess.Read))
            using (var reader = new StreamReader(fileStream))
            {
                var templateEngine = new RazorTemplateEngine(new RazorEngineHost(codeLanguage));
                var parseResults = templateEngine.ParseTemplate(reader);
                return parseResults.Document.Flatten();
            }
        }
예제 #2
0
        private Type getViewType(RazorTemplate descriptor)
        {
            var className             = ParserHelpers.SanitizeClassName(descriptor.ViewPath);
            var baseTemplateType      = _razorEngineSettings.BaseTemplateType;
            var generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo",
                                                                  "FubuMVC.Razor.Rendering.TemplateHelper", "DefineSection");
            var codeLanguage = RazorCodeLanguageFactory.Create(descriptor.FilePath.FileExtension());
            var host         = new RazorEngineHost(codeLanguage)
            {
                DefaultBaseClass      = baseTemplateType.FullName,
                DefaultNamespace      = "FubuMVC.Razor.GeneratedTemplates",
                GeneratedClassContext = generatedClassContext
            };

            host.NamespaceImports.UnionWith(_commonViewNamespaces.Namespaces);

            var results = _templateGenerator.GenerateCode(descriptor, className, host);

            return(_templateCompiler.Compile(className, results.GeneratedCode, host));
        }