예제 #1
0
 public DefaultRazorCodeGenerationOptionsBuilder(RazorConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
 }
예제 #2
0
        public static RazorProjectEngine Create(
            RazorProjectFileSystem fileSystem,
            RazorConfiguration configuration,
            Action <RazorProjectEngineBuilder> configure)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var builder = new DefaultRazorProjectEngineBuilder(configuration, fileSystem);

            AddDefaults(builder);

            if (configuration.DesignTime)
            {
                AddDesignTimeDefaults(builder);
            }
            else
            {
                AddRuntimeDefaults(builder);
            }

            configure?.Invoke(builder);

            return(builder.Build());
        }
예제 #3
0
        public DefaultRazorCodeGenerationOptionsBuilder(RazorConfiguration configuration, string fileKind)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Configuration = configuration;
            FileKind      = fileKind;
        }
        protected RazorProjectEngine CreateProjectEngine(Action <RazorProjectEngineBuilder> configure)
        {
            var configuration = RazorConfiguration.Create(Version, "test", Array.Empty <RazorExtension>());

            return(RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b =>
            {
                ConfigureProjectEngine(b);
                configure?.Invoke(b);
            }));
        }
예제 #5
0
        public DefaultRazorParserOptionsBuilder(RazorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Configuration   = configuration;
            LanguageVersion = configuration.LanguageVersion;
        }
예제 #6
0
        public DefaultRazorProjectEngineBuilder(RazorConfiguration configuration, RazorProjectFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            Configuration = configuration;
            FileSystem    = fileSystem;
            Features      = new List <IRazorFeature>();
            Phases        = new List <IRazorEnginePhase>();
        }
예제 #7
0
        public static RazorProjectEngine Create(
            RazorConfiguration configuration,
            RazorProjectFileSystem fileSystem,
            Action <RazorProjectEngineBuilder> configure)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var builder = new DefaultRazorProjectEngineBuilder(configuration, fileSystem);

            // The intialization order is somewhat important.
            //
            // Defaults -> Extensions -> Additional customization
            //
            // This allows extensions to rely on default features, and customizations to override choices made by
            // extensions.
            AddDefaultPhases(builder.Phases);
            AddDefaultFeatures(builder.Features);

            if (configuration.LanguageVersion.CompareTo(RazorLanguageVersion.Version_5_0) >= 0)
            {
                builder.Features.Add(new ViewCssScopePass());
            }

            if (configuration.LanguageVersion.CompareTo(RazorLanguageVersion.Version_3_0) >= 0)
            {
                FunctionsDirective.Register(builder);
                ImplementsDirective.Register(builder);
                InheritsDirective.Register(builder);
                NamespaceDirective.Register(builder);
                AttributeDirective.Register(builder);

                AddComponentFeatures(builder, configuration.LanguageVersion);
            }

            LoadExtensions(builder, configuration.Extensions);

            configure?.Invoke(builder);

            return(builder.Build());
        }
예제 #8
0
        private static void AddDefaultRuntimeFeatures(RazorConfiguration configuration, ICollection <IRazorEngineFeature> features)
        {
            // Configure options
            features.Add(new DefaultRazorParserOptionsFeature(designTime: false, version: configuration.LanguageVersion, fileKind: null));
            features.Add(new DefaultRazorCodeGenerationOptionsFeature(designTime: false));

            // Intermediate Node Passes
            features.Add(new PreallocatedTagHelperAttributeOptimizationPass());

            // Code Target Extensions
            var targetExtension = features.OfType <IRazorTargetExtensionFeature>().FirstOrDefault();

            Debug.Assert(targetExtension != null);

            targetExtension.TargetExtensions.Add(new DefaultTagHelperTargetExtension());
            targetExtension.TargetExtensions.Add(new PreallocatedAttributeTargetExtension());
        }
예제 #9
0
        private static void AddDefaultDesignTimeFeatures(RazorConfiguration configuration, ICollection <IRazorEngineFeature> features)
        {
            // Configure options
            features.Add(new DefaultRazorParserOptionsFeature(designTime: true, version: configuration.LanguageVersion, fileKind: null));
            features.Add(new DefaultRazorCodeGenerationOptionsFeature(designTime: true));
            features.Add(new SuppressChecksumOptionsFeature());

            // Intermediate Node Passes
            features.Add(new DesignTimeDirectivePass());

            // Code Target Extensions
            var targetExtension = features.OfType <IRazorTargetExtensionFeature>().FirstOrDefault();

            Debug.Assert(targetExtension != null);

            targetExtension.TargetExtensions.Add(new DefaultTagHelperTargetExtension());
            targetExtension.TargetExtensions.Add(new DesignTimeDirectiveTargetExtension());
        }
예제 #10
0
        // Internal since RazorEngine APIs are going to be obsolete.
        internal static RazorEngine CreateCore(RazorConfiguration configuration, bool designTime, Action <IRazorEngineBuilder> configure)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var builder = new DefaultRazorEngineBuilder(designTime);

            AddDefaults(builder);

            if (designTime)
            {
                AddDefaultDesignTimeFeatures(configuration, builder.Features);
            }
            else
            {
                AddDefaultRuntimeFeatures(configuration, builder.Features);
            }

            configure?.Invoke(builder);
            return(builder.Build());
        }
        public DefaultRazorProjectEngine(
            RazorConfiguration configuration,
            RazorEngine engine,
            RazorProjectFileSystem fileSystem,
            IReadOnlyList <IRazorProjectEngineFeature> projectFeatures)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }

            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (projectFeatures == null)
            {
                throw new ArgumentNullException(nameof(projectFeatures));
            }

            Configuration   = configuration;
            Engine          = engine;
            FileSystem      = fileSystem;
            ProjectFeatures = projectFeatures;

            for (var i = 0; i < projectFeatures.Count; i++)
            {
                projectFeatures[i].ProjectEngine = this;
            }
        }
예제 #12
0
#pragma warning disable CS0618 // Type or member is obsolete
        private static RazorEngine CreateCore(RazorConfiguration configuration, bool designTime, Action <IRazorEngineBuilder> configure)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var builder = new DefaultRazorEngineBuilder(designTime);

            AddDefaults(builder);

            if (designTime)
            {
                AddDefaultDesignTimeFeatures(configuration, builder.Features);
            }
            else
            {
                AddDefaultRuntimeFeatures(configuration, builder.Features);
            }

            configure?.Invoke(builder);
            return(builder.Build());
        }
예제 #13
0
 public static RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem) => Create(configuration, fileSystem, configure: null);
예제 #14
0
        protected RazorProjectEngine CreateProjectEngine()
        {
            var configuration = RazorConfiguration.Create(Version, "test", Array.Empty <RazorExtension>());

            return(RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, ConfigureProjectEngine));
        }