示例#1
0
 public PagesControllerImpl()
 {
     _tabController                = TabController.Instance;
     _moduleController             = ModuleController.Instance;
     _pageUrlsController           = PageUrlsController.Instance;
     _templateController           = TemplateController.Instance;
     _defaultPortalThemeController = DefaultPortalThemeController.Instance;
 }
示例#2
0
        /// <summary>
        /// Renders the parent's body (invokable at a layout template only). If no parent exists an exception is thrown.
        /// </summary>
        /// <returns></returns>
        public virtual LiteralString RenderBody()
        {
            ITemplateController @this = this;

            if (@this.Parent == null)
            {
                throw new TemplateException("Can only invoke RenderBody() at a child (layout) template.");
            }
            return(new LiteralString(@this.Parent.Result));
        }
        public PagesController()
        {
            _pagesController              = Components.PagesController.Instance;
            _themesController             = ThemesController.Instance;
            _bulkPagesController          = BulkPagesController.Instance;
            _templateController           = TemplateController.Instance;
            _defaultPortalThemeController = DefaultPortalThemeController.Instance;

            _tabController    = TabController.Instance;
            _localeController = LocaleController.Instance;
            _securityService  = SecurityService.Instance;
        }
示例#4
0
        public GetStatusViewUpdateDelegate(
            IStatus status,
            ITemplateController templateController,
            IGetViewModelDelegate <IStatus> statusViewModelDelegate,
            IConvertDelegate <IStatus, IEnumerable <IStatus> > convertStatusTreeToEnumerableDelegate)
        {
            this.status                  = status;
            this.templateController      = templateController;
            this.statusViewModelDelegate = statusViewModelDelegate;
            this.convertStatusTreeToEnumerableDelegate = convertStatusTreeToEnumerableDelegate;

            this.viewParts = new List <string>();
        }
示例#5
0
        /// <summary>
        /// Renders the requested page. Optionally you may pass a specific model. By default the current model is used by the rendered page
        /// </summary>
        /// <param name="virtualPath">The virtual path of the page that must be rendered.</param>
        /// <param name="model">The model.</param>
        /// <param name="skipLayout">if set to <c>true</c> the any layout setting is ignored</param>
        /// <returns></returns>
        public virtual LiteralString RenderPage(string virtualPath, object model = null, bool skipLayout = false)
        {
            ITemplateController @this = this;
            var page = @this.RazorContext.TemplateFactory.CreateTemplateInstance(VirtualLocation.CombineWith(virtualPath)).CastTo <ITemplateController>();

            page.SetModel(model ?? Model);
            page.SetParent(@this);
            page.Execute();
            if (!skipLayout)
            {
                page.TryApplyLayout();
            }
            return(new LiteralString(page.Result));
        }
示例#6
0
        /// <summary>
        /// Renders any parent's section (i.e., the first parent's section with the rquested name).
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="required">if set to <c>true</c> an exception is throw if the section was not found.</param>
        /// <returns></returns>
        public virtual LiteralString RenderSection(string sectionName, bool required = true)
        {
            ITemplateController @this = this;

            if (@this.Parent == null)
            {
                throw new TemplateException("Can only invoke RenderSection() at child templates (layouts).");
            }
            if ([email protected](sectionName))
            {
                if (required)
                {
                    throw new TemplateException("Required section '{0}' not found at any parent template of layout '{1}'. If you want to render this section conditionally invoke RederSection with argument required=false".FormatWith(sectionName, @this.VirtualPath));
                }
                return(string.Empty);
            }
            return(new LiteralString(@this.Parent.CastTo <ITemplateController>().RenderSectionByChildRequest(sectionName)));
        }
示例#7
0
        string ITemplateController.RenderSectionByChildRequest(string sectionName)
        {
            ITemplateController @this = this;

            Action renderAction;

            if (!_sections.TryGetValue(sectionName, out renderAction))
            {
                return(@this.Parent == null ? string.Empty : @this.Parent.CastTo <ITemplateController>().RenderSectionByChildRequest(sectionName));
            }

            var previous = _outputTarget;
            var output   = _outputTarget = new StringBuilder();

            renderAction();
            _outputTarget = previous;
            return(output.ToString());
        }
示例#8
0
 ITemplateController ITemplateController.SetParent(ITemplateController parent)
 {
     Parent = parent;
     if (parent != null)
     {
         _hierarchicalTreeDepth = parent.CastTo <TemplateBase>()._hierarchicalTreeDepth + 1;
         parent.AddChild(this);
     }
     else
     {
         _hierarchicalTreeDepth = 0;
     }
     if (_hierarchicalTreeDepth > _maxHierarchicalTreeDepth)
     {
         throw new TemplateTreeException("The hierarchical tree depth overflows the MaxHierarchicalTreeDepth of {0}. Did you configure recursive layout settings? Did you set a layout (at a _viewStart template) that is not at the shared folder resulting in a recursive loop? ".FormatWith(_maxHierarchicalTreeDepth));
     }
     return(this);
 }
示例#9
0
        ITemplateController ITemplateController.ApplyLayout(ITemplateController layoutTemplate)
        {
            if (layoutTemplate.Parent != null)
            {
                throw new TemplateException("You cannot apply a layout more than once. The layout in argument 'layoutTemplate' already has been applied before. You must create a new layout instance on each assignment.");
            }

            if (_finalResult != null)
            {
                throw new TemplateException("You cannot apply more than one layout to a template. This template already had a layout applied.");
            }

            layoutTemplate.SetParent(this);
            _finalResult = _outputTarget.ToString();
            _outputTarget.Clear();
            layoutTemplate.Execute();
            layoutTemplate.TryApplyLayout();
            _finalResult = layoutTemplate.Result;
            return(this);
        }
示例#10
0
        /// <summary>
        /// Determines whether a section is defined with the specified section name at any parent.
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <returns>
        ///   <c>true</c> if any parent defines a section with the specified section name; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsSectionDefined(string sectionName)
        {
            ITemplateController @this = this;

            return(_sections.ContainsKey(sectionName) || (@this.Parent != null && @this.Parent.CastTo <ITemplate>().IsSectionDefined(sectionName)));
        }
示例#11
0
 ITemplateController ITemplateController.AddChild(ITemplateController child)
 {
     _childs = _childs ?? new List <ITemplate>();
     _childs.Add(child);
     return(this);
 }