Esempio n. 1
0
        private void genQSuppWins(string HtmlFile, string data_type)
        {
            // create the DOM by reading file
            CQ dom = CQ.CreateFromFile(HtmlFile);

            // get section block type
            var secType = dom["[data-type='section']"].Attr("data-block_type");

            secType = String.Format("data-block_type=\"{0}\"", secType);

            // select with JQuery methods
            var qBlocks = dom["div[data-type='" + data_type + "']"];

            int qCnt = 0;

            // generate supplemental window files
            foreach (var qEl in qBlocks)
            {
                // NAME SUPPLEMENTAL WINDOW FILE
                // filename is found in the data-filename attribute of the main table div
                var attrs    = qEl.Attributes;
                var filename = attrs["data-block_type"];
                if (filename == null)
                {
                    filename = "MISSING_FILENAME.html";
                }

                // extract the HTML
                var qBlock = qEl.OuterHTML;

                // EDIT IMAGE PATHS - reference parent directory
                //Regex rgx = new Regex(@"(src="")asset/ch\d+/");
                //qBlock = rgx.Replace(qBlock, "$1../");

                // get question number for supp win title
                Regex  rgx   = new Regex(@"exercise_(\d+)_(\d+).html");
                string qtnum = rgx.Replace(filename, "$1.$2");
                string title = "Exercise";
                if (qtnum.Length > 0)
                {
                    title = String.Format("{0} {1}", title, qtnum);
                }

                // Edit "constant" header and footer for title and chapter CSS and JS file names
                suppWinTop    = _suppWinTop.Replace(subTitle, title);
                suppWinTop    = suppWinTop.Replace(subChapNum, chapnum);
                suppWinTop    = suppWinTop.Replace(@"data-block_type=""section""", secType);
                suppWinBottom = _suppWinBottom.Replace(subChapNum, chapnum);

                // surround table code with supplemental file HTML
                qBlock = suppWinTop + Environment.NewLine + qBlock + Environment.NewLine + suppWinBottom;

                // and write to target directory
                File.WriteAllText(suppWinDir + filename, qBlock);
                qCnt++;
            }

            textBox1.Text += String.Format("{0} {1} files written{2}", qCnt, data_type, Environment.NewLine);
        }
        public void Test2()
        {
            CQ fragment      = CQ.CreateFragment("<p>some text</p>");
            CQ html          = CQ.CreateFromFile(@"index.html");
            CQ modified_html = html.Select("#test").Append(fragment);

            modified_html.Save(@"index_modified.html");
        }
Esempio n. 3
0
        public void GetReportsFromLastCheckTime_Returns21Reports_WhenTwoReportPages()
        {
            const string secondPageUrl = "second page url";

            _sut.LastReportsCheckDateTime = new DateTime(2015, 8, 26);
            _config.Stub(e => e.NewReportsCheckDateTime).Return(_sut.LastReportsCheckDateTime.AddDays(1));
            _urlBuilder.Stub(e => e.GetUrlFromDate(Arg <DateTime> .Is.Anything, Arg <int> .Is.Equal(2)))
            .Return(secondPageUrl);
            SetUpPageGetterStubGetPageMethod(@"..\..\TestFiles\Raporty 2015-08-26.html");
            _pageGetter.Stub(e => e.GetPage(secondPageUrl))
            .Return(CQ.CreateFromFile(@"..\..\TestFiles\Raporty 2015-08-26 page2.html"));

            var reports = _sut.GetReportsFromLastCheckTime();

            Assert.Equal(21, reports.Count);
        }
        public void Test3()
        {
            XDocument xDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));

            XElement wordsElement = new XElement("words");

            xDocument.Add(wordsElement);
            XElement root = xDocument.Root;

            CQ html = CQ.CreateFromFile(@"vocabulaire_russe.htm");

            // <div class="summary">Le vocabulaire<br></div>
            // <table>
            var div   = html.Select("div.summary");
            var table = div.Next("table");
            var rows  = table.Find("tr");

            foreach (var row in rows)
            {
                CQ tdcells = row.Cq().Find("td");
                if (tdcells.Length == 2)
                {
                    string russian = tdcells[0].Cq().Text().Trim();
                    string french  = tdcells[1].Cq().Text().Trim();

                    string output = String.Format("{0} {1}", russian, french);
                    Console.WriteLine(output);

                    XElement wordElement = new XElement("word", new XAttribute("russian", russian), new XAttribute("french", french));
                    root.Add(wordElement);
                }
                else
                {
                    string output = String.Format("{0}",
                                                  tdcells[0].Cq().Text());
                }
            }

            xDocument.Save("vocabulaire_russe.xml");
        }
Esempio n. 5
0
        private void genFigSuppWins(string HtmlFile, string block_type)
        {
            // create the DOM by reading file
            CQ dom = CQ.CreateFromFile(HtmlFile);

            // get section block type
            var secType = dom["[data-type='section']"].Attr("data-block_type");

            secType = String.Format("data-block_type=\"{0}\"", secType);

            // select with JQuery methods
            var figBlocks = dom["div[data-block_type='" + block_type + "']"];

            int figCnt = figBlocks.Count();

            // generate supplemental window files
            int imgCnt = 0;

            foreach (var figEl in figBlocks)
            {
                // NAME SUPPLEMENTAL WINDOW FILE
                // filename is found in the data-filename attribute of the main figure div
                var attrs    = figEl.Attributes;
                var filename = attrs["data-filename"];
                if (filename == null)
                {
                    textBox1.Text += String.Format("Null filename in {0} - abort run", HtmlFile);
                    return;
                }

                // extract the HTML
                var figBlock = figEl.OuterHTML;

                // EDIT IMAGE PATHS
                // make image paths relative (just remove path -- in same directory in this case)
                // NOTE: Maybe save path for later use in placing files to chapter directories,
                // which are canned here
                // figBlock = figBlock.Replace("asset/ch3/", "");

                // get figure number for supp win title
                Regex  rgx    = new Regex(@"figure_\d+_(\d+).html");
                string fignum = rgx.Replace(filename, "$1");
                rgx = new Regex(@"figure_(\d+)_\d+.html");
                string chan  = rgx.Replace(filename, "$1");
                string title = "Figure";
                if (fignum.Length > 0)
                {
                    title = String.Format("{0} {1}.{2}", title, chan, fignum);
                }

                // Edit "constant" header and footer for title and chapter CSS and JS file names
                suppWinTop    = _suppWinTop.Replace(subTitle, title);
                suppWinTop    = suppWinTop.Replace(subChapNum, chapnum);
                suppWinTop    = suppWinTop.Replace(@"data-block_type=""section""", secType);
                suppWinBottom = _suppWinBottom.Replace(subChapNum, chapnum);

                // surround figure code with supplemental file HTML
                figBlock = suppWinTop + Environment.NewLine + figBlock + Environment.NewLine + suppWinBottom;

                // and write to target directory
                File.WriteAllText(suppWinDir + filename, figBlock);
                imgCnt++;
            }
            textBox1.Text += String.Format("{0} {1} files written{2}", imgCnt, block_type, Environment.NewLine);
        }
Esempio n. 6
0
 private void SetUpPageGetterStubGetPageMethod(string fileName)
 {
     _pageGetter.Stub(e => e.GetPage(SampleUrl))
     .Return(CQ.CreateFromFile(fileName));
 }