dzuk-mutant / hundred-rabbits-themes-elm / HRTheme

Decode theme files and use themes that conform to the Hundred Rabbits theme framework.


type alias HRTheme =
{ background : Color
, fHigh : Color
, fMed : Color
, fLow : Color
, fInv : Color
, bHigh : Color
, bMed : Color
, bLow : Color
, bInv : Color 
}

A color theme that uses the Hundred Rabbits theme spec.

Because there's no central Color type in elm, you may have to convert these colours to another type when you get them to be usable.

The Color types used in this record are from avh4/elm-color.

Because it would be impractical to do so, there is no constructor function for this type, you just manually create the record like so:

import Color exposing (rgb255) -- avh4/elm-color

myTheme : HRTheme
myTheme = { background = rgb255 224 177 203
        , fHigh = rgb255 35 25 66
        , fMed = rgb255 94 84 142
        , fLow = rgb255 190 149 196
        , fInv = rgb255 224 177 203
        , bHigh = rgb255 255 255 255
        , bMed = rgb255 94 84 142
        , bLow = rgb255 190 149 196
        , bInv = rgb255 159 134 192
        }

decoder : Xml.Decode.Decoder HRTheme

Decodes a Hundred Rabbits theme SVG file/string into a usable type in Elm.

import Xml.Decode as XD -- from ymtszw/elm-xml-decode
import HRTheme

hundredRabbitsTheme = XD.run HRTheme.decoder xmlString

Alongside the String-based errors the XML decoder might generate, this decoder will generate errors specific to Hundred Rabbits themes:

toXmlString : HRTheme -> String

Converts a Hundred Rabbits Theme to an XML string so that it can be downloaded to the user as a file.

import File.Download as Download
import HRTheme

save : Theme -> Cmd msg
save theme =
    Download.string "theme.svg" "image/svg+xml" (HRTheme.toXmlString theme)

toSvgImage : HRTheme -> Svg msg

Generates an Svg of the theme in the same way that 100r theme files look like.

HRTheme.toSvgImage theme