Ejemplo n.º 1
0
        public void TestCssParcer()
        {
            var parser  = new CssParser();
            var data    = new StreamReader(@"Content\SimpleStyles.css").ReadToEnd();
            var classes = CssParser.ParceCss(data);

            BaseStyle temp;

            Assert.IsNotNull(classes);
            Assert.IsTrue(classes.TryGetValue("head", out temp));
            Assert.IsTrue(classes.TryGetValue("odd", out temp));
            Assert.IsTrue(classes.TryGetValue("value", out temp));
            Assert.IsTrue(classes.TryGetValue("name", out temp));
        }
Ejemplo n.º 2
0
        public IEnumerable <Table> CreateTables <TModel>(string filePath, TModel model)
        {
            var generator = new RazorTextGenerator();

            var content = generator.Generate(filePath, model);

            var document = XDocument.Parse(string.Concat("<body>", content, "</body>"));

            // ReSharper disable PossibleNullReferenceException

            var tableTags = document.Root.Elements("table");

            var styleTag = document.Root.Elements("style").FirstOrDefault();

            // ReSharper restore PossibleNullReferenceException

            IDictionary <string, BaseStyle> classes;

            if (styleTag != null)
            {
                var parser = new CssParser();
                classes = CssParser.ParceCss(styleTag.Value);
            }
            else
            {
                classes = new Dictionary <string, BaseStyle>();
            }

            var tables = ParseTables(tableTags, classes).ToArray();

            var imagesTags = document.Root.Elements("img");

            var images = ParseImages(imagesTags);

            var table = tables.First();

            table.Images = images;

            return(tables);
        }