From 32467aec15d825a30ba400cc36996a745b2da0e1 Mon Sep 17 00:00:00 2001 From: "Angel D. Munoz" Date: Fri, 4 Jun 2021 23:54:08 -0500 Subject: [PATCH] should work now --- .config/dotnet-tools.json | 12 +++++++++ IO.fs | 8 +++--- Program.fs | 1 + README.md | 10 ++++++++ Templates.fs | 51 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 README.md diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..5d6dd36 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fable": { + "version": "3.2.2", + "commands": [ + "fable" + ] + } + } +} \ No newline at end of file diff --git a/IO.fs b/IO.fs index d238f51..0b00772 100644 --- a/IO.fs +++ b/IO.fs @@ -76,10 +76,12 @@ module IO = let fsproj = Path.Combine(root, "Sutil.Shoelace.fsproj") - use library = File.CreateText library - library.WriteLine "namespace Sutil.Shoelace\n" - library.WriteLine "type Shoelace = class end" + use library = File.Create library + let bytes = + getBytesFromStr (Templates.getShoelaceAPIClass components) + + library.Write bytes use fsproj = File.Create fsproj let writeComponents = Templates.getFsFileReference components diff --git a/Program.fs b/Program.fs index 2e51814..875a631 100644 --- a/Program.fs +++ b/Program.fs @@ -20,6 +20,7 @@ let main argv = let version = metadata.version printfn "Downloaded %s, version %s" name version tryWriteFiles version metadata.components + printfn $"Wrote: [{metadata.components.Length}] Components to [Sutil.Shoelace]" return 0 | None -> return 1 } diff --git a/README.md b/README.md new file mode 100644 index 0000000..b51a691 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Shoelace Generator + +This is a [Shoelace](https://github.com/shoelace-style/shoelace) wrapper generator for [Sutil](https://github.com/davedawkins/Sutil) heavily inspider in [react-generator](https://github.com/shoelace-style/react-generator) + +# Run +``` +dotnet tool restore + +dotnet run && dotnet fable --cwd Sutil.Shoelace +``` \ No newline at end of file diff --git a/Templates.fs b/Templates.fs index ce2bc3c..86c789a 100644 --- a/Templates.fs +++ b/Templates.fs @@ -205,7 +205,7 @@ let getCompModule (tagAndName: string * string) (comp: SlProp array) = $""" /// [] -module {className} = +module internal {className} = /// doesn't provide any binding helper logic and allows the user to take full /// control over the HTML Element either to create static HTML or do custom bindings /// via "bindFragment" or "Bind.attr("", binding)" @@ -248,6 +248,55 @@ type {comp.className} = {attrsTpl}{attrsModule}{getCompModule (comp.tag, comp.className) (comp.props)}""" +let getShoelaceAPIClass (components: SlComponent array) = + let opens = + components + |> Array.fold + (fun (current: string) next -> + let name = next.className.[2..] + + let current = + if current.Length > 0 then + $"{current}\n" + else + "" + + $"{current}open Sutil.Shoelace.{name}") + "" + + let methods = + components + |> Array.fold + (fun (current: string) next -> + let current = + if current.Length > 0 then + $"{current}\n " + else + "" + + let stateful = + if next.props.Length > 0 then + $""" + static member inline {next.className} (attrs: IStore<{next.className}Attributes>, content: NodeFactory seq) = + {next.className}.stateful attrs content""" + else + "" + + ($""" + {current}static member inline {next.className} (content: NodeFactory seq) = + {next.className}.stateless content + {stateful}""" + .TrimStart())) + "" + + $"""namespace Sutil.Shoelace +open Sutil +open Sutil.DOM +{opens} +type Shoelace = + {methods}""" + + let getFsFileReference (components: SlComponent array) = components |> Array.fold