mweiss / elm-rte-toolkit / RichText.Model.Attribute

This module contains basic methods for accessing and defining element and mark attributes.

Attribute type


type Attribute
    = StringAttribute String String
    | IntegerAttribute String Basics.Int
    | BoolAttribute String Basics.Bool
    | FloatAttribute String Basics.Float

An attribute is a key value pair. It's used to store information on an element or mark. Information you can store are things like color, font type, or image or link locations.

StringAttribute "href" "www.google.com"

Helpers

findBoolAttribute : String -> List Attribute -> Maybe Basics.Bool

Find the first BoolAttribute that has the name provided and return Just that value. If no attribute exists, return Nothing.

findBoolAttribute "foo" [ BoolAttribute "foo" True, StringAttribute "foo2" "bar2" ]
--> Just True

findFloatAttribute : String -> List Attribute -> Maybe Basics.Float

Find the first FloatAttribute that has the name provided and return Just that value. If no attribute exists, return Nothing.

findFloatAttribute "foo" [ FloatAttribute "foo" 1.1, StringAttribute "foo2" "bar2" ]
--> Just 1.1

findIntegerAttribute : String -> List Attribute -> Maybe Basics.Int

Find the first IntegerAttribute that has the name provided and return Just that value. If no attribute exists, return Nothing.

findIntegerAttribute "foo" [ IntegerAttribute "foo" 1, StringAttribute "foo2" "bar2" ]
--> Just 1

findStringAttribute : String -> List Attribute -> Maybe String

Find the first StringAttribute that has the name provided and return Just that value. If no attribute exists, return Nothing.

findStringAttribute "foo2" [ FloatAttribute "foo" 1.1, StringAttribute "foo2" "bar2" ]
--> Just "bar2"

replaceOrAddBoolAttribute : String -> Basics.Bool -> List Attribute -> List Attribute

Replaces all BoolAttributes that have the name provided in the list, or add it to the beginning of the list if no pre existing BoolAttribute exists.

replaceOrAddBoolAttribute "foo" True [ BoolAttribute "foo" False, StringAttribute "foo2" "bar2" ]
--> [ BoolAttribute "foo" True, StringAttribute "foo2" "bar2" ]

replaceOrAddFloatAttribute : String -> Basics.Float -> List Attribute -> List Attribute

Replaces all FloatAttributes that have the name provided in the list, or add it to the beginning of the list if no pre existing FloatAttribute exists.

replaceOrAddFloatAttribute "foo" 2.2 [ FloatAttribute "foo" 1.1, StringAttribute "foo2" "bar2" ]
--> [ FloatAttribute "foo" 2.2, StringAttribute "foo2" "bar2" ]

replaceOrAddIntegerAttribute : String -> Basics.Int -> List Attribute -> List Attribute

Replaces all IntegerAttributes that have the name provided in the list, or add it to the beginning of the list if no pre existing IntegerAttribute exists.

replaceOrAddIntegerAttribute "foo" 2 [ IntegerAttribute "foo" 1, StringAttribute "foo2" "bar2" ]
--> [ IntegerAttribute "foo" 2, StringAttribute "foo2" "bar2" ]

replaceOrAddStringAttribute : String -> String -> List Attribute -> List Attribute

Replaces all StringAttributes that have the name provided in the list, or add it to the beginning of the list if no pre existing StringAttribute exists.

replaceOrAddStringAttribute "foo2" "bar3" [ BoolAttribute "foo" False, StringAttribute "foo2" "bar2" ]
--> [ BoolAttribute "foo" False, StringAttribute "foo2" "bar3" ]