Bloom.web.controllers.PageTemplatesApi.GetBookTemplatePaths C# (CSharp) Method

GetBookTemplatePaths() static private method

Give a list of paths to template books, considering desired presentation order and anything else.
This method is the focus of the logic of this class. So is designed to be unit-testable without a ton of setup; making it static makes it easier to keep that constraint.
static private GetBookTemplatePaths ( string pathToCurrentTemplateHtml, IEnumerable sourceBookPaths ) : List
pathToCurrentTemplateHtml string
sourceBookPaths IEnumerable
return List
        internal static List<string> GetBookTemplatePaths(string pathToCurrentTemplateHtml, IEnumerable<string> sourceBookPaths )
        {
            var bookTemplatePaths = new List<string>();

            // 1) we start the list with the template that was used to start this book
            bookTemplatePaths.Add(pathToCurrentTemplateHtml);

            // 2) Future, add those in their current collection

            // 3) Next look through the books that came with bloom and other that this user has installed (e.g. via download or bloompack)
            //    and add in all other template books that are designed for inclusion in other books. These should end in "template.html".
            //    Requiring the book to end in the word "template" is low budget, but fast. Maybe we'll do something better later.
            bookTemplatePaths.AddRange(sourceBookPaths
                .Where(path => ( (path.ToLower().EndsWith("template.html") || path.ToLower().EndsWith("basic book.html"))
                                    && !string.Equals(path, pathToCurrentTemplateHtml, StringComparison.InvariantCultureIgnoreCase)))
                .Select(path => path));

            var indexOfBasicBook = bookTemplatePaths.FindIndex(p => p.ToLowerInvariant().Contains("basic book"));
            if (indexOfBasicBook > 1)
            {
                var pathOfBasicBook = bookTemplatePaths[indexOfBasicBook];
                bookTemplatePaths.RemoveAt(indexOfBasicBook);
                bookTemplatePaths.Insert(1,pathOfBasicBook);
            }
            return bookTemplatePaths;
        }

Usage Example

Example #1
0
		public void GetBookTemplatePaths_NonBasicBookOriginal_BasicBookOfferedSecond()
		{
			using (var temp = new TemporaryFolder("NonBasicBookOriginal"))
			{
				var original = new TemplateBookTestFolder(temp.FolderPath, "originalTemplate");
				var basic = new TemplateBookTestFolder(temp.FolderPath, "basic book");
				var alphabet = new TemplateBookTestFolder(temp.FolderPath, "alphabet");
				var zebra = new TemplateBookTestFolder(temp.FolderPath, "zebra");
				var pathToCurrentTemplateHtml = original.HtmlPath;
				var pathToBasicBook = basic.HtmlPath;
				var pathToAlphabet = alphabet.HtmlPath;
				var pathToZebra = zebra.HtmlPath;
				var sourceBookPaths = new[]
				{
					pathToAlphabet,
					"c:\\installation dir\\templates\\some book that is not a template at all.html",
					pathToBasicBook,
					pathToCurrentTemplateHtml,
					pathToZebra
				};
				var result = PageTemplatesApi.GetBookTemplatePaths(pathToCurrentTemplateHtml, sourceBookPaths);
				Assert.AreEqual(4, result.Count);
				Assert.That(result[0].ToLowerInvariant(), Is.EqualTo(pathToCurrentTemplateHtml.ToLowerInvariant()),
					"Template used to make the book should be first in the list.");
				Assert.That(result[1].ToLowerInvariant(), Is.EqualTo(pathToBasicBook.ToLowerInvariant()),
					"Basic Book should move ahead of Alphabet to be second in list when it is not first.");
				Assert.That(result[2].ToLowerInvariant(), Is.EqualTo(pathToAlphabet.ToLowerInvariant()), "Alphabet should be third.");
				Assert.That(result[3].ToLowerInvariant(), Is.EqualTo(pathToZebra.ToLowerInvariant()), "Zebra should be last.");
				if (!Platform.IsWindows)
					Assert.That(result[0], Is.EqualTo(pathToCurrentTemplateHtml), "Should not change case on Linux");
			}
		}
All Usage Examples Of Bloom.web.controllers.PageTemplatesApi::GetBookTemplatePaths