Failess ':' CSS EDSL in FSharp

Posted on 1 January 2013

Failess features:

open Fake
open Failess

Target "custom.css" (fun () ->
    CSS ("..\css\custom.css") [
        code @ Color.black
        "/* When highlighted code blocks are too wide, they wrap. Resulting in the */"
        "/* line numbers column's rows not lining up with the code rows. Prevent */"
        "/* wrapping. */"
        pre -|[
            whiteSpace  -- pre
            width       -- inh
        ]
    ]
); "custom.css"

RunParameterTargetOrDefault "target" "custom.css"

CSS EDSL (https://github.com/Heather/FailessLib )

FailessLib features:

fieldset << [
    ★  [    
        margin -/ [em 1.0; px 0]
        padding -- em 1.0
        Border.set (px 1) Solid "#ccc"
        ]
    ☆ p @ margin -/ px4 2 12 10 10
    ⠂ "login" ++ label
        >< ⠂ "register" ++ label
        >< ⠂ "changePassword" ++ label
            @ Display.block
    ]
⠂ loginDisplay << [
    ★  [
        fontSize       -- em 1.1
        padding        -- px 10
        Display.block
        TextAlign.right
        Color.white
        ]
    ☆ a << [
        ⠅ link     @ Color.white
        ⠅ visited  @ Color.white
        ⠅ hover    @ Color.white
        ] ]
Border.set (px 1) Solid "#ccc" |> fun ➷ ->
    input << [
        ⠂ "textEntry "      -|[ ➷; width -- px 320 ]
        ⠂ "passwordEntry"   -|[ ➷; width -- px 320 ]
        ]

How does it work

It’s designed to use custom F# operators with right priority in mind and basically it replaces custom keywords to strings and merges all the stuff

let inline (~+.) st =
    match st with
    | [] -> ""
    | [ _ ] -> sprintf " {{ %s }}" st.Head
    | _ ->
        let pars =
            [for s in st ->
                sprintf "%s%s"
                <| tab
                <| s]
        sprintf " {{%s%s%s%s}}"
        <| System.Environment.NewLine
        <| String.Join(System.Environment.NewLine, pars)
        <| System.Environment.NewLine
        <| tab