Skip to content

Instantly share code, notes, and snippets.

@smurphy8
Created December 3, 2014 17:53
Show Gist options
  • Select an option

  • Save smurphy8/f6abd6d56a17a812a070 to your computer and use it in GitHub Desktop.

Select an option

Save smurphy8/f6abd6d56a17a812a070 to your computer and use it in GitHub Desktop.
data OnpingForm = OnpingForm {
row :: [Row]
}
data Row = Row {
_rowItem :: [Item]
_rowAttrib :: [RowAttributes]
}
data Item = Item {
_item :: [ItemType]
_itemAttrib :: [ItemAttributes]
}
data ItemType = ItemLabel Label
|ItemInput Input
|ItemEmptyBlock EmptyBlock
|ItemTableTopHeader TableTopHeader
|ItemTableLeftHeader ItemTableLeftHeader
data Label = Label {
_getLabelText :: Text
_itemAttrib :: [LabelAttributes]
}
data Button = Button {
_getButtonText :: Text
_buttonAttrib :: [ButtonAttributes]
}
-- | Render for the input needs to be dependent on the type of the input
data Input = Input {
_getInput :: [InputType]
_inputAttrib :: [InputAttribute]
}
data InputType = InputTypeText InputText
|InputTypeSignature Signature
newtype InputText = InputText { _getInputText::Text }
newtype Signature = Signature {
_signature :: FilePath
}
--------------------------------------------------------
data Attribute = Attribute {
name= Text
val = Text
}
class Attribute a where
toAttrPair a = a -> Attribute
data WidthAttr = WidthAttr {
_getWidth::Int
}
instance Attribute WidthAttr where
toAttribute (WidthAttr a) = Attribute
"width"
pack.show $ a
data ActionAttr = ActionAttr {
_getFunctionName :: Text
}
instance Attribute WidthAttr where
toAttribute (ActionAttr a) = Attribute
"action"
pack.show $ a
data ButtonAttributes = ButtonWidth WidthAttr
|ButtonAction ActionAttr
renderAttribute :: Attribute -> Text
renderAttribute attr = [here|
${name attr}=${val}
|]
renderAttrList :: (Attribute a) => [a] -> Text
renderAttrList attrs = concat $ renderAttribute . toAttribute <$> attrs
instance Attribute ButtonAttributes where
toAttribute (ButtonWidth b) = toAttribute b
toAttribute(ButtonAction a) = toAttrPair a
renderButton (Button txt attrs) = [here|
<button ${renderAttrList attrs} > ${txt} </button>
|]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment