Skip to content

Commit 91c3c46

Browse files
authored
Merge pull request #8 from falcoframework/html-module
The unified DSL module introduces consistent prefix-based naming conventions for elements, text shortcuts, and attributes, making code cleaner and more readable. The example usage demonstrates how this approach simplifies markup creation while preserving the flexibility of the original modules.
2 parents 39bca4c + 3d13134 commit 91c3c46

16 files changed

Lines changed: 1282 additions & 108 deletions

Build.ps1

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ param (
99
[string] $Configuration = "Debug",
1010

1111
[switch] $NoRestore,
12-
12+
1313
[switch] $Clean
1414
)
1515

@@ -24,24 +24,21 @@ $srcDir = Join-Path -Path $rootDir -ChildPath 'src'
2424
$testDir = Join-Path -Path $rootDir -ChildPath 'test'
2525

2626
switch ($Action) {
27-
"Test" { $projectdir = Join-Path -Path $testDir -ChildPath 'Falco.Markup.Tests' }
28-
"Pack" { $projectDir = Join-Path -Path $srcDir -ChildPath 'Falco.Markup' }
29-
"BuildSite" { $projectDir = Join-Path -Path $rootDir -ChildPath 'site' }
30-
"DevelopSite" { $projectDir = Join-Path -Path $rootDir -ChildPath 'site' }
31-
Default { $projectDir = Join-Path -Path $srcDir -ChildPath 'Falco.Markup' }
27+
"Test" { $projectdir = Join-Path -Path $testDir -ChildPath 'Falco.Tests' }
28+
"Pack" { $projectDir = Join-Path -Path $srcDir -ChildPath 'Falco' }
29+
Default { $projectDir = Join-Path -Path $srcDir -ChildPath 'Falco' }
3230
}
3331

3432
if(!$NoRestore.IsPresent) {
3533
RunCommand "dotnet restore $projectDir --force --force-evaluate --nologo --verbosity quiet"
3634
}
3735

38-
if ($Clean)
39-
{
36+
if ($Clean) {
4037
RunCommand "dotnet clean $projectDir -c $Configuration --nologo --verbosity quiet"
4138
}
4239

4340
switch ($Action) {
44-
"Test" { RunCommand "dotnet test `"$projectDir`"" }
45-
"Pack" { RunCommand "dotnet pack `"$projectDir`" -c $Configuration --include-symbols --include-source" }
46-
Default { RunCommand "dotnet build `"$projectDir`" -c $Configuration" }
47-
}
41+
"Test" { RunCommand "dotnet test `"$projectDir`"" }
42+
"Pack" { RunCommand "dotnet pack `"$projectDir`" -c $Configuration --include-symbols --include-source" }
43+
Default { RunCommand "dotnet build `"$projectDir`" -c $Configuration" }
44+
}

Falco.Markup.sln

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,63 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{25A4B987-E
1111
EndProject
1212
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Falco.Markup.Tests", "test\Falco.Markup.Tests\Falco.Markup.Tests.fsproj", "{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}"
1313
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{5D20AA90-6969-D8BD-9DCD-8634F4692FDA}"
15+
EndProject
16+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "StaticWebsite", "samples\StaticWebsite\StaticWebsite.fsproj", "{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
21+
Debug|x64 = Debug|x64
22+
Debug|x86 = Debug|x86
1723
Release|Any CPU = Release|Any CPU
18-
EndGlobalSection
19-
GlobalSection(SolutionProperties) = preSolution
20-
HideSolutionNode = FALSE
24+
Release|x64 = Release|x64
25+
Release|x86 = Release|x86
2126
EndGlobalSection
2227
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2328
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2429
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|x64.ActiveCfg = Debug|Any CPU
31+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|x64.Build.0 = Debug|Any CPU
32+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|x86.ActiveCfg = Debug|Any CPU
33+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Debug|x86.Build.0 = Debug|Any CPU
2534
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2635
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|x64.ActiveCfg = Release|Any CPU
37+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|x64.Build.0 = Release|Any CPU
38+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|x86.ActiveCfg = Release|Any CPU
39+
{06D04004-6DB3-4522-8EFA-E5239219EF0D}.Release|x86.Build.0 = Release|Any CPU
2740
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2841
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|x64.ActiveCfg = Debug|Any CPU
43+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|x64.Build.0 = Debug|Any CPU
44+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|x86.ActiveCfg = Debug|Any CPU
45+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Debug|x86.Build.0 = Debug|Any CPU
2946
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
3047
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|x64.ActiveCfg = Release|Any CPU
49+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|x64.Build.0 = Release|Any CPU
50+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|x86.ActiveCfg = Release|Any CPU
51+
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA}.Release|x86.Build.0 = Release|Any CPU
52+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|x64.ActiveCfg = Debug|Any CPU
55+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|x64.Build.0 = Debug|Any CPU
56+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|x86.ActiveCfg = Debug|Any CPU
57+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Debug|x86.Build.0 = Debug|Any CPU
58+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|x64.ActiveCfg = Release|Any CPU
61+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|x64.Build.0 = Release|Any CPU
62+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|x86.ActiveCfg = Release|Any CPU
63+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D}.Release|x86.Build.0 = Release|Any CPU
64+
EndGlobalSection
65+
GlobalSection(SolutionProperties) = preSolution
66+
HideSolutionNode = FALSE
3167
EndGlobalSection
3268
GlobalSection(NestedProjects) = preSolution
3369
{06D04004-6DB3-4522-8EFA-E5239219EF0D} = {795C5C1E-4386-49BE-8B93-CB0722AC6220}
3470
{A6AADC18-B737-4CB4-8B35-857E9F94C5CA} = {25A4B987-EB43-4351-A7CD-C5451613B590}
71+
{2C6417E9-ACAE-4B44-A4FA-31D53720F09D} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA}
3572
EndGlobalSection
3673
EndGlobal

samples/StaticWebsite.fsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

samples/StaticWebsite/Program.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
open System
2+
open System.IO
3+
open Falco.Markup
4+
5+
// Components
6+
let divider =
7+
_hr [ _class_ "divider" ]
8+
9+
// Template
10+
let master (title : string) (content : XmlNode list) =
11+
_html [ _lang_ "en" ] [
12+
_head [] [
13+
_title [] [ _text "Sample App" ]
14+
]
15+
_body [] content
16+
]
17+
18+
// Views
19+
let homeView =
20+
master "Homepage" [
21+
_h1' "Homepage"
22+
divider
23+
_p' "Lorem ipsum dolor sit amet."
24+
]
25+
26+
let aboutView =
27+
master "About Us" [
28+
_h1' "About"
29+
divider
30+
_p' "Lorem ipsum dolor sit amet."
31+
]
32+
33+
// Generate website
34+
let writeHtmlToFile (filename : string) (html : XmlNode) =
35+
File.WriteAllText(
36+
Path.Join(__SOURCE_DIRECTORY__, filename),
37+
renderHtml html)
38+
39+
writeHtmlToFile "_homepage.html" homeView
40+
writeHtmlToFile "_about.html" aboutView
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\Falco.Markup\Falco.Markup.fsproj" />
14+
</ItemGroup>
15+
16+
</Project>

samples/StaticWebsite/_about.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html lang="en"><head><title>Sample App</title></head><body><h1>About</h1><hr class="divider" /><p>Lorem ipsum dolor sit amet.</p></body></html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html lang="en"><head><title>Sample App</title></head><body><h1>Homepage</h1><hr class="divider" /><p>Lorem ipsum dolor sit amet.</p></body></html>

src/Falco.Markup/Attr.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Attr =
1818
"class", " "
1919
"style", "; "
2020
"accept", ", " ]
21-
21+
2222
/// Merge two XmlAttribute lists
2323
let merge (attrs1 : XmlAttribute list) (attrs2 : XmlAttribute list) =
2424

@@ -446,7 +446,7 @@ module Attr =
446446

447447
/// Alias for `enctype=multipart/form-data`
448448
let enctypeMultipart = enctype "multipart/form-data"
449-
449+
450450
// Alias for `method=post`
451451
let methodPost = method "post"
452452

@@ -470,7 +470,7 @@ module Attr =
470470

471471
/// Alias for `target=_unfencedTop`
472472
let targetUnfencedTop = target "_unfencedTop"
473-
473+
474474
/// Alias for `type=button`
475475
let typeButton = type' "button"
476476

@@ -545,35 +545,35 @@ module Attr =
545545
value (x.ToString())
546546

547547
/// Alias for `value={str}` by invoking `_.ToString(format)` on input
548-
let inline valueStringf format (x : ^T when ^T : (member ToString : string -> string)) =
548+
let inline valueStringf format (x : ^T when ^T : (member ToString : string -> string)) =
549549
value (x.ToString(format))
550550

551551
/// Alias for `Attr.valueStringf "yyyy-MM-dd" dt`
552552
let valueDate (dt : DateTime) =
553553
valueStringf "yyyy-MM-dd" dt
554554

555555
/// Alias for `Attr.valueStringf "s" dt`
556-
let valueDatetimeLocal (dt : DateTime) =
557-
valueStringf "s" dt
556+
let valueDatetimeLocal (dt : DateTime) =
557+
valueStringf "s" dt
558558

559559
/// Alias for `Attr.valueStringf "yyyy-MM"`
560560
let valueMonth (dt : DateTime) =
561561
valueStringf "yyyy-MM" dt
562562

563-
/// Alias for `Attr.valueStringf "hh\:mm" time`
564-
let valueTime (time : TimeSpan) =
563+
/// Alias for `Attr.valueStringf "hh\:mm" time`
564+
let valueTime (time : TimeSpan) =
565565
valueStringf "hh\:mm" time
566-
567-
let private cal = System.Globalization.GregorianCalendar(GregorianCalendarTypes.USEnglish)
566+
567+
let private cal = GregorianCalendar(GregorianCalendarTypes.USEnglish)
568568

569569
/// Alias for `value={yyyy-W#}` (ex: `value=1986-W50`)
570-
let valueWeek (dt : DateTime) =
570+
let valueWeek (dt : DateTime) =
571571
let wk = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday).ToString("00")
572572
let yr = dt.ToString("yyyy")
573573
value (sprintf "%s-W%s" yr wk)
574-
574+
575575
/// Invoke `fn` if `Some` otherwise return `value=""`
576-
let valueOption fn opt =
576+
let valueOption fn opt =
577577
match opt with Some x -> fn x | None -> valueEmpty
578578

579579
//
@@ -841,4 +841,4 @@ module Attr =
841841
let onwaiting = create "onwaiting"
842842

843843
/// `wheel={value}` event
844-
let onwheel = create "wheel"
844+
let onwheel = create "wheel"

src/Falco.Markup/Falco.Markup.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Compile Include="Attr.fs" />
4747
<Compile Include="Elem.fs" />
4848
<Compile Include="Text.fs" />
49+
<Compile Include="Html.fs" />
4950
<Compile Include="Svg.fs" />
5051
<Compile Include="Templates.fs" />
5152
<Compile Include="TestHelpers.fs" />

0 commit comments

Comments
 (0)