Skip to content

Commit

Permalink
Output now keeps original case (XAML support)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzoukr committed Jan 17, 2017
1 parent 96bd92f commit 0119770
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
@@ -1,3 +1,6 @@
### 1.1.0 - January 17 2017
* Output now keeps original case (XAML support)

### 1.0.0 - January 10 2017
* Public release

Expand Down
8 changes: 4 additions & 4 deletions src/Fue/AssemblyInfo.fs
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Fue")>]
[<assembly: AssemblyProductAttribute("Fue")>]
[<assembly: AssemblyDescriptionAttribute("F# templating library with simple syntax designed for smooth work with F# types")>]
[<assembly: AssemblyVersionAttribute("1.0.0")>]
[<assembly: AssemblyFileVersionAttribute("1.0.0")>]
[<assembly: AssemblyVersionAttribute("1.1.0")>]
[<assembly: AssemblyFileVersionAttribute("1.1.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Fue"
let [<Literal>] AssemblyProduct = "Fue"
let [<Literal>] AssemblyDescription = "F# templating library with simple syntax designed for smooth work with F# types"
let [<Literal>] AssemblyVersion = "1.0.0"
let [<Literal>] AssemblyFileVersion = "1.0.0"
let [<Literal>] AssemblyVersion = "1.1.0"
let [<Literal>] AssemblyFileVersion = "1.1.0"
2 changes: 1 addition & 1 deletion src/Fue/Compiler.fs
Expand Up @@ -7,7 +7,7 @@ open HtmlAgilityPack
open Extensions

let private asDocument elms =
let doc = HtmlDocument()
let doc = HtmlDocument.Create()
elms |> List.iter (doc.DocumentNode.AppendChild >> ignore)
match doc.DocumentNode.ChildNodes.Count with
| 0 -> ""
Expand Down
7 changes: 6 additions & 1 deletion src/Fue/Extensions.fs
Expand Up @@ -6,8 +6,13 @@ type HtmlNode with
member this.TryGetAttribute attr = this.Attributes |> Seq.filter (fun x -> x.Name = attr) |> Seq.tryHead

type HtmlDocument with
static member ParseNode html =
static member Create() =
let doc = new HtmlDocument()
doc.OptionOutputOriginalCase <- true
doc

static member ParseNode html =
let doc = HtmlDocument.Create()
// fix for http://stackoverflow.com/questions/293342/htmlagilitypack-drops-option-end-tags
HtmlNode.ElementsFlags.Remove("option") |> ignore
doc.LoadHtml(html)
Expand Down
6 changes: 3 additions & 3 deletions src/Fue/NodeCompiler.fs
Expand Up @@ -38,7 +38,7 @@ let private compileAttributes data attrs =
let private prepareAttributes data cleanFunc = Seq.filter cleanFunc >> compileAttributes data

let private newElements name children attributes =
let node = HtmlDocument().CreateElement(name)
let node = HtmlDocument.Create().CreateElement(name)
attributes |> Seq.iter (fun (name, value) -> node.SetAttributeValue(name, value) |> ignore)
children |> List.iter (fun x -> if x <> null then node.AppendChild(x) |> ignore else ())
node |> asResults
Expand All @@ -57,9 +57,9 @@ let private compileNode compileFun (source:HtmlNode) data attributesFilter =
let elms = source.ChildNodes |> Seq.toList |> List.map (compileFun data) |> Rop.fold
match source.Name with
| "fs-template" -> elms
| name ->
| _ ->
let attrs = source.Attributes |> prepareAttributes data attributesFilter
Rop.bind2 (newElements name) elms attrs
Rop.bind2 (newElements source.OriginalName) elms attrs

let private compileIf compileFun (source:HtmlNode) data boolValue =
boolValue |> ValueCompiler.compile data
Expand Down
10 changes: 9 additions & 1 deletion tests/Fue.Tests/Compiler.fs
Expand Up @@ -395,4 +395,12 @@ let ``Compiles for with option tag`` () =
init
|> add "values" values
|> fromText """<option fs-for="loc in values">{{{loc}}}</option>"""
|> should equal """<option>0</option><option>1</option>"""
|> should equal """<option>0</option><option>1</option>"""

[<Test>]
let ``Keeps case sensitivity``() =
let html = """<HelloWorld>{{{value}}}</HelloWorld>"""
init
|> add "value" "It works!"
|> fromText html
|> should equal "<HelloWorld>It works!</HelloWorld>"

0 comments on commit 0119770

Please sign in to comment.