Add part5
This commit is contained in:
48
intro/part5/src/Asset.elm
Normal file
48
intro/part5/src/Asset.elm
Normal file
@@ -0,0 +1,48 @@
|
||||
module Asset exposing (Image, defaultAvatar, error, loading, src)
|
||||
|
||||
{-| Assets, such as images, videos, and audio. (We only have images for now.)
|
||||
|
||||
We should never expose asset URLs directly; this module should be in charge of
|
||||
all of them. One source of truth!
|
||||
|
||||
-}
|
||||
|
||||
import Html exposing (Attribute, Html)
|
||||
import Html.Attributes as Attr
|
||||
|
||||
|
||||
type Image
|
||||
= Image String
|
||||
|
||||
|
||||
|
||||
-- IMAGES
|
||||
|
||||
|
||||
error : Image
|
||||
error =
|
||||
image "error.jpg"
|
||||
|
||||
|
||||
loading : Image
|
||||
loading =
|
||||
image "loading.svg"
|
||||
|
||||
|
||||
defaultAvatar : Image
|
||||
defaultAvatar =
|
||||
Image "smiley-cyrus.jpg"
|
||||
|
||||
|
||||
image : String -> Image
|
||||
image filename =
|
||||
Image ("/assets/images/" ++ filename)
|
||||
|
||||
|
||||
|
||||
-- USING IMAGES
|
||||
|
||||
|
||||
src : Image -> Attribute msg
|
||||
src (Image url) =
|
||||
Attr.src url
|
||||
Reference in New Issue
Block a user