protected internal void SetBody(LayoutModel layout, string[] pathSegments) { Fs appRoot = AppConf.AppRoot; if (appRoot.FileExists(pathSegments)) { string html = appRoot.ReadAllText(pathSegments); CQ dollarSign = CQ.Create(html); string body = dollarSign["body"].Html().Replace("\r", "").Replace("\n", "").Replace("\t", ""); layout.PageContent = body; StringBuilder headLinks = new StringBuilder(); dollarSign["link", dollarSign["head"]].Each(el => { AddLink(headLinks, el); }); StringBuilder links = new StringBuilder(layout.StyleSheetLinkTags); links.Append(headLinks.ToString()); layout.StyleSheetLinkTags = links.ToString(); StringBuilder scriptTags = new StringBuilder(); dollarSign["script", dollarSign["head"]].Each(el => { AddScript(scriptTags, el); }); StringBuilder scripts = new StringBuilder(layout.ScriptTags); scripts.Append(scriptTags.ToString()); layout.ScriptTags = scripts.ToString(); } }
public void WriteBooks(AppConf appConfig) { AppName = appConfig.Name; FireEvent(AppInitializing, new WebBookEventArgs(appConfig)); // get all the pages BamApplicationManager manager = new BamApplicationManager(appConfig.BamConf); List <string> pageNames = new List <string>(manager.GetPageNames(appConfig.Name)); // read all the pages pageNames.Each(pageName => { FireEvent(WritingBook, new WebBookEventArgs(appConfig)); CurrentPage = pageName; Fs appFs = appConfig.AppRoot; // create a new book for every page WebBook book = new WebBook { Name = pageName }; string content = appFs.ReadAllText("pages", "{0}.html"._Format(pageName)); // get all the [data-navigate-to] and a elements CQ cq = CQ.Create(content); CQ navElements = cq["a, [data-navigate-to]"]; navElements.Each(nav => { // create a WebBookPage for each target string href = nav.Attributes["href"]; string navTo = nav.Attributes["data-navigate-to"]; string url = string.IsNullOrEmpty(navTo) ? href: navTo; if (!string.IsNullOrEmpty(url)) { url = url.Contains('?') ? url.Split('?')[0] : url; string layout = nav.Attributes["data-layout"]; layout = string.IsNullOrEmpty(layout) ? "basic" : layout; if (pageNames.Contains(url)) { book.Pages.Add(new WebBookPage { Name = url, Layout = layout }); } } }); appFs.WriteFile("~/books/{0}.json"._Format(book.Name), book.ToJson(true), true); FireEvent(WroteBook, new WebBookEventArgs(appConfig)); }); FireEvent(AppInitialized, new WebBookEventArgs(appConfig)); }
protected internal WebBook GetBookByAppAndPage(string appName = "localhost", string pageName = "home") { AppConf appConf = BamConf[appName]; WebBook result = new WebBook(); if (appConf != null) { string booksDir = "books"; string bookFile = "{0}.json"._Format(pageName); Fs appRoot = appConf.AppRoot; if (appRoot.FileExists(booksDir, bookFile)) { result = appRoot.ReadAllText(booksDir, bookFile).FromJson <WebBook>(); } } return(result); }