예제 #1
0
        public virtual XDocument Generate()
        {
            var mainDocument = new HTMLDocument(Compatibility);

            GenerateHead();
            GenerateBody();
            var encoding = new UTF8Encoding();

            foreach (var file in _styles)
            {
                IHTMLItem styleElement;
                if (EmbedStyles)
                {
                    var styleElementEntry = new Style(Compatibility);
                    styleElement = styleElementEntry;
                    styleElementEntry.Type.Value = CSSFile.MediaType.GetAsSerializableString();
                    try
                    {
                        using (var outStream = new MemoryStream())
                        {
                            file.Write(outStream);
                            styleElementEntry.InternalTextItem.Text = encoding.GetString(outStream.ToArray());
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
                else
                {
                    var cssStyleSheet = new Link(Compatibility);
                    styleElement = cssStyleSheet;
                    cssStyleSheet.Relation.Value = "stylesheet";
                    cssStyleSheet.Type.Value     = file.GetMediaType().GetAsSerializableString();
                    cssStyleSheet.HRef.Value     = file.PathInEPUB.GetRelativePath(FileEPubInternalPath, FlatStructure);
                }
                HeadElement.Add(styleElement);
            }

            mainDocument.RootHTML.Add(HeadElement);

            mainDocument.RootHTML.Add(BodyElement);

            if (!mainDocument.RootHTML.IsValid())
            {
                throw new Exception("Document content is not valid");
            }


            var titleElm = new Title(Compatibility);

            titleElm.InternalTextItem.Text = InternalPageTitle;
            HeadElement.Add(titleElm);


            _generatedCodeXDocument = mainDocument.Generate();
            Durty = false;
            return(_generatedCodeXDocument);
        }
예제 #2
0
        public HtmlTag AddScript(string scriptType, string scriptContents)
        {
            var key = Guid.NewGuid().ToString();

            _alterations.Add(html => html.Replace(key, System.Environment.NewLine + scriptContents + System.Environment.NewLine));
            return(Head.Add("script").Attr("type", scriptType).Text(key));
        }
예제 #3
0
        public HtmlTag AddStyle(string styling)
        {
            var key = Guid.NewGuid().ToString();

            _alterations.Add(html => html.Replace(key, styling));
            return(Head.Add("style").Text(key));
        }
예제 #4
0
        public void Should_ThrowArgumentNullException_WhenAddNullParameter_AndCollectionIsEmpty()
        {
            var head = new Head();

            Assert.Throws <ArgumentNullException>(() => head.Add(null));
            Assert.IsFalse(head.Any());
        }
예제 #5
0
 public HtmlTag ReferenceStyle(string path)
 {
     return(Head.Add("link")
            .Attr("media", "screen")
            .Attr("href", path)
            .Attr("type", "text/css")
            .Attr("rel", "stylesheet"));
 }
예제 #6
0
        public void Should_AddCorrectComponent_HeadIsNotEmpty()
        {
            var head = new Head();

            Assert.DoesNotThrow(() => head.Add(new Component("asd", ComponentType.DRY, false)));

            Assert.IsTrue(head.Any());
        }
예제 #7
0
 public HtmlDocument()
 {
     RootTag = new HtmlTag("html");
     DocType = "<!DOCTYPE html>";
     Head    = RootTag.Add("head");
     _title  = Head.Add("title");
     Body    = RootTag.Add("body");
     Last    = Body;
 }
예제 #8
0
 public void Add(int Address)
 {
     Count++;
     if (Head == null)
     {
         Head = new Node()
         {
             Address = Address
         }
     }
     ;
     else
     {
         Head.Add(Address);
     }
 }
예제 #9
0
 public HtmlTag ReferenceScriptFile(string scriptType, string path) => Head.Add("script").Attr("type", scriptType).Attr("src", path);
예제 #10
0
        public void Should_ThrowArgumentNullException_WhenAddNullParameter()
        {
            var head = new Head();

            Assert.Throws <ArgumentNullException>(() => head.Add(null));
        }
예제 #11
0
 public bool Insert(int data)
 {
     return(Head.Add(data));
 }