Exemplo n.º 1
0
        // TODO May want to make a version of this virtual

        private void ApplyMaster()
        {
            if (!this.IsMasterTemplate)
            {
                return;
            }

            var masterInfo         = this.TemplateContext.MasterInfo;
            var placeholderContent = masterInfo.PlaceholderContent;
            var mergeAttributes    = masterInfo.LayoutElement;
            var master             = this;

            // TODO If template isnt IHxlDocumentAccessor, then this is an error
            var access = ((IHxlDocumentAccessor)master);
            // The document element is c:root, so we need to find the element being
            // actually rendered
            // TODO What if c:root has c:text or multiple ? (rare)
            var de = access.Document.DocumentElement;

            de = de.ChildNodes.OfType <DomElement>().First();
            HxlPlaceholderContentProvider.MergeAttributes(mergeAttributes, de);

            de.Attribute("data-layout", masterInfo.LayoutName);

            // If master has no doctype, then copy doctype from child
            if (access.Document.ChildNodes.All(t => t.NodeType != DomNodeType.DocumentType))
            {
                var dt = mergeAttributes.ChildNodes.OfType <DomDocumentType>().FirstOrDefault();
                if (dt != null)
                {
                    access.Document.ChildNodes.Insert(0, dt);
                }
            }

            // Merge the head element if present
            var myHead = de.Element("head");

            if (myHead != null && masterInfo.HeadElement != null)
            {
                // TODO Array copy is wasteful (performance)
                foreach (var m in masterInfo.HeadElement.ChildNodes.ToArray())
                {
                    // TODO XMLNS might not be correct (rare)
                    if (m.HasAttributes && (m.HasAttribute("hxl:placeholder") ||
                                            m.HasAttribute("hxl:placeholdertarget")))
                    {
                        continue;
                    }

                    myHead.Append(m);
                }
            }
        }
Exemplo n.º 2
0
        protected override void Render()
        {
            // Capture placeholder content
            var placeholderContent = HxlPlaceholderContentProvider.FromElement(Element);

            HxlMasterInfo masterInfo = new HxlMasterInfo(placeholderContent, null, this.Element, _layoutName);
            var           output     = this.Output;

            HxlTemplateContext context = this.TemplateContext;
            var master = LoadMaster(context.TemplateFactory, _ignoreErrors, _layoutName);

            var childContext = context.CreateChildContext(master);

            childContext.SetMasterInfo(masterInfo);

            master.Transform(output, childContext);
        }
Exemplo n.º 3
0
        protected override void Render()
        {
            // Only render the content placeholders
            var placeholderContent = HxlPlaceholderContentProvider.FromElement(Element);

            var masterInfo = new HxlMasterInfo(placeholderContent, null, Element, _layout);

            masterInfo.InSpa = true;

            var master = LayoutTemplate.LoadMaster(TemplateContext.TemplateFactory, false, _layout);
            var tc     = TemplateContext.CreateChildContext(master);

            tc.SetMasterInfo(masterInfo);

            master.Transform(TextWriter.Null, tc);

            // TODO Could have multiple items scheduled
            // TODO Skip over single-page elements that were disabled
            // TODO Output correct spa locations

            // If Output is null writer, then we're nested
            if (ReferenceEquals(Output, TextWriter.Null))
            {
                return;
            }

            Output.WriteLine("{ ");
            object versionString = "1";

            Output.WriteLine(string.Format("\"version\": \"{0}\", ", versionString));
            Output.WriteLine("\"fragments\": [");

            bool comma = false;

            foreach (StringWriter b in TemplateContext.EndBufferContent("spaFragments"))
            {
                if (comma)
                {
                    Output.Write(",");
                }

                Output.WriteLine(b);
                comma = true;
            }
            Output.WriteLine("] }");
        }