Skip to content

Commit

Permalink
Add server-side Bolero.Html, use it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Apr 11, 2021
1 parent 1f51a38 commit 5c1be5f
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 689 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"fake-cli": {
"version": "5.20.3",
"version": "5.20.4",
"commands": [
"fake"
]
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ You can use the following options to customize the project being created:

If `false`, the solution only contains the `Client` project that is compiled to WebAssembly.

* `--razor`, `-r`:
* `--hostpage`:

If `true` (the default if `server=true`), the server-side project includes a Razor page that can be configured to serve the application as client-side or server-side Blazor ([learn about the difference](https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-models?view=aspnetcore-3.0)). When the application is in Development environment, both modes are available by passing `?server=true` or `false` in the URL.
Determines how the server-side HTML page content is written. Can be one of:

If `false` (the default and only possible value if `server=false`), the application is served as client-side Blazor in a plain HTML file.
* `bolero`: using Bolero.Html functions.

* `razor`: using a dynamically-compiled Razor page.

* `html`: using a plain .html file.

* `--hotreload`, `-ho`:

Expand Down
38 changes: 12 additions & 26 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,18 @@ let buildOutputDir = slnDir </> "build"
let packageOutputFile o = buildOutputDir </> sprintf "Bolero.Templates.%s.nupkg" (version o)
let variantsToTest =
[
"NoRazor.Server.Reload", "--server --hotreload --minimal=false --razor=false"
"NoRazor.Server.NoReload", "--server --hotreload=false --minimal=false --razor=false"
"NoRazor.Server.NoHtml", "--server --html=false --minimal=false --razor=false"
"NoRazor.Server.Reload.Pwa", "--server --hotreload --minimal=false --razor=false --pwa"
"NoRazor.Server.NoReload.Pwa", "--server --hotreload=false --minimal=false --razor=false --pwa"
"NoRazor.Server.NoHtml.Pwa", "--server --html=false --minimal=false --razor=false --pwa"
"NoRazor.NoServer.NoReload", "--server=false --hotreload=false --minimal=false --razor=false"
"NoRazor.NoServer.NoHtml", "--server=false --html=false --minimal=false --razor=false"
"NoRazor.NoServer.NoReload.Pwa", "--server=false --hotreload=false --minimal=false --razor=false --pwa"
"NoRazor.NoServer.NoHtml.Pwa", "--server=false --html=false --minimal=false --razor=false --pwa"
"Razor.Server.Reload", "--server --hotreload --minimal=false --razor"
"Razor.Server.NoReload", "--server --hotreload=false --minimal=false --razor"
"Razor.Server.NoHtml", "--server --html=false --minimal=false --razor"
"Razor.Server.Reload.Pwa", "--server --hotreload --minimal=false --razor --pwa"
"Razor.Server.NoReload.Pwa", "--server --hotreload=false --minimal=false --razor --pwa"
"Razor.Server.NoHtml.Pwa", "--server --html=false --minimal=false --razor --pwa"
"Razor.NoServer.NoReload", "--server --hotreload=false --minimal=false --razor"
"Razor.NoServer.NoHtml", "--server --html=false --minimal=false --razor"
"Razor.NoServer.NoReload.Pwa", "--server --hotreload=false --minimal=false --razor --pwa"
"Razor.NoServer.NoHtml.Pwa", "--server --html=false --minimal=false --razor --pwa"
"Minimal.Server.Reload", "--server --hotreload --minimal --razor=false"
"Minimal.Server.NoReload", "--server --hotreload=false --minimal --razor=false"
"Minimal.NoServer.NoReload", "--server=false --hotreload=false --minimal"
"Minimal.Server.Reload.Pwa", "--server --hotreload --minimal --razor=false --pwa"
"Minimal.Server.NoReload.Pwa", "--server --hotreload=false --minimal --razor=false --pwa"
"Minimal.NoServer.NoReload.Pwa", "--server=false --hotreload=false --minimal --pwa"
for pwak, pwav in [("Pwa", "true"); ("NoPwa", "false")] do
// Server
for hostk, hostv in [("Bolero", "bolero"); ("Razor", "razor"); ("Html", "html")] do
for htmlk, reloadv, htmlv in [("Reload", "true", "true"); ("NoReload", "false", "true"); ("NoHtml", "false", "false")] do
for minik, miniv in [("Minimal", "true"); ("Full", "false")] do
if not (miniv = "true" && htmlv = "true") then
$"{minik}.Server{hostk}.{htmlk}.{pwak}", $"--server --minimal={miniv} --hostpage={hostv} --pwa={pwav} --html={htmlv} --hotreload={reloadv}"
// Client
for htmlk, htmlv in [("Html", "true"); ("NoHtml", "false")] do
for minik, miniv in [("Minimal", "true"); ("Full", "false")] do
if not (miniv = "true" && htmlv = "true") then
$"{minik}.NoServer.{htmlk}.{pwak}", $"--server=false --minimal={miniv} --pwa={pwav} --html={htmlv}"
]

Target.description "Create the NuGet package containing the templates."
Expand Down
37 changes: 37 additions & 0 deletions content/application/.template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "http://json.schemastore.org/dotnetcli.host",
"symbolInfo": {
"minimal": {
"longName": "minimal",
"shortName": "m"
},
"server": {
"longName": "server",
"shortName": "s"
},
"html": {
"longName": "html",
"shortName": "ht"
},
"hotreload": {
"longName": "hotreload",
"shortName": "hr"
},
"hostpage": {
"longName": "hostpage",
"shortName": "hp"
},
"pwa": {
"longName": "pwa",
"shortName": "pwa"
},
"nightly": {
"longName": "nightly",
"shortName": "ni"
},
"paket": {
"longName": "paket",
"shortName": "p"
}
}
}
39 changes: 29 additions & 10 deletions content/application/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@
"dataType": "bool",
"defaultValue": "true"
},
"razor": {
"hostpage": {
"type": "parameter",
"isRequired": false,
"description": "Use Razor on the server side (ignored if server=false)",
"dataType": "bool",
"defaultValue": "true"
"description": "How the static HTML content is generated (ignored if server=false)",
"dataType": "choice",
"choices": [
{"choice":"bolero","description":"A page defined with Bolero's html functions"},
{"choice":"html","description":"A plain index.html file"},
{"choice":"razor","description":"A dynamically compiled Razor page"}
],
"defaultValue":"bolero"
},
"pwa": {
"type": "parameter",
Expand Down Expand Up @@ -78,10 +83,18 @@
"dataType": "bool",
"value": "(hotreload && html && server_actual)"
},
"razor_actual": {
"type": "computed",
"dataType": "bool",
"value": "(razor && server_actual)"
"bolero_version": {
"type": "generated",
"generator": "switch",
"replaces": "BOLERO_VERSION",
"parameters": {
"evaluator": "C++",
"datatype": "string",
"cases": [
{"condition": "(nightly)", "value": "0.*-*"},
{"condition": "(!nightly)", "value": "0.*"}
]
}
}
},
"sources": [
Expand Down Expand Up @@ -127,14 +140,20 @@
]
},
{
"condition": "(!razor_actual)",
"condition": "(hostpage != \"bolero\")",
"exclude": [
"src/Bolero.Template.Server/Index.fs"
]
},
{
"condition": "(hostpage != \"razor\")",
"exclude": [
"src/Bolero.Template.Server/Pages/_Host.cshtml",
"src/Bolero.Template.Server/HostModel.fs"
]
},
{
"condition": "(razor_actual)",
"condition": "(hostpage != \"html\")",
"exclude": [
"src/Bolero.Template.Client/wwwroot/index.html"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<Compile Include="Startup.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bolero" Version="0.*" />
<PackageReference Include="Bolero.Build" Version="0.*" />
<PackageReference Include="Bolero" Version="BOLERO_VERSION" />
<PackageReference Include="Bolero.Build" Version="BOLERO_VERSION" />
<!-- //#if (hotreload_actual) -->
<PackageReference Include="Bolero.HotReload" Version="0.*" />
<PackageReference Include="Bolero.HotReload" Version="BOLERO_VERSION" />
<!-- //#endif -->
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.*" />
<!-- //#if (server_actual) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
<!-- //#if (!minimal) -->
<Compile Include="BookService.fs" />
<!-- //#endif -->
<!-- //#if (hostpage == "bolero") -->
<Compile Include="Index.fs" />
<!-- //#endif -->
<Compile Include="Startup.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bolero.Template.Client\Bolero.Template.Client.fsproj" />
<PackageReference Include="Bolero.Server" Version="0.*" />
<PackageReference Include="Bolero.Server" Version="BOLERO_VERSION" />
<!-- //#if (hotreload_actual) -->
<PackageReference Include="Bolero.HotReload.Server" Version="0.*" />
<PackageReference Include="Bolero.HotReload.Server" Version="BOLERO_VERSION" />
<!-- //#endif -->
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="5.0.*" />
<!-- //#if (razor_actual) -->
<!-- //#if (hostpage == "razor") -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.*" />
<!-- //#endif -->
</ItemGroup>
Expand Down
36 changes: 36 additions & 0 deletions content/application/src/Bolero.Template.Server/Index.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Bolero.Template.Server.Index

open Bolero
open Bolero.Html
open Bolero.Server.Html
open Bolero.Template

let page = doctypeHtml [] [
head [] [
meta [attr.charset "UTF-8"]
meta [attr.name "viewport"; attr.content "width=device-width, initial-scale=1.0"]
title [] [text "Bolero Application"]
``base`` [attr.href "/"]
link [attr.rel "stylesheet"; attr.href "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css"]
link [attr.rel "stylesheet"; attr.href "css/index.css"]
//#if (pwa)
link [attr.rel "manifest"; attr.href "manifest.json"]
link [attr.rel "apple-touch-icon"; attr.sizes "512x512"; attr.href "icon-512.png"]
//#endif
]
body [] [
nav [attr.classes ["navbar"; "is-dark"]; "role" => "navigation"; attr.aria "label" "main navigation"] [
div [attr.classes ["navbar-brand"]] [
a [attr.classes ["navbar-item"; "has-text-weight-bold"; "is-size-5"]; attr.href "https://fsbolero.io"] [
img [attr.style "height:40px"; attr.src "https://github.com/fsbolero/website/raw/master/src/Website/img/wasm-fsharp.png"]
text "  Bolero"
]
]
]
div [attr.id "main"] [rootComp<Client.Main.MyApp>]
boleroScript
//#if (pwa)
script [] [RawHtml "navigator.serviceWorker.register('service-worker.js');"]
//#endif
]
]
15 changes: 8 additions & 7 deletions content/application/src/Bolero.Template.Server/Startup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.DependencyInjection
open Bolero
open Bolero.Remoting.Server
//#if (razor_actual)
open Bolero.Server.RazorHost
//#endif
open Bolero.Server
open Bolero.Template
//#if (hotreload_actual)
open Bolero.Templating.Server
Expand All @@ -20,7 +18,7 @@ type Startup() =
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
member this.ConfigureServices(services: IServiceCollection) =
//#if (razor_actual)
//#if (hostpage == "razor")
services.AddMvc().AddRazorRuntimeCompilation() |> ignore
services.AddServerSideBlazor() |> ignore
//#else
Expand All @@ -34,7 +32,7 @@ type Startup() =
.Services
.AddRemoting<BookService>()
//#endif
//#if (razor_actual)
//#if (hostpage != "html")
.AddBoleroHost()
//#endif
//#if (hotreload_actual)
Expand All @@ -60,10 +58,13 @@ type Startup() =
endpoints.UseHotReload()
#endif
//#endif
//#if (razor_actual)
//#if (hostpage == "razor")
endpoints.MapBlazorHub() |> ignore
endpoints.MapFallbackToPage("/_Host") |> ignore)
//#else
//#elseif (hostpage == "bolero")
endpoints.MapBlazorHub() |> ignore
endpoints.MapFallbackToBolero(Index.page) |> ignore)
//#elseif (hostpage == "html")
endpoints.MapControllers() |> ignore
endpoints.MapFallbackToFile("index.html") |> ignore)
//#endif
Expand Down
Loading

0 comments on commit 5c1be5f

Please sign in to comment.