public IHandlerBuilder Index() { var model = new AIModel(_AIs); return(ModScriban.Page(Resource.FromAssembly("ai_index.html"), (r, h) => new ViewModel <AIModel>(r, h, model)) .Title("Models")); }
public IHandlerBuilder Index() { var model = new ReportModel(_Reports); return(ModScriban.Page(Resource.FromAssembly("reports.html"), (r, h) => new ViewModel <ReportModel>(r, h, model)) .Title("Reports")); }
public void TestRendering() { ModelProvider <CustomModel> modelProvider = (r, h) => new CustomModel(r, h); var providers = new List <IHandlerBuilder>() { ModScriban.Page(Data.FromString("Hello {{ world }}!"), modelProvider), ModRazor.Page(Data.FromString("Hello @Model.World!"), modelProvider), Placeholders.Page(Data.FromString("Hello [World]!"), modelProvider) }; foreach (var provider in providers) { var layout = Layout.Create().Add("page", provider); using var runner = TestRunner.Run(layout); using var response = runner.GetResponse("/page"); var content = response.GetContent(); Assert.NotEqual("Hello World!", content); Assert.Contains("Hello World!", content); } }
public void TestRouting() { var providers = new List <IHandlerBuilder>() { ModScriban.Page(Data.FromString("{{ route 'https://google.de' }}|{{ route 'res/123' }}|{{ route 'other/456/' }}|{{ route './relative' }}")), ModRazor.Page(Data.FromString("@Model.Route(\"https://google.de\")|@Model.Route(\"res/123\")|@Model.Route(\"other/456/\")|@Model.Route(\"./relative\")")), }; foreach (var provider in providers) { var inner = Layout.Create() .Add("page", provider); var outer = Layout.Create() .Add("res", Layout.Create()) .Add("inner", inner); var layout = Layout.Create() .Add("other", Layout.Create()) .Add("outer", outer); using var runner = TestRunner.Run(layout); using var response = runner.GetResponse("/outer/inner/page"); var content = response.GetContent(); Assert.Contains("https://google.de|../res/123|../../other/456/|./relative", content); } }
public IHandlerBuilder Details([FromPath] int id) { var model = _AIs.Where(m => m.ID == id).First(); return(ModScriban.Page(Resource.FromAssembly("ai.html"), (r, h) => new ViewModel <AI>(r, h, model)) .Title($"Model {model.Name}")); }
private static IHandlerBuilder Setup() { var index = Page.From("Home", "This is the home page") .Description("Home Page"); var additional = Page.From("Content", "This is additional content") .Description("Additional Content"); var error = ModScriban.Page(Resource.FromString("This is a {{ rendering.error }}!")) .Description("Error page"); var content = Layout.Create() .Add("one", additional) .Add("two", additional) .Add("error", error) .Index(additional); var root = Layout.Create() .Index(index) .Add("content", content) .Add("other", additional); var main = Layout.Create() .Add("avatar.png", Download.From(Resource.FromAssembly("avatar.png"))) .Index(ModScriban.Page(Resource.FromAssembly("Index.html")).Title("GenHTTP Themes")); var menu = Menu.Empty() .Add("{website}", "Home") .Add("content/", "Content", new List <(string, string)> { ("one/", "One"), ("two/", "Two"), ("error/", "Error") })
public IHandlerBuilder Index() { var model = new SystemModel(_Systems); return(ModScriban.Page(Resource.FromAssembly("system_index.html"), (r, h) => new ViewModel <SystemModel>(r, h, model)) .Title("Systems")); }
public AdminLteTheme(string?title, IHandlerBuilder?logo, Func <IRequest, IHandler, ValueTask <UserProfile?> >?userProfile, Func <IRequest, IHandler, ValueTask <string?> >?footerLeft, Func <IRequest, IHandler, ValueTask <string?> >?footerRight, Func <IRequest, IHandler, ValueTask <string?> >?sidebar, Func <IRequest, IHandler, ValueTask <SearchBox?> >?searchBox, Func <IRequest, IHandler, ValueTask <string?> >?notifications, IMenuProvider?headerMenu) { _Title = title; var resources = Layout.Create() .Fallback(Modules.IO.Resources.From(ResourceTree.FromAssembly("AdminLTE.resources"))); HasLogo = (logo != null); if (logo != null) { resources.Add("logo.png", logo); } _UserProfile = userProfile; _FooterLeft = footerLeft; _FooterRight = footerRight; _Sidebar = sidebar; _SearchBox = searchBox; _HeaderMenu = headerMenu; _Notifications = notifications; Resources = resources; ErrorHandler = ModScriban.Template <ErrorModel>(Resource.FromAssembly("Error.html")).Build(); Renderer = ModScriban.Template <WebsiteModel>(Resource.FromAssembly("Template.html")).Build(); }
public FortuneHandler(IHandler parent) { Parent = parent; Page = ModScriban.Page(Data.FromResource("Fortunes.html"), (r, h) => GetFortunes(r, h)) .Title("Fortunes") .Build(this); Template = ModScriban.Template <TemplateModel>(Data.FromResource("Template.html")).Build(); }
public ScribanPageProvider(IHandler parent, IResourceProvider templateProvider, ModelProvider <T> modelProvider, ContentInfo pageInfo) { Parent = parent; TemplateProvider = templateProvider; ModelProvider = modelProvider; PageInfo = pageInfo; Renderer = ModScriban.Template <T>(templateProvider).Build(); }
public static IHandlerBuilder Build() { var index = ModScriban.Page(Data.FromResource("Index.html")) .Title("Examples"); return(Layout.Create() .Add("plaintext", Content.From("Hello, World!")) .Add("infrastructure", InfrastructureExamples.Create()) .Add("webservice", WebserviceExamples.Create()) .Add("listing", ListingExamples.Create()) .Index(index)); }
public ArcanaTheme(string?title, string?copyright, Func <IRequest, IHandler, ValueTask <string?> >?footer) { _Title = title; _Copyright = copyright; _Footer = footer; Resources = Modules.IO.Resources.From(ResourceTree.FromAssembly("Arcana.resources")); ErrorHandler = ModScriban.Template <ErrorModel>(Resource.FromAssembly("Error.html")).Build(); Renderer = ModScriban.Template <WebsiteModel>(Resource.FromAssembly("Template.html")).Build(); }
private static void Setup() { var resources = new string[] { "avatar.png", "logo.png", "mia.png", "ee1.PNG", "ee2.PNG", "ee3.PNG", "ee4.PNG" }; var main = Layout.Create() .Add("models", Controller.From <AIController>()) .Add("games-main", Controller.From <GameController>()) .Add("games-ggj", Controller.From <GGJController>()) .Add("games-eternal", Controller.From <EternalController>()) .Add("systems", Controller.From <SystemController>()) .Add("reports", Controller.From <ReportController>()) .Add("user", ModScriban.Page(Resource.FromAssembly("user.html")).Title("Internal Systems")) .Index(ModScriban.Page(Resource.FromFile("Pages/index.html")).Title("Home")); foreach (var resource in resources) { main.Add(resource, Download.From(Resource.FromAssembly(resource))); } var menu = Menu.Empty() .Add("{website}", "Home") .Add("/games-main/", "Games - Main", GameController.Links()) .Add("/games-eternal/", "Games - Eternal", EternalController.Links()) .Add("/games-ggj/", "Games - GGJ", GGJController.Links()) .Add("/models/", "AI Models", AIController.Links()) .Add("/systems/", "Systems", SystemController.Links()); var website = Website.Create() .Theme(GetAdminLTE()) .Menu(menu) .Content(main); Host.Create() .Defaults() .Console() .Handler(website) .Run(); }
public ArcanaTheme(string?title, string?copyright, string?footer1Title, IMenuProvider?footerMenu1, string?footer2Title, IMenuProvider?footerMenu2) { _Title = title; _Copyright = copyright; _FooterMenu1 = footerMenu1; _Footer1Title = footer1Title; _FooterMenu2 = footerMenu2; _Footer2Title = footer2Title; Resources = Static.Resources("Arcana.resources"); ErrorHandler = ModScriban.Template <ErrorModel>(Data.FromResource("Error.html")).Build(); Renderer = ModScriban.Template <WebsiteModel>(Data.FromResource("Template.html")).Build(); }
private static IHandlerBuilder Setup() { var content = Layout.Create() .Index(Page.From("Home", "This is the home page")) .Add("content", Page.From("Content", "This is additional content")); var main = Layout.Create() .Index(ModScriban.Page(Data.FromResource("Index.html")).Title("GenHTTP Themes")); foreach (var entry in GetThemes()) { var website = Website.Create() .Theme(entry.Theme) .Content(content); main.Add(entry.Name, website); } return(main); }
private static ITheme GetAdminLTE() { var menu = Menu.Empty() .Add("{website}/", "Home") .Add("/reports/", "Reports"); var notifications = ModScriban.Template <IBaseModel>(Resource.FromAssembly("Notifications.html")) .Build(); return(new AdminLteBuilder().Title("Dracon Interactive") .Logo(Download.From(Resource.FromAssembly("logo.png"))) .UserProfile((r, h) => new UserProfile("User Page", "/avatar.png", "/user")) .FooterLeft((r, h) => Helpers.Version) .FooterRight((r, h) => "Peter M Carey (2021)") .Sidebar((r, h) => SideBarConstructor()) .Search((r, h) => new SearchBox("")) .Header(menu) .Notifications((r, h) => notifications.RenderAsync(new ViewModel(r, h)).Result) .Build()); }
public LorahostTheme(IResourceProvider?header, string?copyright, string?title, string?subtitle, string?action, string?actionTitle) { _Copyright = copyright; _Title = title; _Subtitle = subtitle; _Action = action; _ActionTitle = actionTitle; var resources = Layout.Create() .Fallback(Static.Resources("Lorahost.resources")); if (header != null) { resources.Add("header.jpg", Download.From(header).Type(ContentType.ImageJpg)); } Resources = resources; ErrorHandler = ModScriban.Template <ErrorModel>(Data.FromResource("Error.html")).Build(); Renderer = ModScriban.Template <WebsiteModel>(Data.FromResource("Template.html")).Build(); }
public void TestRoutingToPath() { var providers = new List <IHandlerBuilder>() { ModScriban.Page(Data.FromString("{{ route path }}"), (IRequest r, IHandler h) => new PathModel(r, h)), ModRazor.Page(Data.FromString("@Model.Route(Model.Path)"), (IRequest r, IHandler h) => new PathModel(r, h)), }; foreach (var provider in providers) { var layout = Layout.Create() .Add("page", provider) .Add("test", Content.From("test")); using var runner = TestRunner.Run(layout); using var response = runner.GetResponse("/page"); var content = response.GetContent(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Contains("/test/1", content); } }