Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
should work now
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelMunoz committed Jun 5, 2021
1 parent 69337e5 commit 32467ae
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fable": {
"version": "3.2.2",
"commands": [
"fable"
]
}
}
}
8 changes: 5 additions & 3 deletions IO.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
51 changes: 50 additions & 1 deletion Templates.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ let getCompModule (tagAndName: string * string) (comp: SlProp array) =
$"""
///
[<RequireQualifiedAccess>]
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)"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32467ae

Please sign in to comment.