Skip to content

Commit

Permalink
🤖 elm-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Feldman committed Dec 7, 2016
1 parent bf51494 commit 32bdb0e
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 141 deletions.
8 changes: 4 additions & 4 deletions elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"source-directories": [
"src"
],
"native-modules": true,
"exposed-modules": [],
"native-modules": true,
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0"
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}
3 changes: 2 additions & 1 deletion src/HtmlQuery.elm
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ queryInNode selector node =
[ node ]
else
[]

_ ->
[]

_ ->
[]



predicateFromSelector : Selector -> (NodeRecord -> Bool)
predicateFromSelector selector =
case selector of
Expand Down
34 changes: 22 additions & 12 deletions src/HtmlToString.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module HtmlToString exposing (..) -- where
module HtmlToString exposing (..)

import Html exposing (Html)
-- where

import Html exposing (Html)
import String
import Dict exposing (Dict)
import Json.Decode

import ServerSide.Constants exposing (..)
import ServerSide.Helpers exposing (..)
import ServerSide.InternalTypes exposing (..)
Expand All @@ -31,12 +31,13 @@ nodeTypeFromHtml =
>> Json.Decode.decodeString decodeNodeType
>> Result.withDefault NoOp


{-| Convert a node record to a string. This basically takes the tag name, then
pulls all the facts into tag declaration, then goes through the children and
nests them undert hsi one
-}
nodeRecordToString : NodeRecord -> String
nodeRecordToString {tag, children, facts} =
nodeRecordToString { tag, children, facts } =
let
openTag : List (Maybe String) -> String
openTag extras =
Expand All @@ -48,7 +49,9 @@ nodeRecordToString {tag, children, facts} =

filling =
case trimmedExtras of
[] -> ""
[] ->
""

more ->
" " ++ (String.join " " more)
in
Expand All @@ -63,10 +66,12 @@ nodeRecordToString {tag, children, facts} =

styles =
case Dict.toList facts.styles of
[] -> Nothing
[] ->
Nothing

styles ->
styles
|> List.map (\(key, value) -> key ++ ":" ++ value)
|> List.map (\( key, value ) -> key ++ ":" ++ value)
|> String.join ""
|> (\styleString -> "style=\"" ++ styleString ++ "\"")
|> Just
Expand All @@ -78,42 +83,47 @@ nodeRecordToString {tag, children, facts} =
stringOthers =
Dict.filter (\k v -> k /= "className") facts.stringOthers
|> Dict.toList
|> List.map (\(k, v) -> k ++ "=\"" ++ v ++ "\"")
|> List.map (\( k, v ) -> k ++ "=\"" ++ v ++ "\"")
|> String.join " "
|> Just

boolOthers =
Dict.toList facts.boolOthers
|> List.map (\(k, v) -> k ++ "=" ++ (String.toLower <| toString v))
|> List.map (\( k, v ) -> k ++ "=" ++ (String.toLower <| toString v))
|> String.join " "
|> Just

in
String.join ""
[ openTag [ classes, styles, stringOthers, boolOthers ]
, childrenStrings
, closeTag
]


{-| Convert a given html node to a string based on the type
-}
nodeTypeToString : NodeType -> String
nodeTypeToString nodeType =
case nodeType of
TextTag {text} ->
TextTag { text } ->
text

NodeEntry record ->
nodeRecordToString record

CustomNode record ->
""

MarkdownNode record ->
record.model.markdown

NoOp ->
""


{-| Take a Html element, convert it to a string
Useful for tests
-}
htmlToString : Html msg -> String
htmlToString =
htmlToString =
nodeTypeFromHtml >> nodeTypeToString
24 changes: 18 additions & 6 deletions src/ServerSide/Constants.elm
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
module ServerSide.Constants exposing (..) --where
module ServerSide.Constants exposing (..)

--where


styleKey : String
styleKey = "STYLE"
styleKey =
"STYLE"


eventKey : String
eventKey = "EVENT"
eventKey =
"EVENT"


attributeKey : String
attributeKey = "ATTR"
attributeKey =
"ATTR"


attributeNamespaceKey : String
attributeNamespaceKey = "ATTR_NS"
attributeNamespaceKey =
"ATTR_NS"


knownKeys : List String
knownKeys = [ styleKey, eventKey, attributeKey, attributeNamespaceKey ]
knownKeys =
[ styleKey, eventKey, attributeKey, attributeNamespaceKey ]
16 changes: 11 additions & 5 deletions src/ServerSide/Helpers.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module ServerSide.Helpers exposing (..) -- where
module ServerSide.Helpers exposing (..)

-- where

import String
import Regex
import ServerSide.Constants exposing (..)
import Dict exposing (Dict)

import Result
import Json.Decode
import Html
import Native.ServerSideHelpers



nativeAddThings : Html.Attribute msg -> Html.Html msg -> Html.Html msg
nativeAddThings =
Native.ServerSideHelpers.addAttribute
Expand All @@ -21,6 +21,7 @@ addAttribute : Html.Attribute msg -> Html.Html msg -> Html.Html msg
addAttribute attribute htmlThing =
nativeAddThings attribute htmlThing


triggerEvent : String -> Json.Decode.Value -> Html.Html msg -> Result String msg
triggerEvent =
Native.ServerSideHelpers.triggerEvent
Expand All @@ -36,35 +37,40 @@ filterKnownKeys =
Dict.filter (\key _ -> not (List.member key knownKeys))



-- UNUSED
-- Hacky text approach


wrapWithQuotesAndColons : String -> String -> String
wrapWithQuotesAndColons left right =
"\"" ++ (String.trim left) ++ "\"" ++ ":" ++ right


replaceInternalStructure : String -> String
replaceInternalStructure =
Regex.replace Regex.All (Regex.regex "<internal structure>") (\_ -> "null")


replaceChildren : String -> String
replaceChildren =
Native.ServerSideHelpers.replaceChildren


wrapFieldsWithQuotes : String -> String
wrapFieldsWithQuotes =
let
rejoiner parts =
case parts of
left::right::_ ->
left :: right :: _ ->
if String.startsWith "{" left then
"{" ++ (wrapWithQuotesAndColons (String.dropLeft 1 left) right)
else
wrapWithQuotesAndColons left right

_ ->
String.join ":" parts
in
String.split ","
>> List.map (String.split ":" >> Debug.log "parts" >> rejoiner)
>> String.join ","

6 changes: 4 additions & 2 deletions src/ServerSide/InternalTypes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module ServerSide.InternalTypes
import Dict exposing (Dict)
import Json.Encode
import Json.Decode exposing ((:=))

import ServerSide.Markdown exposing (..)
import ServerSide.Constants exposing (..)
import ServerSide.Helpers exposing (..)
Expand Down Expand Up @@ -47,6 +46,7 @@ type alias MarkdownNodeRecord =
, model : MarkdownModel
}


type alias CustomNodeRecord =
{ facts : Facts
, model : Json.Decode.Value
Expand Down Expand Up @@ -113,7 +113,8 @@ decodeKeyedNode =
let
-- elm stores keyed nodes as tuples
-- we only want to decode the html, in the second property
decodeSecondNode = (Json.Decode.at [ "_1" ] decodeNodeType)
decodeSecondNode =
(Json.Decode.at [ "_1" ] decodeNodeType)
in
Json.Decode.object4 NodeRecord
("tag" := Json.Decode.string)
Expand All @@ -140,6 +141,7 @@ encodeNodeRecord record =
, ( "descendantsCount", Json.Encode.int record.descendantsCount )
]


decodeCustomNode : Json.Decode.Decoder NodeType
decodeCustomNode =
Json.Decode.oneOf
Expand Down
6 changes: 3 additions & 3 deletions src/ServerSide/Markdown.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ baseMarkdownModel =
, markdown = ""
}


type alias MarkdownOptions =
{ githubFlavored : Maybe { tables : Bool, breaks : Bool }
, defaultHighlighting : Maybe String
Expand All @@ -41,13 +42,12 @@ encodeOptions options =
encodeMarkdownModel : MarkdownModel -> Json.Decode.Value
encodeMarkdownModel model =
Json.Encode.object
[ ("options", encodeOptions model.options )
[ ( "options", encodeOptions model.options )
, ( "markdown", Json.Encode.string model.markdown )
]


decodeMarkdownModel : Json.Decode.Decoder MarkdownModel
decodeMarkdownModel =
Json.Decode.object1 (MarkdownModel baseMarkdownModel.options)
( "markdown" := Json.Decode.string )

("markdown" := Json.Decode.string)
Loading

0 comments on commit 32bdb0e

Please sign in to comment.