Skip to content

Commit

Permalink
Simplify pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed May 15, 2024
1 parent 3c7bf04 commit f4564de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"direct": {
"Garados007/elm-svg-parser": "1.0.0",
"elm-community/maybe-extra": "5.3.0",
"elm/core": "1.0.4",
"elm/json": "1.1.3",
"elm/regex": "1.0.0",
Expand All @@ -27,4 +28,4 @@
"direct": {},
"indirect": {}
}
}
}
29 changes: 9 additions & 20 deletions src/Svg2Elm/Generator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Svg2Elm.Generator exposing (compileFunction)
import Regex
import String.Case exposing (toCamelCaseLower)
import SvgParser exposing (SvgAttribute, SvgNode(..), parseToNode)
import Maybe.Extra as Maybe


quote : String -> String
Expand Down Expand Up @@ -49,26 +50,14 @@ compileChildren mbKey children =

compileNode : Maybe String -> Bool -> SvgNode -> String
compileNode mbKey attrs node =
case ( node, mbKey ) of
( SvgElement { name, attributes, children }, Just key ) ->
case node of
SvgElement { name, attributes, children } ->
String.concat
[ "Svg.Keyed.node "
, quote name
, " (["
, compileAttributes attributes
, if attrs then
"] ++ attrs) "
[ if Maybe.isJust mbKey then
"Svg.Keyed.node "

else
"]) "
, "["
, compileChildren (Just key) children
, "]"
]

( SvgElement { name, attributes, children }, Nothing ) ->
String.concat
[ "Svg.node "
"Svg.node "
, quote name
, " (["
, compileAttributes attributes
Expand All @@ -78,14 +67,14 @@ compileNode mbKey attrs node =
else
"]) "
, "["
, compileChildren Nothing children
, compileChildren mbKey children
, "]"
]

( SvgText text, _ ) ->
SvgText text ->
"Svg.text(" ++ quote text ++ ")"

( SvgComment comment, _ ) ->
SvgComment comment ->
"{-" ++ comment ++ "-}"


Expand Down

0 comments on commit f4564de

Please sign in to comment.