{-# LANGUAGE TemplateHaskell #-}

module Text.Html.PigLet.Html5Defs where

import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as HA
import           Language.Haskell.TH
import           Data.Maybe (isJust)

getHtmlParent :: String -> ExpQ
getHtmlParent tag = maybe (error $ "Invalid parent tag " ++ tag)
                          id
                          (lookup tag html5Parent)

getHtmlLeaf :: String -> ExpQ
getHtmlLeaf tag = maybe (error $ "Invalid leaf tag " ++ tag)
                        id
                        (lookup tag html5Leaf)

getHtmlAttr :: String -> ExpQ
getHtmlAttr attr = maybe (error $ "Invalid attr " ++ attr)
                         id
                         (lookup attr html5Attr)

isParent :: String -> Bool
isParent = isJust . flip lookup html5Parent

isLeaf   :: String -> Bool
isLeaf   = isJust . flip lookup html5Leaf

html5Parent :: [(String, ExpQ)]
html5Parent = [ ("html"       , [| H.docTypeHtml |])
              , ("a"          , [| H.a |])
              , ("abbr"       , [| H.abbr |])
              , ("address"    , [| H.address |])
              , ("article"    , [| H.article |])
              , ("aside"      , [| H.aside |])
              , ("audio"      , [| H.audio |])
              , ("b"          , [| H.b |])
              , ("base"       , [| H.base |])
              , ("bdo"        , [| H.bdo |])
              , ("blockquote" , [| H.blockquote |])
              , ("body"       , [| H.body |])
              , ("button"     , [| H.button |])
              , ("canvas"     , [| H.canvas |])
              , ("caption"    , [| H.caption |])
              , ("cite"       , [| H.cite |])
              , ("code"       , [| H.code |])
              , ("colgroup"   , [| H.colgroup |])
              , ("command"    , [| H.command |])
              , ("datalist"   , [| H.datalist |])
              , ("dd"         , [| H.dd |])
              , ("del"        , [| H.del |])
              , ("details"    , [| H.details |])
              , ("dfn"        , [| H.dfn |])
              , ("div"        , [| H.div |])
              , ("dl"         , [| H.dl |])
              , ("dt"         , [| H.dt |])
              , ("em"         , [| H.em |])
              , ("fieldset"   , [| H.fieldset |])
              , ("figcaption" , [| H.figcaption |])
              , ("figure"     , [| H.figure |])
              , ("footer"     , [| H.footer |])
              , ("form"       , [| H.form |])
              , ("h1"         , [| H.h1 |])
              , ("h2"         , [| H.h2 |])
              , ("h3"         , [| H.h3 |])
              , ("h4"         , [| H.h4 |])
              , ("h5"         , [| H.h5 |])
              , ("h6"         , [| H.h6 |])
              , ("head"       , [| H.head |])
              , ("header"     , [| H.header |])
              , ("hgroup"     , [| H.hgroup |])
              , ("html"       , [| H.html |])
              , ("i"          , [| H.i |])
              , ("iframe"     , [| H.iframe |])
              , ("ins"        , [| H.ins |])
              , ("keygen"     , [| H.keygen |])
              , ("kbd"        , [| H.kbd |])
              , ("label"      , [| H.label |])
              , ("legend"     , [| H.legend |])
              , ("li"         , [| H.li |])
              , ("map"        , [| H.map |])
              , ("mark"       , [| H.mark |])
              , ("menu"       , [| H.menu |])
              , ("meter"      , [| H.meter |])
              , ("nav"        , [| H.nav |])
              , ("noscript"   , [| H.noscript |])
              , ("object"     , [| H.object |])
              , ("ol"         , [| H.ol |])
              , ("optgroup"   , [| H.optgroup |])
              , ("option"     , [| H.option |])
              , ("output"     , [| H.output |])
              , ("p"          , [| H.p |])
              , ("pre"        , [| H.pre |])
              , ("progress"   , [| H.progress |])
              , ("q"          , [| H.q |])
              , ("rp"         , [| H.rp |])
              , ("rt"         , [| H.rt |])
              , ("ruby"       , [| H.ruby |])
              , ("samp"       , [| H.samp |])
              , ("script"     , [| H.script |])
              , ("section"    , [| H.section |])
              , ("select"     , [| H.select |])
              , ("small"      , [| H.small |])
              , ("source"     , [| H.source |])
              , ("span"       , [| H.span |])
              , ("strong"     , [| H.strong |])
              , ("style"      , [| H.style |])
              , ("sub"        , [| H.sub |])
              , ("summary"    , [| H.summary |])
              , ("sup"        , [| H.sup |])
              , ("table"      , [| H.table |])
              , ("tbody"      , [| H.tbody |])
              , ("td"         , [| H.td |])
              , ("textarea"   , [| H.textarea |])
              , ("tfoot"      , [| H.tfoot |])
              , ("th"         , [| H.th |])
              , ("thead"      , [| H.thead |])
              , ("time"       , [| H.time |])
              , ("title"      , [| H.title |])
              , ("tr"         , [| H.tr |])
              , ("ul"         , [| H.ul |])
              , ("var"        , [| H.var |])
              , ("video"      , [| H.video |])
              ]

html5Leaf :: [(String , ExpQ)]
html5Leaf = [ ("area" , [| H.area |])
            , ("br"   , [| H.br  |])
            , ("col"  , [| H.col |])
            , ("embed", [| H.embed |])
            , ("hr"   , [| H.hr |])
            , ("img"  , [| H.img |])
            , ("input", [| H.input |])
            , ("meta" , [| H.meta |])
            , ("link" , [| H.link |])
            , ("param", [| H.param |]) ]

html5Attr :: [(String, ExpQ)]
html5Attr = [ ("accept"             , [| HA.accept |])
            , ("accept-charset"     , [| HA.acceptCharset |])
            , ("accesskey"          , [| HA.accesskey |])
            , ("action"             , [| HA.action |])
            , ("alt"                , [| HA.alt |])
            , ("async"              , [| HA.async |])
            , ("autocomplete"       , [| HA.autocomplete |])
            , ("autofocus"          , [| HA.autofocus |])
            , ("autoplay"           , [| HA.autoplay |])
            , ("challenge"          , [| HA.challenge |])
            , ("charset"            , [| HA.charset |])
            , ("checked"            , [| HA.checked |])
            , ("cite"               , [| HA.cite |])
            , ("class"              , [| HA.class_ |])
            , ("cols"               , [| HA.cols |])
            , ("colspan"            , [| HA.colspan |])
            , ("content"            , [| HA.content |])
            , ("contenteditable"    , [| HA.contenteditable |])
            , ("contextmenu"        , [| HA.contextmenu |])
            , ("controls"           , [| HA.controls |])
            , ("coords"             , [| HA.coords |])
            , ("data"               , [| HA.data_ |])
            , ("datetime"           , [| HA.datetime |])
            , ("defer"              , [| HA.defer |])
            , ("dir"                , [| HA.dir |])
            , ("disabled"           , [| HA.disabled |])
            , ("draggable"          , [| HA.draggable |])
            , ("enctype"            , [| HA.enctype |])
            , ("for"                , [| HA.for |])
            , ("form"               , [| HA.form |])
            , ("formaction"         , [| HA.formaction |])
            , ("formenctype"        , [| HA.formenctype |])
            , ("formmethod"         , [| HA.formmethod |])
            , ("formnovalidate"     , [| HA.formnovalidate |])
            , ("formtarget"         , [| HA.formtarget |])
            , ("headers"            , [| HA.headers |])
            , ("height"             , [| HA.height |])
            , ("hidden"             , [| HA.hidden |])
            , ("high"               , [| HA.high |])
            , ("href"               , [| HA.href |])
            , ("hreflang"           , [| HA.hreflang |])
            , ("http-equiv"         , [| HA.httpEquiv |])
            , ("icon"               , [| HA.icon |])
            , ("id"                 , [| HA.id |])
            , ("ismap"              , [| HA.ismap |])
            , ("item"               , [| HA.item |])
            , ("itemprop"           , [| HA.itemprop |])
            , ("keytype"            , [| HA.keytype |])
            , ("label"              , [| HA.label |])
            , ("lang"               , [| HA.lang |])
            , ("list"               , [| HA.list |])
            , ("loop"               , [| HA.loop |])
            , ("low"                , [| HA.low |])
            , ("manifest"           , [| HA.manifest |])
            , ("max"                , [| HA.max |])
            , ("maxlength"          , [| HA.maxlength |])
            , ("media"              , [| HA.media |])
            , ("method"             , [| HA.method |])
            , ("min"                , [| HA.min |])
            , ("multiple"           , [| HA.multiple |])
            , ("name"               , [| HA.name |])
            , ("novalidate"         , [| HA.novalidate |])
            , ("onbeforeonload"     , [| HA.onbeforeonload |])
            , ("onbeforeprint"      , [| HA.onbeforeprint |])
            , ("onblur"             , [| HA.onblur |])
            , ("oncanplay"          , [| HA.oncanplay |])
            , ("oncanplaythrough"   , [| HA.oncanplaythrough |])
            , ("onchange"           , [| HA.onchange |])
            , ("oncontextmenu"      , [| HA.oncontextmenu |])
            , ("onclick"            , [| HA.onclick |])
            , ("ondblclick"         , [| HA.ondblclick |])
            , ("ondrag"             , [| HA.ondrag |])
            , ("ondragend"          , [| HA.ondragend |])
            , ("ondragenter"        , [| HA.ondragenter |])
            , ("ondragleave"        , [| HA.ondragleave |])
            , ("ondragover"         , [| HA.ondragover |])
            , ("ondragstart"        , [| HA.ondragstart |])
            , ("ondrop"             , [| HA.ondrop |])
            , ("ondurationchange"   , [| HA.ondurationchange |])
            , ("onemptied"          , [| HA.onemptied |])
            , ("onended"            , [| HA.onended |])
            , ("onerror"            , [| HA.onerror |])
            , ("onfocus"            , [| HA.onfocus |])
            , ("onformchange"       , [| HA.onformchange |])
            , ("onforminput"        , [| HA.onforminput |])
            , ("onhaschange"        , [| HA.onhaschange |])
            , ("oninput"            , [| HA.oninput |])
            , ("oninvalid"          , [| HA.oninvalid |])
            , ("onkeydown"          , [| HA.onkeydown |])
            , ("onkeyup"            , [| HA.onkeyup |])
            , ("onload"             , [| HA.onload |])
            , ("onloadeddata"       , [| HA.onloadeddata |])
            , ("onloadedmetadata"   , [| HA.onloadedmetadata |])
            , ("onloadstart"        , [| HA.onloadstart |])
            , ("onmessage"          , [| HA.onmessage |])
            , ("onmousedown"        , [| HA.onmousedown |])
            , ("onmousemove"        , [| HA.onmousemove |])
            , ("onmouseout"         , [| HA.onmouseout |])
            , ("onmouseover"        , [| HA.onmouseover |])
            , ("onmouseup"          , [| HA.onmouseup |])
            , ("onmousewheel"       , [| HA.onmousewheel |])
            , ("ononline"           , [| HA.ononline |])
            , ("onpagehide"         , [| HA.onpagehide |])
            , ("onpageshow"         , [| HA.onpageshow |])
            , ("onpause"            , [| HA.onpause |])
            , ("onplay"             , [| HA.onplay |])
            , ("onplaying"          , [| HA.onplaying |])
            , ("onprogress"         , [| HA.onprogress |])
            , ("onpropstate"        , [| HA.onpropstate |])
            , ("onratechange"       , [| HA.onratechange |])
            , ("onreadystatechange" , [| HA.onreadystatechange |])
            , ("onredo"             , [| HA.onredo |])
            , ("onresize"           , [| HA.onresize |])
            , ("onscroll"           , [| HA.onscroll |])
            , ("onseeked"           , [| HA.onseeked |])
            , ("onseeking"          , [| HA.onseeking |])
            , ("onselect"           , [| HA.onselect |])
            , ("onstalled"          , [| HA.onstalled |])
            , ("onstorage"          , [| HA.onstorage |])
            , ("onsubmit"           , [| HA.onsubmit |])
            , ("onsuspend"          , [| HA.onsuspend |])
            , ("ontimeupdate"       , [| HA.ontimeupdate |])
            , ("onundo"             , [| HA.onundo |])
            , ("onunload"           , [| HA.onunload |])
            , ("onvolumechange"     , [| HA.onvolumechange |])
            , ("onwaiting"          , [| HA.onwaiting |])
            , ("open"               , [| HA.open |])
            , ("optimum"            , [| HA.optimum |])
            , ("pattern"            , [| HA.pattern |])
            , ("ping"               , [| HA.ping |])
            , ("placeholder"        , [| HA.placeholder |])
            , ("preload"            , [| HA.preload |])
            , ("pubdate"            , [| HA.pubdate |])
            , ("radiogroup"         , [| HA.radiogroup |])
            , ("readonly"           , [| HA.readonly |])
            , ("rel"                , [| HA.rel |])
            , ("required"           , [| HA.required |])
            , ("reversed"           , [| HA.reversed |])
            , ("rows"               , [| HA.rows |])
            , ("rowspan"            , [| HA.rowspan |])
            , ("sandbox"            , [| HA.sandbox |])
            , ("scope"              , [| HA.scope |])
            , ("scoped"             , [| HA.scoped |])
            , ("seamless"           , [| HA.seamless |])
            , ("selected"           , [| HA.selected |])
            , ("shape"              , [| HA.shape |])
            , ("size"               , [| HA.size |])
            , ("sizes"              , [| HA.sizes |])
            , ("span"               , [| HA.span |])
            , ("spellcheck"         , [| HA.spellcheck |])
            , ("src"                , [| HA.src |])
            , ("srcdoc"             , [| HA.srcdoc |])
            , ("start"              , [| HA.start |])
            , ("step"               , [| HA.step |])
            , ("style"              , [| HA.style |])
            , ("subject"            , [| HA.subject |])
            , ("summary"            , [| HA.summary |])
            , ("tabindex"           , [| HA.tabindex |])
            , ("target"             , [| HA.target |])
            , ("title"              , [| HA.title |])
            , ("type"               , [| HA.type_ |])
            , ("usemap"             , [| HA.usemap |])
            , ("value"              , [| HA.value |])
            , ("width"              , [| HA.width |])
            , ("wrap"               , [| HA.wrap |])
            , ("xmlns"              , [| HA.xmlns |])
            ]

html5Attr1 :: [(String, H.AttributeValue -> H.Attribute)]
html5Attr1 = [ ("accept"             ,  HA.accept )
             , ("accept-charset"     ,  HA.acceptCharset )
             , ("accesskey"          ,  HA.accesskey )
             , ("action"             ,  HA.action )
             , ("alt"                ,  HA.alt )
             , ("async"              ,  HA.async )
             , ("autocomplete"       ,  HA.autocomplete )
             , ("autofocus"          ,  HA.autofocus )
             , ("autoplay"           ,  HA.autoplay )
             , ("challenge"          ,  HA.challenge )
             , ("charset"            ,  HA.charset )
             , ("checked"            ,  HA.checked )
             , ("cite"               ,  HA.cite )
             , ("class"              ,  HA.class_ )
             , ("cols"               ,  HA.cols )
             , ("colspan"            ,  HA.colspan )
             , ("content"            ,  HA.content )
             , ("contenteditable"    ,  HA.contenteditable )
             , ("contextmenu"        ,  HA.contextmenu )
             , ("controls"           ,  HA.controls )
             , ("coords"             ,  HA.coords )
             , ("data"               ,  HA.data_ )
             , ("datetime"           ,  HA.datetime )
             , ("defer"              ,  HA.defer )
             , ("dir"                ,  HA.dir )
             , ("disabled"           ,  HA.disabled )
             , ("draggable"          ,  HA.draggable )
             , ("enctype"            ,  HA.enctype )
             , ("for"                ,  HA.for )
             , ("form"               ,  HA.form )
             , ("formaction"         ,  HA.formaction )
             , ("formenctype"        ,  HA.formenctype )
             , ("formmethod"         ,  HA.formmethod )
             , ("formnovalidate"     ,  HA.formnovalidate )
             , ("formtarget"         ,  HA.formtarget )
             , ("headers"            ,  HA.headers )
             , ("height"             ,  HA.height )
             , ("hidden"             ,  HA.hidden )
             , ("high"               ,  HA.high )
             , ("href"               ,  HA.href )
             , ("hreflang"           ,  HA.hreflang )
             , ("http-equiv"         ,  HA.httpEquiv )
             , ("icon"               ,  HA.icon )
             , ("id"                 ,  HA.id )
             , ("ismap"              ,  HA.ismap )
             , ("item"               ,  HA.item )
             , ("itemprop"           ,  HA.itemprop )
             , ("keytype"            ,  HA.keytype )
             , ("label"              ,  HA.label )
             , ("lang"               ,  HA.lang )
             , ("list"               ,  HA.list )
             , ("loop"               ,  HA.loop )
             , ("low"                ,  HA.low )
             , ("manifest"           ,  HA.manifest )
             , ("max"                ,  HA.max )
             , ("maxlength"          ,  HA.maxlength )
             , ("media"              ,  HA.media )
             , ("method"             ,  HA.method )
             , ("min"                ,  HA.min )
             , ("multiple"           ,  HA.multiple )
             , ("name"               ,  HA.name )
             , ("novalidate"         ,  HA.novalidate )
             , ("onbeforeonload"     ,  HA.onbeforeonload )
             , ("onbeforeprint"      ,  HA.onbeforeprint )
             , ("onblur"             ,  HA.onblur )
             , ("oncanplay"          ,  HA.oncanplay )
             , ("oncanplaythrough"   ,  HA.oncanplaythrough )
             , ("onchange"           ,  HA.onchange )
             , ("oncontextmenu"      ,  HA.oncontextmenu )
             , ("onclick"            ,  HA.onclick )
             , ("ondblclick"         ,  HA.ondblclick )
             , ("ondrag"             ,  HA.ondrag )
             , ("ondragend"          ,  HA.ondragend )
             , ("ondragenter"        ,  HA.ondragenter )
             , ("ondragleave"        ,  HA.ondragleave )
             , ("ondragover"         ,  HA.ondragover )
             , ("ondragstart"        ,  HA.ondragstart )
             , ("ondrop"             ,  HA.ondrop )
             , ("ondurationchange"   ,  HA.ondurationchange )
             , ("onemptied"          ,  HA.onemptied )
             , ("onended"            ,  HA.onended )
             , ("onerror"            ,  HA.onerror )
             , ("onfocus"            ,  HA.onfocus )
             , ("onformchange"       ,  HA.onformchange )
             , ("onforminput"        ,  HA.onforminput )
             , ("onhaschange"        ,  HA.onhaschange )
             , ("oninput"            ,  HA.oninput )
             , ("oninvalid"          ,  HA.oninvalid )
             , ("onkeydown"          ,  HA.onkeydown )
             , ("onkeyup"            ,  HA.onkeyup )
             , ("onload"             ,  HA.onload )
             , ("onloadeddata"       ,  HA.onloadeddata )
             , ("onloadedmetadata"   ,  HA.onloadedmetadata )
             , ("onloadstart"        ,  HA.onloadstart )
             , ("onmessage"          ,  HA.onmessage )
             , ("onmousedown"        ,  HA.onmousedown )
             , ("onmousemove"        ,  HA.onmousemove )
             , ("onmouseout"         ,  HA.onmouseout )
             , ("onmouseover"        ,  HA.onmouseover )
             , ("onmouseup"          ,  HA.onmouseup )
             , ("onmousewheel"       ,  HA.onmousewheel )
             , ("ononline"           ,  HA.ononline )
             , ("onpagehide"         ,  HA.onpagehide )
             , ("onpageshow"         ,  HA.onpageshow )
             , ("onpause"            ,  HA.onpause )
             , ("onplay"             ,  HA.onplay )
             , ("onplaying"          ,  HA.onplaying )
             , ("onprogress"         ,  HA.onprogress )
             , ("onpropstate"        ,  HA.onpropstate )
             , ("onratechange"       ,  HA.onratechange )
             , ("onreadystatechange" ,  HA.onreadystatechange )
             , ("onredo"             ,  HA.onredo )
             , ("onresize"           ,  HA.onresize )
             , ("onscroll"           ,  HA.onscroll )
             , ("onseeked"           ,  HA.onseeked )
             , ("onseeking"          ,  HA.onseeking )
             , ("onselect"           ,  HA.onselect )
             , ("onstalled"          ,  HA.onstalled )
             , ("onstorage"          ,  HA.onstorage )
             , ("onsubmit"           ,  HA.onsubmit )
             , ("onsuspend"          ,  HA.onsuspend )
             , ("ontimeupdate"       ,  HA.ontimeupdate )
             , ("onundo"             ,  HA.onundo )
             , ("onunload"           ,  HA.onunload )
             , ("onvolumechange"     ,  HA.onvolumechange )
             , ("onwaiting"          ,  HA.onwaiting )
             , ("open"               ,  HA.open )
             , ("optimum"            ,  HA.optimum )
             , ("pattern"            ,  HA.pattern )
             , ("ping"               ,  HA.ping )
             , ("placeholder"        ,  HA.placeholder )
             , ("preload"            ,  HA.preload )
             , ("pubdate"            ,  HA.pubdate )
             , ("radiogroup"         ,  HA.radiogroup )
             , ("readonly"           ,  HA.readonly )
             , ("rel"                ,  HA.rel )
             , ("required"           ,  HA.required )
             , ("reversed"           ,  HA.reversed )
             , ("rows"               ,  HA.rows )
             , ("rowspan"            ,  HA.rowspan )
             , ("sandbox"            ,  HA.sandbox )
             , ("scope"              ,  HA.scope )
             , ("scoped"             ,  HA.scoped )
             , ("seamless"           ,  HA.seamless )
             , ("selected"           ,  HA.selected )
             , ("shape"              ,  HA.shape )
             , ("size"               ,  HA.size )
             , ("sizes"              ,  HA.sizes )
             , ("span"               ,  HA.span )
             , ("spellcheck"         ,  HA.spellcheck )
             , ("src"                ,  HA.src )
             , ("srcdoc"             ,  HA.srcdoc )
             , ("start"              ,  HA.start )
             , ("step"               ,  HA.step )
             , ("style"              ,  HA.style )
             , ("subject"            ,  HA.subject )
             , ("summary"            ,  HA.summary )
             , ("tabindex"           ,  HA.tabindex )
             , ("target"             ,  HA.target )
             , ("title"              ,  HA.title )
             , ("type"               ,  HA.type_ )
             , ("usemap"             ,  HA.usemap )
             , ("value"              ,  HA.value )
             , ("width"              ,  HA.width )
             , ("wrap"               ,  HA.wrap )
             , ("xmlns"              ,  HA.xmlns )
             ]
