Skip to content

Commit

Permalink
Web: Add new page for flag usage (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlb authored Oct 23, 2022
1 parent 1d1453a commit dd49b88
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
8 changes: 8 additions & 0 deletions SMBolero.Client/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Bolero.Templating.Client
/// Routing endpoints definition.
type Page =
| [<EndPoint "?main">] Home
| [<EndPoint "?flags">] FlagPage
| [<EndPoint "?help">] Help

/// The Elmish application's model.
Expand Down Expand Up @@ -76,6 +77,11 @@ let aboutPage model dispatch =
Main.About()
.Elt()

let flagPage model dispatch =
Main.FlagPage()
.FlagHelp(Options.flagsHelp.Value)
.Elt()

let homePage model dispatch =
Main.Home()
.Minify(fun _ -> dispatch Minify)
Expand All @@ -94,12 +100,14 @@ let view model dispatch =
Main()
.Menu(concat {
menuItem model Home "Minifier"
menuItem model FlagPage "Flags"
menuItem model Help "Help"
})
.Body(
cond model.page <| function
| Home -> homePage model dispatch
| Help -> aboutPage model dispatch
| FlagPage -> flagPage model dispatch
)
.Error(
cond model.error <| function
Expand Down
2 changes: 1 addition & 1 deletion SMBolero.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bolero Application</title>
<title>Shader Minifier</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
Expand Down
23 changes: 13 additions & 10 deletions SMBolero.Client/wwwroot/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,25 @@ <h1>Menu</h1>
</div>

<template id="Home">
<h1 class="title">Shader Minifier</h1>
<h1>Shader Minifier</h1>
<p>
<textarea rows="15" id="input" bind="${ShaderInput}"></textarea>
<input type="text" style="width: 50%" name="flags" bind="${Flags}" />
<button onclick="${Minify}" class="button">Minify!</button>
<textarea rows="15" readonly>${ShaderOutput}</textarea>
<p>
Tip: use the flags <code>--format indented --no-renaming</code> for debugging.
</p>
</template>

<template id="FlagPage">
<h1>Flags</h1>

<pre>${FlagHelp}</pre>
</template>

<template id="About">
<h1 class="title">About</h1>
<h1>About</h1>
<div class="content">

<p>
Expand All @@ -44,14 +52,9 @@ <h1 class="title">About</h1>
<p>
See <a href="https://github.com/laurentlb/Shader_Minifier">Shader Minifier</a>
on GitHub for more information about the tool.
If you use it frequently, you might want to download Shader Minifier and run it on your computer.
as it has more features and can be integrated in your toolchain.
</p>

<p>
This version of Shader Minifier was compiled to WebAssembly, and can be used offline.
Some features are still missing, in particular settings are not yet available here.
Follow <a href="https://github.com/laurentlb/Shader_Minifier/issues/145">issue #145</a> on GitHub for updates.
This version of Shader Minifier was compiled to WebAssembly, and runs entirely in the browser.
If you use it frequently, you might want to download the Shader Minifier binary and run it on your computer,
as it can be integrated in your toolchain.
</p>

<p>
Expand Down
16 changes: 10 additions & 6 deletions src/options.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,22 @@ module Globals =

open Globals

let private initPrivate argv needFiles =
let argParser = ArgumentParser.Create<CliArguments>(
let helpTextMessage = sprintf "Shader Minifier %s - https://github.com/laurentlb/Shader_Minifier" version

let private argParser = lazy (
ArgumentParser.Create<CliArguments>(
programName = "Shader Minifier",
helpTextMessage =
sprintf "Shader Minifier %s - https://github.com/laurentlb/Shader_Minifier" version)
helpTextMessage = helpTextMessage))

let args = argParser.Parse(argv)
let private initPrivate argv needFiles =
let args = argParser.Value.Parse(argv)

let opt = args.GetResult(NoRenamingList, defaultValue = "main")
let noRenamingList = [for i in opt.Split([|','|]) -> i.Trim()]
let filenames = args.GetResult(Filenames, defaultValue=[]) |> List.toArray

if filenames.Length = 0 && needFiles then
printfn "%s" (argParser.PrintUsage(message = "Missing parameter: the list of shaders to minify"))
printfn "%s" (argParser.Value.PrintUsage(message = "Missing parameter: the list of shaders to minify"))
false
else
options.outputName <- args.GetResult(OutputName, defaultValue = "shader_code.h")
Expand All @@ -115,5 +117,7 @@ let private initPrivate argv needFiles =
options.filenames <- filenames
true

let flagsHelp = lazy (argParser.Value.PrintUsage(message = helpTextMessage))

let init argv = initPrivate argv false |> ignore
let initFiles argv = initPrivate argv true

0 comments on commit dd49b88

Please sign in to comment.