aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Sier <pjsier@users.noreply.github.com>2019-08-13 03:40:17 -0500
committerJakub Hampl <kopomir@gmail.com>2019-08-13 09:40:17 +0100
commitc3496315f52ae90c9c86a2d72dd8690db67dbd04 (patch)
tree4dc046b7d0f4da9745dccd8cb898500eec598c4a
parent09249b8f3e88e70fc78a7d1f8b91e89c5962661b (diff)
Uses Bool instead of Expression for visibility (#51)
-rw-r--r--generate-elm.js6
-rw-r--r--src/Mapbox/Layer.elm6
-rw-r--r--style-generator/src/Decoder.elm3
-rw-r--r--style-generator/src/MyElm/Syntax.elm9
4 files changed, 17 insertions, 7 deletions
diff --git a/generate-elm.js b/generate-elm.js
index 181c4c1..ec1e889 100644
--- a/generate-elm.js
+++ b/generate-elm.js
@@ -258,9 +258,9 @@ filter =
Expression.encode >> Top "filter"
{-| Whether this layer is displayed. -}
-visible : Expression CameraExpression Bool -> LayerAttr any
-visible vis =
- Layout "visibility" <| Expression.encode <| Expression.ifElse vis (Expression.str "visible") (Expression.str "none")
+visible : Bool -> LayerAttr any
+visible isVisible =
+ Layout "visibility" <| Expression.encode <| Expression.str <| if isVisible then "visible" else "none"
${Object.entries(codes)
.map(([section, codes]) => `-- ${section}\n\n${codes.join("\n")}`)
diff --git a/src/Mapbox/Layer.elm b/src/Mapbox/Layer.elm
index dea484c..2c24fb5 100644
--- a/src/Mapbox/Layer.elm
+++ b/src/Mapbox/Layer.elm
@@ -319,9 +319,9 @@ filter =
{-| Whether this layer is displayed.
-}
-visible : Expression CameraExpression Bool -> LayerAttr any
-visible vis =
- Layout "visibility" <| Expression.encode <| Expression.ifElse vis (Expression.str "visible") (Expression.str "none")
+visible : Bool -> LayerAttr any
+visible isVisible =
+ Layout "visibility" <| Expression.encode <| Expression.str <| if isVisible then "visible" else "none"
diff --git a/style-generator/src/Decoder.elm b/style-generator/src/Decoder.elm
index 1df0a73..ce18306 100644
--- a/style-generator/src/Decoder.elm
+++ b/style-generator/src/Decoder.elm
@@ -194,6 +194,9 @@ decodeAttrs =
"filter" ->
decodeAttr "filter" (D.oneOf [ Decoder.Legacy.filter, Decode.expression ]) attrValue
+ "visibility" ->
+ decodeAttr "visible" (D.map ((==) "visible" >> bool) D.string) attrValue
+
other ->
decodeAttr (toCamelCaseLower attrName) Decode.expression attrValue
)
diff --git a/style-generator/src/MyElm/Syntax.elm b/style-generator/src/MyElm/Syntax.elm
index 7b99915..b207d17 100644
--- a/style-generator/src/MyElm/Syntax.elm
+++ b/style-generator/src/MyElm/Syntax.elm
@@ -1,6 +1,6 @@
module MyElm.Syntax exposing
( QualifiedName, local, valueName, typeName, constructorName
- , Expression, string, float, int, list, pair, triple, call0, call1, call2, call3, call4, calln, pipe, record
+ , Expression, string, float, int, bool, list, pair, triple, call0, call1, call2, call3, call4, calln, pipe, record
, Type, type0, type1, type2, typen, recordType, functionType, pairType, tripleType, typeVar
, Declaration, variable, fun1, customType, typeAlias
, build, Exposing, opaque, withConstructors, exposeFn
@@ -321,6 +321,13 @@ int i =
Literal (String.fromInt i)
+{-| A bool literal.
+-}
+bool : Bool -> Expression
+bool b =
+ Literal (if b then "True" else "False")
+
+
{-| A list literal
-}
list : List Expression -> Expression