Пример #1
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Initializes a new instance of <see cref="TopicViewEngine"/>.
    /// </summary>
    /// <remarks>
    ///   When instantiated, the <see cref="TopicViewEngine.TopicViewEngine"/> constructor will initialize location formats with
    ///   extensions intended to support organizing views by <see cref="Topic.ContentType"/>.
    /// </remarks>
    public TopicViewEngine(IViewPageActivator viewPageActivator = null) : base(viewPageActivator) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Define view location
      >-------------------------------------------------------------------------------------------------------------------------
      | Supports the following replacement tokens: {0} Controller, {1} View, {2} Area, and {3} Content Type.
      \-----------------------------------------------------------------------------------------------------------------------*/
      var viewLocations = new[] {
        "~/Views/{3}/{1}.cshtml",
        "~/Views/ContentTypes/{3}.{1}.cshtml",
        "~/Views/ContentTypes/{1}.cshtml",
        "~/Views/Shared/{1}.cshtml",
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Set view locations
      \-----------------------------------------------------------------------------------------------------------------------*/
      ViewLocationFormats = ViewLocationFormats.Union(viewLocations).ToArray();
      MasterLocationFormats = MasterLocationFormats.Union(viewLocations).ToArray();
      PartialViewLocationFormats = PartialViewLocationFormats.Union(viewLocations).ToArray();

      /*------------------------------------------------------------------------------------------------------------------------
      | Update view locations for areas
      \-----------------------------------------------------------------------------------------------------------------------*/
      viewLocations = viewLocations.Select(v => v.Replace("~", "~/{2}/")).ToArray();

      /*------------------------------------------------------------------------------------------------------------------------
      | Set area view locations
      \-----------------------------------------------------------------------------------------------------------------------*/
      AreaViewLocationFormats = AreaViewLocationFormats.Union(viewLocations).ToArray();
      AreaMasterLocationFormats = AreaMasterLocationFormats.Union(viewLocations).ToArray();
      AreaPartialViewLocationFormats = AreaPartialViewLocationFormats.Union(viewLocations).ToArray();

    }
Пример #2
0
        public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            string controllerName = controllerContext.RouteData.GetRequiredString("controller");
            object area;
            string viewArea = null;

            if (controllerContext.RouteData.DataTokens.TryGetValue("area", out area))
            {
                viewArea = area as string;
            }
            var loc = ViewLocationFormats
                      .Select(x => String.Format(x, viewName, controllerName, viewArea))
                      .FirstOrDefault(s => File.Exists(MockVirtualPathFactory.NormalizePath(s)));
            var masterLoc = MasterLocationFormats
                            .Select(x => String.Format(x, viewName, masterName, viewArea))
                            .FirstOrDefault(s => File.Exists(MockVirtualPathFactory.NormalizePath(s)));

            if (loc == null)
            {
                return(new ViewEngineResult(ViewLocationFormats));
            }
            else
            {
                var view = new MockView(MockVirtualPathFactory.NormalizePath(loc), loc, true, FileExtensions);
                return(new ViewEngineResult(view, this));
            }
        }
Пример #3
0
        public FeaturesViewEngine()
        {
            ViewLocationCache = new DefaultViewLocationCache();

            var featureFolders = new[]
            {
                "~/Features/%1/{1}/{0}.cshtml",
                "~/Features/%1/%2/{1}/{0}.cshtml",
                "~/Features/%1/{0}.cshtml",
                "~/Features/%1/%2/{0}.cshtml",
                "~/Cms/%1/{1}/{0}.cshtml",
                "~/Commerce/%1/{1}/{0}.cshtml",
                "~/Social/%1/{1}/{0}.cshtml"
            };

            featureFolders = featureFolders.Union(AdditionalPartialViewFormats).ToArray();

            ViewLocationFormats = ViewLocationFormats
                                  .Union(featureFolders)
                                  .ToArray();

            PartialViewLocationFormats = PartialViewLocationFormats
                                         .Union(featureFolders)
                                         .ToArray();

            MasterLocationFormats = MasterLocationFormats
                                    .Union(featureFolders)
                                    .ToArray();
        }
Пример #4
0
 public EPiServerViewEngine()
 {
     this.PartialViewLocationFormats     = PartialViewLocationFormats.Union(ViewFormats).ToArray();
     this.ViewLocationFormats            = ViewLocationFormats.Union(ViewFormats).ToArray();
     this.AreaPartialViewLocationFormats = AreaPartialViewLocationFormats.Union(AreaViewFormats).ToArray();
     this.AreaViewLocationFormats        = AreaViewLocationFormats.Union(AreaViewFormats).ToArray();
     this.AreaMasterLocationFormats      = AreaMasterViewFormats.Union(AreaMasterViewFormats).ToArray();
     this.MasterLocationFormats          = MasterLocationFormats.Union(MasterViewFormats).ToArray();
 }
        private void Initialize()
        {
            MasterLocationFormats      = MasterLocationFormats.CSharpHtmlOnly();
            ViewLocationFormats        = ViewLocationFormats.CSharpHtmlOnly();
            PartialViewLocationFormats = PartialViewLocationFormats.CSharpHtmlOnly();

            AreaMasterLocationFormats      = AreaMasterLocationFormats.CSharpHtmlOnly();
            AreaPartialViewLocationFormats = AreaPartialViewLocationFormats.CSharpHtmlOnly();
            AreaViewLocationFormats        = AreaViewLocationFormats.CSharpHtmlOnly();
        }
Пример #6
0
 public CsRazorViewEngine(IViewPageActivator viewPageActivator)
     : base(viewPageActivator)
 {
     AreaViewLocationFormats        = AreaViewLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     AreaMasterLocationFormats      = AreaMasterLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     AreaPartialViewLocationFormats = AreaPartialViewLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     ViewLocationFormats            = ViewLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     MasterLocationFormats          = MasterLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     PartialViewLocationFormats     = PartialViewLocationFormats.Where(f => f.EndsWith("cshtml")).ToArray();
     FileExtensions = FileExtensions.Where(f => f.EndsWith("cshtml")).ToArray();
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Employment.Web.Mvc.Infrastructure.ViewEngines.CsRazorViewEngine" /> class.
        /// </summary>
        public CsRazorViewEngine()
        {
            const string extension = "cshtml";

            // Only include the cshtml type in location formats and file extensions
            AreaViewLocationFormats        = AreaViewLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            AreaMasterLocationFormats      = AreaMasterLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            AreaPartialViewLocationFormats = AreaPartialViewLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            ViewLocationFormats            = ViewLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            MasterLocationFormats          = MasterLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            PartialViewLocationFormats     = PartialViewLocationFormats.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
            FileExtensions = FileExtensions.Where(s => s.EndsWith(extension, StringComparison.Ordinal)).ToArray();
        }
Пример #8
0
        public FeatureViewEngine()
        {
            var featureFolderViewLocationFormats = new[]
            {
                "~/Features/{0}.cshtml",
                "~/Features/{1}/{0}.cshtml",
                "~/Features/{1}/Views/{0}.cshtml"
            }
            .Union(FeatureFolders())
            .ToArray();

            ViewLocationFormats        = ViewLocationFormats.Union(featureFolderViewLocationFormats).ToArray();
            MasterLocationFormats      = MasterLocationFormats.Union(featureFolderViewLocationFormats).ToArray();
            PartialViewLocationFormats = PartialViewLocationFormats.Union(featureFolderViewLocationFormats).ToArray();
        }
Пример #9
0
        public MultiDeviceRazorViewEngine()
        {
            var newViewLocations = new[]
            {
                "~/Views/{1}/{0}/{0}.cshtml",
                "~/Views/{1}/{0}/Partials/{0}.cshtml",
                "~/Views/{1}/Partials/{0}.cshtml",
                "~/Views/{1}/Partials/{0}/{0}.cshtml",
                "~/Views/Shared/{0}/{0}.cshtml",
                "~/Views/Shared/Partials/{0}.cshtml",
                "~/Views/Shared/Partials/{0}/{0}.cshtml"
            };

            ViewLocationFormats        = ViewLocationFormats.Union(newViewLocations).ToArray();
            MasterLocationFormats      = MasterLocationFormats.Union(newViewLocations).ToArray();
            PartialViewLocationFormats = PartialViewLocationFormats.Union(newViewLocations).ToArray();
        }
Пример #10
0
        /// <summary>
        ///  Constructor for the custom view engine.
        /// </summary>
        public ViewEngineConfig() : base()
        {
            List <string> masterLocationFormats      = MasterLocationFormats.ToList();
            List <string> partialViewLocationFormats = PartialViewLocationFormats.ToList();
            List <string> viewLocationFormats        = ViewLocationFormats.ToList();

            List <string> featureLocationFormats = new List <string>
            {
                "~/Features/{1}/Views/{0}.cshtml",
                "~/Features/{1}/Views/Shared/{0}.cshtml",
            };

            masterLocationFormats.AddRange(featureLocationFormats);
            partialViewLocationFormats.AddRange(featureLocationFormats);
            viewLocationFormats.AddRange(featureLocationFormats);

            this.MasterLocationFormats      = masterLocationFormats.ToArray();
            this.PartialViewLocationFormats = partialViewLocationFormats.ToArray();
            this.ViewLocationFormats        = viewLocationFormats.ToArray();
        }
Пример #11
0
        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            Template.FileSystem = new DotLiquidFileSystem(MasterLocationFormats.Concat(PartialViewLocationFormats));

            return(new DotLiquidView(controllerContext, viewPath, masterPath));
        }