Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Nov 14, 2021
2 parents 313d7f1 + c6325de commit 467524c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Restore
run: dotnet restore
- name: Build
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

## 2.0.0-alpha-1

- Updated to .NET 6 and Giraffe 6.0.0-alpha-*
- Improved performance by removing redundant `ToArray` functions and making `XmlElement` a struct

## 1.4.0

- Added `slot` and `template` elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>GithubExample</RootNamespace>
</PropertyGroup>

Expand Down
14 changes: 7 additions & 7 deletions src/Giraffe.ViewEngine/Engine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module HtmlElements =
| KeyValue of string * string
| Boolean of string

type XmlElement = string * XmlAttribute[] // Name * XML attributes
type XmlElement = (struct(string * XmlAttribute list)) // Name * XML attributes

type XmlNode =
| ParentNode of XmlElement * XmlNode list // An XML element which contains nested XML elements
Expand All @@ -58,11 +58,11 @@ module HtmlElements =
let tag (tagName : string)
(attributes : XmlAttribute list)
(contents : XmlNode list) =
ParentNode ((tagName, Array.ofList attributes), contents)
ParentNode ((tagName, attributes), contents)

let voidTag (tagName : string)
(attributes : XmlAttribute list) =
VoidElement (tagName, Array.ofList attributes)
VoidElement (tagName, attributes)

/// <summary>
///
Expand Down Expand Up @@ -554,21 +554,21 @@ module internal ViewBuilder =

let rec internal buildNode (isHtml : bool) (sb : StringBuilder) (node : XmlNode) : unit =

let buildElement closingBracket (elemName, attributes : XmlAttribute array) =
let buildElement closingBracket struct(elemName, attributes : XmlAttribute list) =
match attributes with
| [||] -> do sb += "<" += elemName +! closingBracket
| [] -> do sb += "<" += elemName +! closingBracket
| _ ->
do sb += "<" +! elemName

attributes
|> Array.iter (fun attr ->
|> List.iter (fun attr ->
match attr with
| KeyValue (k, v) -> do sb += " " += k += "=\"" += v +! "\""
| Boolean k -> do sb += " " +! k)

do sb +! closingBracket

let inline buildParentNode (elemName, attributes : XmlAttribute array) (nodes : XmlNode list) =
let inline buildParentNode struct(elemName, attributes : XmlAttribute list) (nodes : XmlNode list) =
do buildElement ">" (elemName, attributes)
for node in nodes do buildNode isHtml sb node
do sb += "</" += elemName +! ">"
Expand Down
4 changes: 2 additions & 2 deletions src/Giraffe.ViewEngine/Giraffe.ViewEngine.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en-GB</NeutralLanguage>

<!-- Build settings -->
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<DebugType>portable</DebugType>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -46,5 +46,5 @@
<Compile Include="StringBuilderPool.fs" />
<Compile Include="Engine.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand Down
45 changes: 45 additions & 0 deletions tests/Giraffe.ViewEngine.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,51 @@ type HtmlUtf8Benchmark() =
ArrayPool<char>.Shared.Return(chars)
stringBuilder.Clear()

[<MemoryDiagnoser>]
type HtmlBuildBenchmark() =

let doc() =
div [] [
div [ _class "top-bar" ]
[ div [ _class "top-bar-left" ]
[ ul [ _class "dropdown menu"
_data "dropdown-menu" "" ]
[ li [ _class "menu-text" ]
[ rawText "Site Title" ]
li [ ]
[ a [ _href "#" ]
[ str """One <script>alert("hello world")</script>""" ]
ul [ _class "menu vertical" ]
[ li [ ]
[ a [ _href "#" ]
[ rawText "One" ] ]
li [ ]
[ a [ _href "#" ]
[ str "Two" ] ]
li [ ]
[ a [ _href "#" ]
[ rawText "Three" ] ] ] ]
li [ ]
[ a [ _href "#" ]
[ str "Two" ] ]
li [ ]
[ a [ _href "#" ]
[ str "Three" ] ] ] ]
div [ _class "top-bar-right" ]
[ ul [ _class "menu" ]
[ li [ ]
[ input [ _type "search"
_placeholder "Search" ] ]
li [ ]
[ button [ _type "button"
_class "button" ]
[ rawText "Search" ] ] ] ] ]
]

[<Benchmark( Baseline = true )>]
member this.Default() =
doc()

[<EntryPoint>]
let main args =
let asm = typeof<HtmlUtf8Benchmark>.Assembly
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,7 +19,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.*" />
<PackageReference Include="NSubstitute" Version="4.2.*" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.*" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 467524c

Please sign in to comment.