Skip to content

Commit

Permalink
Update to Elm 0.18.
Browse files Browse the repository at this point in the history
Signed-off-by: David Calavera <david.calavera@gmail.com>
  • Loading branch information
calavera committed Dec 10, 2016
1 parent 278d9ea commit ac299ab
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
sudo: false

env:
ELM_VERSION=0.17.0
ELM_VERSION=0.18.0

language: node_js
node_js:
Expand Down
12 changes: 6 additions & 6 deletions elm-package.json
Expand Up @@ -9,11 +9,11 @@
"exposed-modules": [],
"native-modules": true,
"dependencies": {
"elm-lang/core": "4.0.5 <= v < 5.0.0",
"elm-lang/html": "1.1.0 <= v < 2.0.0",
"elm-lang/navigation": "1.0.0 <= v < 2.0.0",
"evancz/url-parser": "1.0.0 <= v < 2.0.0",
"sporto/erl": "10.0.1 <= v < 11.0.0"
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/navigation": "2.0.1 <= v < 3.0.0",
"evancz/url-parser": "2.0.1 <= v < 3.0.0",
"sporto/erl": "10.0.2 <= v < 11.0.0"
},
"elm-version": "0.17.1 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -27,9 +27,9 @@
},
"homepage": "https://github.com/netlify/netlify-playground#readme",
"dependencies": {
"elm": "^0.17.1",
"elm": "^0.18.0",
"css-loader": "^0.25.0",
"elm-webpack-loader": "^3.0.6",
"elm-webpack-loader": "^3.1.0",
"file-loader": "^0.9.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
Expand Down
43 changes: 29 additions & 14 deletions src/List/Extra.elm
@@ -1,15 +1,22 @@
module List.Extra exposing (..)

-- List.Extra

{-| Take elements in order as long as the predicate evaluates to `True`
-}

-- List.Extra


takeWhile : (a -> Bool) -> List a -> List a
takeWhile predicate list =
case list of
[] -> []
x::xs -> if (predicate x) then x :: takeWhile predicate xs
else []
case list of
[] ->
[]

x :: xs ->
if (predicate x) then
x :: takeWhile predicate xs
else
[]


{-| Drop the given prefix from the list. If the list doesn't start with that prefix, return `Nothing`.
Expand All @@ -21,11 +28,19 @@ takeWhile predicate list =
-}
stripPrefix : List a -> List a -> Maybe (List a)
stripPrefix prefix xs =
let
step e m =
case m of
Nothing -> Nothing
Just [] -> Nothing
Just (x::xs') -> if e == x then Just xs' else Nothing
in
List.foldl step (Just xs) prefix
let
step e m =
case m of
Nothing ->
Nothing

Just [] ->
Nothing

Just (x :: xs_) ->
if e == x then
Just xs_
else
Nothing
in
List.foldl step (Just xs) prefix
37 changes: 15 additions & 22 deletions src/Main.elm
Expand Up @@ -2,18 +2,19 @@ module Main exposing (..)

import Navigation
import Messages exposing (Msg(..))
import Models exposing (Model, Rules, initialModel)
import Models exposing (Model, Rules)
import View exposing (view)
import Routing exposing (Route)
import Routing exposing (Route, route)
import UrlParser


init : Result String Route -> ( Model, Cmd Msg )
init result =
init : Navigation.Location -> ( Model, Cmd Msg )
init location =
let
currentRoute =
Routing.routeFromResult result
history =
UrlParser.parsePath route location
in
( initialModel currentRoute, Cmd.none )
( { history = [ history ], rules = Rules "" "" }, Cmd.none )


subscriptions : Model -> Sub Msg
Expand All @@ -24,31 +25,23 @@ subscriptions model =
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NewUrl url ->
( model, Navigation.newUrl url )

UrlChange location ->
( { model | history = UrlParser.parsePath route location :: model.history }, Cmd.none )

RulesChanged newRules ->
{ model | rules = Rules newRules model.rules.updatedText } ! []

ParseRedirects newRules ->
{ model | rules = Rules model.rules.text newRules } ! []

ShowRedirects ->
( model, Navigation.newUrl "#redirects" )


urlUpdate : Result String Route -> Model -> ( Model, Cmd Msg )
urlUpdate result model =
let
currentRoute =
Routing.routeFromResult result
in
( { model | route = currentRoute }, Cmd.none )


main : Program Never
main =
Navigation.program Routing.parser
Navigation.program UrlChange
{ init = init
, view = view
, update = update
, urlUpdate = urlUpdate
, subscriptions = subscriptions
}
4 changes: 3 additions & 1 deletion src/Messages.elm
@@ -1,9 +1,11 @@
module Messages exposing (..)

import Navigation
import Redirects.Messages


type Msg
= ShowRedirects
= NewUrl String
| UrlChange Navigation.Location
| ParseRedirects String
| RulesChanged String
9 changes: 1 addition & 8 deletions src/Models.elm
Expand Up @@ -10,13 +10,6 @@ type alias Rules =


type alias Model =
{ route : Routing.Route
{ history : List (Maybe Routing.Route)
, rules : Rules
}


initialModel : Routing.Route -> Model
initialModel route =
{ route = route
, rules = Rules "" ""
}
2 changes: 1 addition & 1 deletion src/Partials.elm
Expand Up @@ -22,7 +22,7 @@ pageHeader model links button =
]
[ text "Netlify's Playground" ]
, a
[ onClick ShowRedirects
[ onClick (NewUrl "/redirects")
, class "nav-item"
, attribute "data-letters" "Redirects"
]
Expand Down
4 changes: 2 additions & 2 deletions src/Redirects/View.elm
Expand Up @@ -21,7 +21,7 @@ render model =
in
div [ class "main" ]
[ Partials.pageHeader model links button
, main'
, main_
[]
[ Partials.editor model redirectsPlaceholder
, parseRedirects model
Expand Down Expand Up @@ -56,7 +56,7 @@ showRedirectsResult response =
[ (redirectsResultHeader response)
, div [ class "results-list" ] (List.map renderErrorRule response.errors)
, button
[ type' "button"
[ type_ "button"
, title "Close results panel"
, onClick (ParseRedirects "")
]
Expand Down
39 changes: 8 additions & 31 deletions src/Routing.elm
Expand Up @@ -2,40 +2,17 @@ module Routing exposing (..)

import String
import Navigation
import UrlParser exposing (..)
import UrlParser exposing (s, top)


type Route
= HomeRoute
| RedirectsRoute
| NotFoundRoute
= Home
| Redirects


matchers : Parser (Route -> a) a
matchers =
oneOf
[ format HomeRoute (s "")
, format RedirectsRoute (s "redirects")
route : UrlParser.Parser (Route -> a) a
route =
UrlParser.oneOf
[ UrlParser.map Home top
, UrlParser.map Redirects (s "redirects")
]


hashParser : Navigation.Location -> Result String Route
hashParser location =
location.hash
|> String.dropLeft 1
|> parse identity matchers


parser : Navigation.Parser (Result String Route)
parser =
Navigation.makeParser hashParser


routeFromResult : Result String Route -> Route
routeFromResult result =
case result of
Ok route ->
route

Err string ->
NotFoundRoute
27 changes: 17 additions & 10 deletions src/View.elm
Expand Up @@ -13,22 +13,29 @@ import Redirects.View

view : Model -> Html Msg
view model =
case model.route of
RedirectsRoute ->
Redirects.View.render model.rules

HomeRoute ->
case model.history of
[] ->
homeView model.rules

NotFoundRoute ->
notFoundView model.rules
current :: _ ->
case current of
Nothing ->
homeView model.rules

Just route ->
case route of
Redirects ->
Redirects.View.render model.rules

Home ->
homeView model.rules


notFoundView : Rules -> Html Msg
notFoundView model =
div []
[ Partials.pageHeader model Nothing Nothing
, main'
, main_
[ class "central-message" ]
[ div [ class "title" ]
[ text "This is not the place you're looking for" ]
Expand All @@ -40,7 +47,7 @@ homeView : Rules -> Html Msg
homeView model =
div []
[ Partials.pageHeader model Nothing Nothing
, main'
, main_
[ class "central-message" ]
[ div [ class "title" ]
[ text "PLAY - Netlify's Playground" ]
Expand All @@ -59,7 +66,7 @@ homeView model =
[ span []
[ text "go to "
, a
[ onClick ShowRedirects ]
[ onClick (NewUrl "/redirects") ]
[ text "redirects" ]
, text " to test your _redirects rules"
]
Expand Down
1 change: 0 additions & 1 deletion tests/Main.elm
Expand Up @@ -5,7 +5,6 @@ import Json.Encode exposing (Value)
import Redirects.Tests


main : Program Value
main =
run emit Redirects.Tests.all

Expand Down
17 changes: 8 additions & 9 deletions tests/elm-package.json
@@ -1,7 +1,6 @@
{
"version": "1.0.0",
"summary": "Sample Elm Test",
"description": "Description",
"repository": "https://github.com/user/project.git",
"license": "BSD-3-Clause",
"source-directories": [
Expand All @@ -10,13 +9,13 @@
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-community/elm-test": "2.0.0 <= v < 3.0.0",
"rtfeldman/node-test-runner": "2.0.0 <= v < 3.0.0",
"elm-lang/html": "1.1.0 <= v < 2.0.0",
"sporto/erl": "10.0.1 <= v < 11.0.0",
"elm-lang/navigation": "1.0.0 <= v < 2.0.0",
"evancz/url-parser": "1.0.0 <= v < 2.0.0"
"elm-community/elm-test": "3.1.0 <= v < 4.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/navigation": "2.0.1 <= v < 3.0.0",
"evancz/url-parser": "2.0.1 <= v < 3.0.0",
"rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0",
"sporto/erl": "11.0.0 <= v < 12.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}

0 comments on commit ac299ab

Please sign in to comment.