mweiss/elm-rte-toolkit/1.0.2

NOTE: the latest version is 1.0.4

RichText.Model.Attribute

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

Attribute type

= StringAttribute String String
| IntegerAttribute String Int
| BoolAttribute String Bool
| FloatAttribute String 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 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 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 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 -> 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 -> 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 -> 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" ]