public MvcWebPageRazorHost(string virtualPath, string physicalPath)
            : base(virtualPath, physicalPath)
        {
            RegisterSpecialFile(RazorViewEngine.ViewStartFileName, typeof(ViewStartPage));

            DefaultPageBaseClass = typeof(WebViewPage).FullName;

            NamespaceImports.Add("System.Threading.Tasks");
            var context = GeneratedClassContext;
            if (!String.IsNullOrEmpty(context.ExecuteMethodName))
            {
                GeneratedClassContext = new GeneratedClassContext(context.ExecuteMethodName + "Async",
                                                                  context.WriteMethodName,
                                                                  context.WriteLiteralMethodName,
                                                                  context.WriteToMethodName,
                                                                  context.WriteLiteralToMethodName,
                                                                  context.TemplateTypeName,
                                                                  context.DefineSectionMethodName,
                                                                  context.BeginContextMethodName,
                                                                  context.EndContextMethodName)
                {
                    ResolveUrlMethodName = context.ResolveUrlMethodName
                };
            }
            // REVIEW get rid of the namespace import to not force additional references in default MVC projects
            GetRidOfNamespace("System.Web.WebPages.Html");
        }
Ejemplo n.º 2
0
        private WebPageRazorHost()
        {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");
            NamespaceImports.Add("System.Web.WebPages.Html");

            RegisterSpecialFile(ApplicationStartFileName, typeof(ApplicationStartPage));
            RegisterSpecialFile(PageStartFileName, typeof(StartPage));
            DefaultNamespace = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName,
                                                              BeginContextMethodName,
                                                              EndContextMethodName)
            {
                ResolveUrlMethodName = ResolveUrlMethodName
            };
            DefaultPageBaseClass = PageBaseClass;
            DefaultDebugCompilation = true;
            EnableInstrumentation = false;
        }
        public OpenRastaRazorHost(RazorCodeLanguage codeLanguage)
        {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            //NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");

            DefaultNamespace = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName);
            DefaultBaseClass = typeof (RazorViewBase<>).AssemblyQualifiedName;
            DefaultDebugCompilation = true;
            CodeLanguage = codeLanguage;
        }
Ejemplo n.º 4
0
		public NodeRazorHost(RazorCodeLanguage codeLanguage)
			: base(codeLanguage)
		{
			//Override the default methods to use inside the template
			_generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", typeof(HelperResult).FullName, "DefineSection")
			{
				ResolveUrlMethodName = "ResolveUrl",
			};
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyRazorEngineHost"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        public NancyRazorEngineHost(RazorCodeLanguage language)
            : base(language)
        {
            this.DefaultBaseClass = typeof(NancyRazorViewBase).FullName;
            this.DefaultNamespace = "RazorOutput";
            this.DefaultClassName = "RazorView";

            var context = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", typeof(HelperResult).FullName, "DefineSection");
            context.ResolveUrlMethodName = "ResolveUrl";

            this.GeneratedClassContext = context;
        }
Ejemplo n.º 6
0
 public RazorPadHost(RazorCodeLanguage language = null)
 {
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     DefaultBaseClass = typeof(TemplateBase).FullName;
     DefaultClassName = "CompiledTemplate";
     DefaultNamespace = "RazorPad.Runtime";
     CodeLanguage = language;
     GeneratedClassContext = new GeneratedClassContext(
         GeneratedClassContext.DefaultExecuteMethodName,
         GeneratedClassContext.DefaultWriteMethodName,
         GeneratedClassContext.DefaultWriteLiteralMethodName,
         "WriteTo", "WriteLiteralTo",
         typeof(HelperResult).FullName);
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
        public override bool Equals(object obj)
        {
            if (!(obj is GeneratedClassContext))
            {
                return(false);
            }
            GeneratedClassContext other = (GeneratedClassContext)obj;

            return(String.Equals(DefineSectionMethodName, other.DefineSectionMethodName, StringComparison.Ordinal) &&
                   String.Equals(WriteMethodName, other.WriteMethodName, StringComparison.Ordinal) &&
                   String.Equals(WriteLiteralMethodName, other.WriteLiteralMethodName, StringComparison.Ordinal) &&
                   String.Equals(WriteToMethodName, other.WriteToMethodName, StringComparison.Ordinal) &&
                   String.Equals(WriteLiteralToMethodName, other.WriteLiteralToMethodName, StringComparison.Ordinal) &&
                   String.Equals(ExecuteMethodName, other.ExecuteMethodName, StringComparison.Ordinal) &&
                   String.Equals(TemplateTypeName, other.TemplateTypeName, StringComparison.Ordinal));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XiptonEngineHost"/> class.
        /// </summary>
        /// <param name="config">The config holds all settings that are needed to initialzie the host.</param>
        public XiptonEngineHost(RazorConfig config)
            : base(config.Templates.Language)
        {
            if (config == null) throw new ArgumentNullException("config");
            _defaultNamespace = "Xipton.Razor.Generated";
            _config = config.AsReadonly();
            _defaultBaseClass = _config.Templates.NonGenericBaseTypeName;
            _namespaceImports = new HashSet<string>();
            _config.Namespaces.ToList().ForEach(ns => _namespaceImports.Add(ns));

            // the GeneratedClassContext defines the methods that are generated to handle the template
            // control like writing the generated output and also handle other control operations like
            // defining sections inside the template
            _generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", typeof(HelperResult).FullName, "DefineSection") {
                ResolveUrlMethodName = "ResolveUrl",
            };
        }
        private Type getViewType(ViewDescriptor<IRazorTemplate> descriptor)
        {
            var className = ParserHelpers.SanitizeClassName(descriptor.ViewPath);
            var baseTemplateType = _razorEngineSettings.BaseTemplateType;
            var generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", null, null,
                                                                  className, "DefineSection");
            var codeLanguage = RazorCodeLanguageFactory.Create(descriptor.Template.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);
        }
Ejemplo n.º 10
0
        public MvcRazorHost()
            : base(new CSharpRazorCodeLanguage())
        {
            DefaultBaseClass = typeof(RazorView).FullName;
            GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: "Execute",
                writeMethodName: "Write",
                writeLiteralMethodName: "WriteLiteral",
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: "Template",
                defineSectionMethodName: "DefineSection")
            {
                ResolveUrlMethodName = "Href"
            };

            foreach (var ns in _namespaces)
            {
                NamespaceImports.Add(ns);
            }
        }
		public PreprocessedRazorHost (string fullPath) : base (RazorCodeLanguage.GetLanguageByExtension (".cshtml"))
		{
			if (fullPath == null)
				throw new ArgumentNullException ("fullPath");

			FullPath = fullPath;
			_codeDomProvider = new Microsoft.CSharp.CSharpCodeProvider ();
			DefaultNamespace = "ASP";
			EnableLinePragmas = true;
			StaticHelpers = true;

			GeneratedClassContext = new GeneratedClassContext (
				GeneratedClassContext.DefaultExecuteMethodName,
				GeneratedClassContext.DefaultWriteMethodName,
				GeneratedClassContext.DefaultWriteLiteralMethodName,
				"WriteTo",
				"WriteLiteralTo",
				"Action<System.IO.TextWriter>",
				"DefineSection",
				"BeginContext",
				"EndContext"
			) {
				ResolveUrlMethodName = "Href"
			};

			codeGeneratorOptions = new CodeGeneratorOptions {
				// HACK: we use true, even though razor uses false, to work around a mono bug where it omits the 
				// line ending after "#line hidden", resulting in the unparseable "#line hiddenpublic"
				BlankLinesBetweenMembers = true,
				BracingStyle = "C",
				// matches Razor built-in settings
				IndentString = String.Empty,
			};

			foreach (var import in defaultImports)
				NamespaceImports.Add (import);
		}
Ejemplo n.º 12
0
        private WebPageRazorHost() {
            NamespaceImports.Add("System");
            NamespaceImports.Add("System.Collections.Generic");
            NamespaceImports.Add("System.IO");
            NamespaceImports.Add("System.Linq");
            NamespaceImports.Add("System.Net");
            NamespaceImports.Add("System.Web");
            NamespaceImports.Add("System.Web.Helpers");
            NamespaceImports.Add("System.Web.Security");
            NamespaceImports.Add("System.Web.UI");
            NamespaceImports.Add("System.Web.WebPages");
            NamespaceImports.Add("System.Web.WebPages.Html");

            DefaultNamespace = WebDefaultNamespace;
            GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
                                                              GeneratedClassContext.DefaultWriteMethodName,
                                                              GeneratedClassContext.DefaultWriteLiteralMethodName,
                                                              WriteToMethodName,
                                                              WriteLiteralToMethodName,
                                                              TemplateTypeName,
                                                              DefineSectionMethodName);
            DefaultPageBaseClass = PageBaseClass;
            DefaultDebugCompilation = true;
        }