示例#1
0
        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}"));
        }
示例#2
0
        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"));
        }
示例#3
0
        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"));
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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);
            }
        }
        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"));
        }
示例#8
0
        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();
        }
示例#9
0
        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));
        }
示例#10
0
        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();
        }
示例#11
0
        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);
        }
示例#12
0
        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);
            }
        }