示例#1
0
        public ContentManager(RazorConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config           = config.AsReadonly();
            _contentProvider = new CompositeContentProvider();
            ContentProvider.ContentModified += OnContentModified;
            config.ContentProviders.ToList().ForEach(ctor => AddContentProvider(ctor()));

            _pathBuilder      = new VirtualPathBuilder(config.RootOperator.Path);
            _autoIncludeName  = config.Templates.AutoIncludeName.EmptyAsNull();
            _defaultExtension = config.Templates.DefaultExtension.EmptyAsNull();
            if (_autoIncludeName != null && !_autoIncludeName.Contains(".") && _defaultExtension != null)
            {
                _autoIncludeName = _autoIncludeName + "." + _defaultExtension.TrimStart('.');
            }
            var shared         = config.Templates.SharedLocation.EmptyAsNull();
            var searchPathList = new List <string>();

            if (shared != null)
            {
                searchPathList.Add(GetPathBuilderWithRootOperator(shared).RemoveTrailingSlash());
            }
            _virtualSearchPathList = searchPathList.AsReadOnly();
        }
示例#2
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",
            };
        }