elm-pages 2.1.9 → 2.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- module ElmHtml.InternalTypes exposing
1
+ module Test.Html.Internal.ElmHtml.InternalTypes exposing
2
2
  ( ElmHtml(..), TextTagRecord, NodeRecord, CustomNodeRecord, MarkdownNodeRecord
3
3
  , Facts, Tagger, EventHandler, ElementKind(..)
4
4
  , Attribute(..), AttributeRecord, NamespacedAttributeRecord, PropertyRecord, EventRecord
@@ -18,12 +18,14 @@ module ElmHtml.InternalTypes exposing
18
18
  -}
19
19
 
20
20
  import Dict exposing (Dict)
21
- import ElmHtml.Constants exposing (..)
22
- import ElmHtml.Helpers exposing (..)
23
- import ElmHtml.Markdown exposing (..)
24
21
  import Html.Events
25
22
  import Json.Decode exposing (field)
26
23
  import Json.Encode
24
+ import Test.Html.Internal.ElmHtml.Constants as Constants exposing (..)
25
+ import Test.Html.Internal.ElmHtml.Helpers exposing (..)
26
+ import Test.Html.Internal.ElmHtml.Markdown exposing (..)
27
+ import Test.Internal.KernelConstants exposing (kernelConstants)
28
+ import VirtualDom
27
29
 
28
30
 
29
31
  {-| Type tree for representing Elm's Html
@@ -105,7 +107,7 @@ type alias EventHandler =
105
107
  -}
106
108
  type alias Facts msg =
107
109
  { styles : Dict String String
108
- , events : Dict String (Json.Decode.Decoder msg)
110
+ , events : Dict String (VirtualDom.Handler msg)
109
111
  , attributeNamespace : Maybe Json.Decode.Value
110
112
  , stringAttributes : Dict String String
111
113
  , boolAttributes : Dict String Bool
@@ -125,7 +127,7 @@ type ElementKind
125
127
 
126
128
 
127
129
  type HtmlContext msg
128
- = HtmlContext (List Tagger) (List Tagger -> EventHandler -> Json.Decode.Decoder msg)
130
+ = HtmlContext (List Tagger) (List Tagger -> EventHandler -> VirtualDom.Handler msg)
129
131
 
130
132
 
131
133
  {-| Type for representing Elm's Attributes
@@ -145,7 +147,7 @@ type Attribute
145
147
  = Attribute AttributeRecord
146
148
  | NamespacedAttribute NamespacedAttributeRecord
147
149
  | Property PropertyRecord
148
- | Styles (List ( String, String ))
150
+ | Style { key : String, value : String }
149
151
  | Event EventRecord
150
152
 
151
153
 
@@ -179,70 +181,55 @@ type alias PropertyRecord =
179
181
  type alias EventRecord =
180
182
  { key : String
181
183
  , decoder : Json.Decode.Value
182
- , options : { stopPropagation : Bool, preventDefault : Bool }
184
+ , options : EventOptions
183
185
  }
184
186
 
185
187
 
186
- factsKey : String
187
- factsKey =
188
- "d"
189
-
190
-
191
- descendantsCountKey : String
192
- descendantsCountKey =
193
- "b"
194
-
195
-
196
- tagKey : String
197
- tagKey =
198
- "c"
199
-
200
-
201
- childrenKey : String
202
- childrenKey =
203
- "e"
188
+ type alias EventOptions =
189
+ { stopPropagation : Bool
190
+ , preventDefault : Bool
191
+ }
204
192
 
205
193
 
206
194
  {-| decode a json object into ElmHtml, you have to pass a function that decodes
207
195
  events from Html Nodes. If you don't want to decode event msgs, you can ignore it:
208
196
 
209
- decodeElmHtml (\_ \_ -> ()) jsonHtml
197
+ decodeElmHtml (\_ _ -> VirtualDom.Normal (Json.Decode.succeed ())) jsonHtml
210
198
 
211
199
  if you do want to decode them, you will probably need to write some native code
212
200
  like elm-html-test does to extract the function inside those.
213
201
 
214
202
  -}
215
- decodeElmHtml : (List Tagger -> EventHandler -> Json.Decode.Decoder msg) -> Json.Decode.Decoder (ElmHtml msg)
203
+ decodeElmHtml : (List Tagger -> EventHandler -> VirtualDom.Handler msg) -> Json.Decode.Decoder (ElmHtml msg)
216
204
  decodeElmHtml eventDecoder =
217
205
  contextDecodeElmHtml (HtmlContext [] eventDecoder)
218
206
 
219
207
 
220
208
  contextDecodeElmHtml : HtmlContext msg -> Json.Decode.Decoder (ElmHtml msg)
221
209
  contextDecodeElmHtml context =
222
- field "$" Json.Decode.int
210
+ field kernelConstants.virtualDom.nodeType Json.Decode.int
223
211
  |> Json.Decode.andThen
224
- (\typeInt ->
225
- case typeInt of
226
- 0 ->
227
- Json.Decode.map TextTag decodeTextTag
212
+ (\nodeType ->
213
+ if nodeType == kernelConstants.virtualDom.nodeTypeText then
214
+ Json.Decode.map TextTag decodeTextTag
228
215
 
229
- 2 ->
230
- Json.Decode.map NodeEntry (decodeKeyedNode context)
216
+ else if nodeType == kernelConstants.virtualDom.nodeTypeKeyedNode then
217
+ Json.Decode.map NodeEntry (decodeKeyedNode context)
231
218
 
232
- 1 ->
233
- Json.Decode.map NodeEntry (decodeNode context)
219
+ else if nodeType == kernelConstants.virtualDom.nodeTypeNode then
220
+ Json.Decode.map NodeEntry (decodeNode context)
234
221
 
235
- 3 ->
236
- decodeCustomNode context
222
+ else if nodeType == kernelConstants.virtualDom.nodeTypeCustom then
223
+ decodeCustomNode context
237
224
 
238
- 4 ->
239
- decodeTagger context
225
+ else if nodeType == kernelConstants.virtualDom.nodeTypeTagger then
226
+ decodeTagger context
240
227
 
241
- 5 ->
242
- field "node" (contextDecodeElmHtml context)
228
+ else if nodeType == kernelConstants.virtualDom.nodeTypeThunk then
229
+ field kernelConstants.virtualDom.node (contextDecodeElmHtml context)
243
230
 
244
- _ ->
245
- Json.Decode.fail ("No such type as " ++ String.fromInt typeInt)
231
+ else
232
+ Json.Decode.fail ("No such type as " ++ String.fromInt nodeType)
246
233
  )
247
234
 
248
235
 
@@ -250,31 +237,21 @@ contextDecodeElmHtml context =
250
237
  -}
251
238
  decodeTextTag : Json.Decode.Decoder TextTagRecord
252
239
  decodeTextTag =
253
- field "a" (Json.Decode.andThen (\text -> Json.Decode.succeed { text = text }) Json.Decode.string)
254
-
255
-
256
- {-| encode text tag
257
- -}
258
- encodeTextTag : TextTagRecord -> Json.Encode.Value
259
- encodeTextTag { text } =
260
- Json.Encode.object [ ( "a", Json.Encode.string text ) ]
240
+ field kernelConstants.virtualDom.text (Json.Decode.andThen (\text -> Json.Decode.succeed { text = text }) Json.Decode.string)
261
241
 
262
242
 
263
243
  {-| decode a tagger
264
244
  -}
265
245
  decodeTagger : HtmlContext msg -> Json.Decode.Decoder (ElmHtml msg)
266
246
  decodeTagger (HtmlContext taggers eventDecoder) =
267
- Json.Decode.field "j" Json.Decode.value
247
+ Json.Decode.field kernelConstants.virtualDom.tagger Json.Decode.value
268
248
  |> Json.Decode.andThen
269
249
  (\tagger ->
270
250
  let
271
251
  nodeDecoder =
272
252
  contextDecodeElmHtml (HtmlContext (taggers ++ [ tagger ]) eventDecoder)
273
253
  in
274
- -- The child node is at the k field of tagger
275
- -- TODO determine if the descendantsCount should be updated for this node,
276
- -- because the tagger object counds as one node. this.b = 1 + (this.k.b || 0)
277
- Json.Decode.at [ "k" ] nodeDecoder
254
+ Json.Decode.at [ kernelConstants.virtualDom.node ] nodeDecoder
278
255
  )
279
256
 
280
257
 
@@ -287,10 +264,10 @@ decodeKeyedNode context =
287
264
  Json.Decode.field "b" (contextDecodeElmHtml context)
288
265
  in
289
266
  Json.Decode.map4 NodeRecord
290
- (Json.Decode.field tagKey Json.Decode.string)
291
- (Json.Decode.field childrenKey (Json.Decode.list decodeSecondNode))
292
- (Json.Decode.field factsKey (decodeFacts context))
293
- (Json.Decode.field descendantsCountKey Json.Decode.int)
267
+ (Json.Decode.field kernelConstants.virtualDom.tag Json.Decode.string)
268
+ (Json.Decode.field kernelConstants.virtualDom.kids (Json.Decode.list decodeSecondNode))
269
+ (Json.Decode.field kernelConstants.virtualDom.facts (decodeFacts context))
270
+ (Json.Decode.field kernelConstants.virtualDom.descendantsCount Json.Decode.int)
294
271
 
295
272
 
296
273
  {-| decode a node record
@@ -298,23 +275,10 @@ decodeKeyedNode context =
298
275
  decodeNode : HtmlContext msg -> Json.Decode.Decoder (NodeRecord msg)
299
276
  decodeNode context =
300
277
  Json.Decode.map4 NodeRecord
301
- (field tagKey Json.Decode.string)
302
- (field childrenKey (Json.Decode.list (contextDecodeElmHtml context)))
303
- (field factsKey (decodeFacts context))
304
- (field descendantsCountKey Json.Decode.int)
305
-
306
-
307
- {-| encode a node record: currently does not support facts or children
308
- -}
309
- encodeNodeRecord : NodeRecord msg -> Json.Encode.Value
310
- encodeNodeRecord record =
311
- Json.Encode.object
312
- [ ( tagKey, Json.Encode.string record.tag )
313
-
314
- --, ( childrenKey, Json.Encode.list encodeElmHtml)
315
- --, ( factsKey, encodeFacts)
316
- , ( descendantsCountKey, Json.Encode.int record.descendantsCount )
317
- ]
278
+ (field kernelConstants.virtualDom.tag Json.Decode.string)
279
+ (field kernelConstants.virtualDom.kids (Json.Decode.list (contextDecodeElmHtml context)))
280
+ (field kernelConstants.virtualDom.facts (decodeFacts context))
281
+ (field kernelConstants.virtualDom.descendantsCount Json.Decode.int)
318
282
 
319
283
 
320
284
  {-| decode custom node into either markdown or custom
@@ -332,8 +296,8 @@ decodeCustomNode context =
332
296
  decodeCustomNodeRecord : HtmlContext msg -> Json.Decode.Decoder (CustomNodeRecord msg)
333
297
  decodeCustomNodeRecord context =
334
298
  Json.Decode.map2 CustomNodeRecord
335
- (field factsKey (decodeFacts context))
336
- (field "g" Json.Decode.value)
299
+ (field kernelConstants.virtualDom.facts (decodeFacts context))
300
+ (field kernelConstants.virtualDom.model Json.Decode.value)
337
301
 
338
302
 
339
303
  {-| decode markdown node record
@@ -341,8 +305,8 @@ decodeCustomNodeRecord context =
341
305
  decodeMarkdownNodeRecord : HtmlContext msg -> Json.Decode.Decoder (MarkdownNodeRecord msg)
342
306
  decodeMarkdownNodeRecord context =
343
307
  Json.Decode.map2 MarkdownNodeRecord
344
- (field factsKey (decodeFacts context))
345
- (field "g" decodeMarkdownModel)
308
+ (field kernelConstants.virtualDom.facts (decodeFacts context))
309
+ (field kernelConstants.virtualDom.model decodeMarkdownModel)
346
310
 
347
311
 
348
312
  {-| decode the styles
@@ -355,19 +319,6 @@ decodeStyles =
355
319
  ]
356
320
 
357
321
 
358
- {-| encode styles
359
- -}
360
- encodeStyles : Dict String String -> Json.Encode.Value
361
- encodeStyles stylesDict =
362
- let
363
- encodedDict =
364
- stylesDict
365
- |> Dict.toList
366
- |> List.map (\( k, v ) -> ( k, Json.Encode.string v ))
367
- in
368
- Json.Encode.object [ ( styleKey, Json.Encode.object encodedDict ) ]
369
-
370
-
371
322
  {-| grab things from attributes via a decoder, then anything that isn't filtered on
372
323
  the object
373
324
  -}
@@ -409,7 +360,7 @@ decodeAttributes decoder =
409
360
  ]
410
361
 
411
362
 
412
- decodeEvents : (EventHandler -> Json.Decode.Decoder msg) -> Json.Decode.Decoder (Dict String (Json.Decode.Decoder msg))
363
+ decodeEvents : (EventHandler -> VirtualDom.Handler msg) -> Json.Decode.Decoder (Dict String (VirtualDom.Handler msg))
413
364
  decodeEvents taggedEventDecoder =
414
365
  Json.Decode.oneOf
415
366
  [ Json.Decode.field eventKey (Json.Decode.dict (Json.Decode.map taggedEventDecoder Json.Decode.value))
@@ -453,50 +404,36 @@ like elm-html-test does to extract the function inside those.
453
404
  -}
454
405
  decodeAttribute : Json.Decode.Decoder Attribute
455
406
  decodeAttribute =
456
- Json.Decode.field "key" Json.Decode.string
407
+ Json.Decode.field "$" Json.Decode.string
457
408
  |> Json.Decode.andThen
458
- (\key ->
459
- if key == attributeKey then
460
- Json.Decode.map2 AttributeRecord
461
- (Json.Decode.field "realKey" Json.Decode.string)
462
- (Json.Decode.field "value" Json.Decode.string)
463
- |> Json.Decode.map Attribute
464
-
465
- else if key == attributeNamespaceKey then
409
+ (\tag ->
410
+ if tag == Constants.attributeKey then
411
+ Json.Decode.map2 (\key val -> Attribute (AttributeRecord key val))
412
+ (Json.Decode.field "n" Json.Decode.string)
413
+ (Json.Decode.field "o" Json.Decode.string)
414
+
415
+ else if tag == Constants.attributeNamespaceKey then
466
416
  Json.Decode.map3 NamespacedAttributeRecord
467
- (Json.Decode.field "realKey" Json.Decode.string)
468
- (Json.Decode.at [ "value", "value" ] Json.Decode.string)
469
- (Json.Decode.at [ "value", "namespace" ] Json.Decode.string)
417
+ (Json.Decode.field "n" Json.Decode.string)
418
+ (Json.Decode.at [ "o", "o" ] Json.Decode.string)
419
+ (Json.Decode.at [ "o", "f" ] Json.Decode.string)
470
420
  |> Json.Decode.map NamespacedAttribute
471
421
 
472
- else if key == styleKey then
473
- Json.Decode.map2 (\a b -> ( a, b ))
474
- (Json.Decode.field "_0" Json.Decode.string)
475
- (Json.Decode.field "_1" Json.Decode.string)
476
- |> elmListDecoder
477
- |> Json.Decode.field "value"
478
- |> Json.Decode.map Styles
479
-
480
- else if key == eventKey then
481
- Json.Decode.map3 EventRecord
482
- (Json.Decode.field "realKey" Json.Decode.string)
483
- (Json.Decode.at [ "value", "decoder" ] Json.Decode.value)
484
- (Json.Decode.at [ "value", "options" ] decodeOptions)
485
- |> Json.Decode.map Event
422
+ else if tag == Constants.styleKey then
423
+ Json.Decode.map2 (\key val -> Style { key = key, value = val })
424
+ (Json.Decode.field "n" Json.Decode.string)
425
+ (Json.Decode.field "o" Json.Decode.string)
426
+
427
+ else if tag == Constants.propKey then
428
+ Json.Decode.map2 (\key val -> Property (PropertyRecord key val))
429
+ (Json.Decode.field "n" Json.Decode.string)
430
+ (Json.Decode.at [ "o", "a" ] Json.Decode.value)
486
431
 
487
432
  else
488
- Json.Decode.field "value" Json.Decode.value
489
- |> Json.Decode.map (PropertyRecord key >> Property)
433
+ Json.Decode.fail ("Unexpected Html.Attribute tag: " ++ tag)
490
434
  )
491
435
 
492
436
 
493
- decodeOptions : Json.Decode.Decoder { stopPropagation : Bool, preventDefault : Bool }
494
- decodeOptions =
495
- Json.Decode.map2 (\stopPropagation preventDefault -> { stopPropagation = stopPropagation, preventDefault = preventDefault })
496
- (Json.Decode.field "stopPropagation" Json.Decode.bool)
497
- (Json.Decode.field "preventDefault" Json.Decode.bool)
498
-
499
-
500
437
  elmListDecoder : Json.Decode.Decoder a -> Json.Decode.Decoder (List a)
501
438
  elmListDecoder itemDecoder =
502
439
  elmListDecoderHelp itemDecoder []
@@ -1,18 +1,19 @@
1
- module ElmHtml.Markdown exposing
1
+ module Test.Html.Internal.ElmHtml.Markdown exposing
2
2
  ( MarkdownOptions, MarkdownModel, baseMarkdownModel
3
- , encodeOptions, encodeMarkdownModel, decodeMarkdownModel
3
+ , decodeMarkdownModel
4
4
  )
5
5
 
6
6
  {-| Markdown helpers
7
7
 
8
8
  @docs MarkdownOptions, MarkdownModel, baseMarkdownModel
9
9
 
10
- @docs encodeOptions, encodeMarkdownModel, decodeMarkdownModel
10
+ @docs decodeMarkdownModel
11
11
 
12
12
  -}
13
13
 
14
14
  import Json.Decode exposing (field)
15
15
  import Json.Encode
16
+ import Test.Internal.KernelConstants exposing (kernelConstants)
16
17
 
17
18
 
18
19
  {-| Just a default markdown model
@@ -47,27 +48,9 @@ type alias MarkdownModel =
47
48
  }
48
49
 
49
50
 
50
- {-| We don't really care about encoding options right now
51
- TODO: we will if we want to represent things as we do for elm-html
52
- -}
53
- encodeOptions : MarkdownOptions -> Json.Decode.Value
54
- encodeOptions options =
55
- Json.Encode.null
56
-
57
-
58
- {-| encode markdown model
59
- -}
60
- encodeMarkdownModel : MarkdownModel -> Json.Decode.Value
61
- encodeMarkdownModel model =
62
- Json.Encode.object
63
- [ ( "options", encodeOptions model.options )
64
- , ( "markdown", Json.Encode.string model.markdown )
65
- ]
66
-
67
-
68
51
  {-| decode a markdown model
69
52
  -}
70
53
  decodeMarkdownModel : Json.Decode.Decoder MarkdownModel
71
54
  decodeMarkdownModel =
72
- field "markdown" Json.Decode.string
55
+ field kernelConstants.markdown.markdown Json.Decode.string
73
56
  |> Json.Decode.map (MarkdownModel baseMarkdownModel.options)
@@ -1,4 +1,4 @@
1
- module ElmHtml.ToString exposing
1
+ module Test.Html.Internal.ElmHtml.ToString exposing
2
2
  ( nodeRecordToString, nodeToString, nodeToStringWithOptions
3
3
  , FormatOptions, defaultFormatOptions
4
4
  )
@@ -12,8 +12,8 @@ module ElmHtml.ToString exposing
12
12
  -}
13
13
 
14
14
  import Dict exposing (Dict)
15
- import ElmHtml.InternalTypes exposing (..)
16
15
  import String
16
+ import Test.Html.Internal.ElmHtml.InternalTypes exposing (..)
17
17
 
18
18
 
19
19
  {-| Formatting options to be used for converting to string
@@ -111,8 +111,8 @@ nodeRecordToString options { tag, children, facts } =
111
111
  [] ->
112
112
  Nothing
113
113
 
114
- stylesList ->
115
- stylesList
114
+ styleValues ->
115
+ styleValues
116
116
  |> List.map (\( key, value ) -> key ++ ":" ++ value ++ ";")
117
117
  |> String.join ""
118
118
  |> (\styleString -> "style=\"" ++ styleString ++ "\"")
@@ -130,19 +130,17 @@ nodeRecordToString options { tag, children, facts } =
130
130
  |> String.join " "
131
131
  |> Just
132
132
 
133
+ boolToString b =
134
+ case b of
135
+ True ->
136
+ "True"
137
+
138
+ False ->
139
+ "False"
140
+
133
141
  boolAttributes =
134
142
  Dict.toList facts.boolAttributes
135
- |> List.map
136
- (\( k, v ) ->
137
- k
138
- ++ "="
139
- ++ (if v then
140
- "true"
141
-
142
- else
143
- "false"
144
- )
145
- )
143
+ |> List.map (\( k, v ) -> k ++ "=" ++ (String.toLower <| boolToString v))
146
144
  |> String.join " "
147
145
  |> Just
148
146
  in
@@ -0,0 +1,34 @@
1
+ module Test.Internal.KernelConstants exposing (kernelConstants)
2
+
3
+ {-| This module defines the mapping of optimized field name and enum values
4
+ for kernel code in other packages the we depend on.
5
+ -}
6
+
7
+
8
+ {-| NOTE: this is duplicating constants also defined in src/Elm/Kernel/HtmlAsJson.js
9
+ so if you make any changes here, be sure to synchronize them there!
10
+ -}
11
+ kernelConstants =
12
+ { virtualDom =
13
+ { nodeType = "$"
14
+ , nodeTypeText = 0
15
+ , nodeTypeKeyedNode = 2
16
+ , nodeTypeNode = 1
17
+ , nodeTypeCustom = 3
18
+ , nodeTypeTagger = 4
19
+ , nodeTypeThunk = 5
20
+ , tag = "c"
21
+ , kids = "e"
22
+ , facts = "d"
23
+ , descendantsCount = "b"
24
+ , text = "a"
25
+ , refs = "l"
26
+ , node = "k"
27
+ , tagger = "j"
28
+ , model = "g"
29
+ }
30
+ , markdown =
31
+ { options = "a"
32
+ , markdown = "b"
33
+ }
34
+ }
@@ -1,151 +0,0 @@
1
- module ElmHtml.ToElmString exposing
2
- ( nodeRecordToString, toElmString, toElmStringWithOptions
3
- , FormatOptions, defaultFormatOptions
4
- )
5
-
6
- {-| Convert ElmHtml to string of Elm code.
7
-
8
- @docs nodeRecordToString, toElmString, toElmStringWithOptions
9
-
10
- @docs FormatOptions, defaultFormatOptions
11
-
12
- -}
13
-
14
- import Dict exposing (Dict)
15
- import ElmHtml.InternalTypes exposing (..)
16
- import String
17
-
18
-
19
- {-| Formatting options to be used for converting to string
20
- -}
21
- type alias FormatOptions =
22
- { indent : Int
23
- , newLines : Bool
24
- }
25
-
26
-
27
- {-| default formatting options
28
- -}
29
- defaultFormatOptions : FormatOptions
30
- defaultFormatOptions =
31
- { indent = 0
32
- , newLines = False
33
- }
34
-
35
-
36
- nodeToLines : FormatOptions -> ElmHtml msg -> List String
37
- nodeToLines options nodeType =
38
- case nodeType of
39
- TextTag { text } ->
40
- [ "Html.text \"" ++ text ++ "\"" ]
41
-
42
- NodeEntry record ->
43
- nodeRecordToString options record
44
-
45
- CustomNode record ->
46
- []
47
-
48
- MarkdownNode record ->
49
- [ record.model.markdown ]
50
-
51
- NoOp ->
52
- []
53
-
54
-
55
- {-| Convert a given html node to a string based on the type
56
- -}
57
- toElmString : ElmHtml msg -> String
58
- toElmString =
59
- toElmStringWithOptions defaultFormatOptions
60
-
61
-
62
- {-| same as toElmString, but with options
63
- -}
64
- toElmStringWithOptions : FormatOptions -> ElmHtml msg -> String
65
- toElmStringWithOptions options =
66
- nodeToLines options
67
- >> String.join
68
- (if options.newLines then
69
- "\n"
70
-
71
- else
72
- ""
73
- )
74
-
75
-
76
- {-| Convert a node record to a string. This basically takes the tag name, then
77
- pulls all the facts into tag declaration, then goes through the children and
78
- nests them under this one
79
- -}
80
- nodeRecordToString : FormatOptions -> NodeRecord msg -> List String
81
- nodeRecordToString options { tag, children, facts } =
82
- let
83
- openTag : List (Maybe String) -> String
84
- openTag extras =
85
- let
86
- trimmedExtras =
87
- List.filterMap (\x -> x) extras
88
- |> List.map String.trim
89
- |> List.filter ((/=) "")
90
-
91
- filling =
92
- case trimmedExtras of
93
- [] ->
94
- ""
95
-
96
- more ->
97
- " " ++ String.join " " more
98
- in
99
- "Html." ++ tag ++ " [" ++ filling
100
-
101
- childrenStrings =
102
- List.map (nodeToLines options) children
103
- |> List.concat
104
- |> List.map ((++) (String.repeat options.indent " "))
105
-
106
- styles =
107
- case Dict.toList facts.styles of
108
- [] ->
109
- Nothing
110
-
111
- stylesList ->
112
- stylesList
113
- |> List.map (\( key, value ) -> "(\"" ++ key ++ "\",\"" ++ value ++ "\")")
114
- |> String.join ", "
115
- |> (\styleString -> "Html.Attributes.style [" ++ styleString ++ "]")
116
- |> Just
117
-
118
- classes =
119
- Dict.get "className" facts.stringAttributes
120
- |> Maybe.map (\name -> "Html.Attributes.class [\"" ++ name ++ "\"]")
121
-
122
- stringAttributes =
123
- Dict.filter (\k v -> k /= "className") facts.stringAttributes
124
- |> Dict.toList
125
- |> List.map (\( k, v ) -> "Html.Attributes." ++ k ++ " \"" ++ v ++ "\"")
126
- |> String.join ", "
127
- |> Just
128
-
129
- boolAttributes =
130
- Dict.toList facts.boolAttributes
131
- |> List.map
132
- (\( k, v ) ->
133
- "Html.Attributes.property \""
134
- ++ k
135
- ++ "\" <| Json.Encode.bool "
136
- ++ (if v then
137
- "True"
138
-
139
- else
140
- "False"
141
- )
142
- )
143
- |> String.join " "
144
- |> Just
145
- in
146
- [ openTag [ classes, styles, stringAttributes, boolAttributes ] ]
147
- ++ [ " ] "
148
- , "[ "
149
- , String.join "" childrenStrings
150
- , "]"
151
- ]