Bloom.Book.HtmlDom.RemoveExtraBookTitles C# (CSharp) Method

RemoveExtraBookTitles() public method

Fix BL-2789, where Tok Pisin and Indonesian would show up in the source bubble for book titles, saying the equivalent of "new book" in each language. BasicBook doesn't have that anymore, but this cleans it up in books made from old shells.
public RemoveExtraBookTitles ( ) : void
return void
        public void RemoveExtraBookTitles()
        {
            //NB: here we're just keeping it simple, not even making sure, for example, that
            //"Nupela Book" is in a Tok Pisin div. If it was in English, we'd zap it as well.
            //This xpath will collect up both divs in the data-div, and also copies of this
            //that may be in a bloom-translationGroup in the cover and title pages.
            var genericBookNames = new[] {"Basic Book", "Nupela Buk", "Buku Dasar"};
            foreach(XmlElement n in _dom.SafeSelectNodes("//*[@data-book='bookTitle']"))
            {
                if(genericBookNames.Contains(n.InnerText.Trim()))
                {
                    n.ParentNode.RemoveChild(n);
                }
            }
        }

Usage Example

Example #1
0
 public void RemoveExtraBookTitles_BookTitlesThatAreJustGeneric_Removed()
 {
     var bookDom = new HtmlDom(@"<html ><head></head><body>
         <div id='bloomDataDiv'>
                 <div data-book='bookTitle' lang='en'>something unique</div>
                 <div data-book='bookTitle' lang='id'>Buku Dasar</div>
                 <div data-book='bookTitle' lang='tpi'>Nupela Buk</div>
         </div>
         <div id='somePage'>
             <div class='bloom-translationGroup bookTitle'>
                 <div class='bloom-editable' data-book='bookTitle' lang='tpi'>
                     <p>Nupela Buk<br/></p>
                 </div>
                 <div class='bloom-editable' data-book='bookTitle' lang='id'>
                     <p>Buku Dasar</p>
                 </div>
                 <div class='bloom-editable' data-book='bookTitle'>
                     <p>something unique<br/></p>
                 </div>
             </div>
         </div>
      </body></html>");
     bookDom.RemoveExtraBookTitles();
     AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='bookTitle' and @lang='en' and text()='something unique']", 1);
     AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='bookTitle' and @lang='id']", 0);
     AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='bookTitle' and @lang='tpi']", 0);
 }