Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Elm 0.19 #7

Merged
merged 4 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 43 additions & 36 deletions demo/Demo.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Main exposing (..)
module Main exposing (Model, Msg(..), init, main, update, view, viewAdd, viewElement, viewFilter, viewHayStack)

import Html exposing (Html, input, div, text, button, span)
import Html.Events exposing (onInput, targetValue, onClick)
import Html.Attributes exposing (placeholder, style)
import Browser
import Fuzzy
import Html exposing (Html, button, div, input, span, text)
import Html.Attributes exposing (placeholder, style)
import Html.Events exposing (onClick, onInput, targetValue)
import String


Expand Down Expand Up @@ -73,6 +74,7 @@ viewElement ( result, item ) =
(\e sum ->
if not sum then
List.member (index - e.offset) e.keys

else
sum
)
Expand All @@ -83,7 +85,8 @@ viewElement ( result, item ) =
List.foldl
(\e sum ->
if not sum then
(e.offset <= index && (e.offset + e.length) > index)
e.offset <= index && (e.offset + e.length) > index

else
sum
)
Expand All @@ -92,34 +95,36 @@ viewElement ( result, item ) =

color index =
if isKey index then
[ ( "color", "red" ) ]
Just ( "color", "red" )

else
[]
Nothing

bgColor index =
if isMatch index then
[ ( "background-color", "yellow" ) ]
Just ( "background-color", "yellow" )

else
[]
Nothing

hStyle index =
style ((color index) ++ (bgColor index))
[ color index, bgColor index ]
|> List.filterMap identity
|> List.map (\( styleName, styleValue ) -> style styleName styleValue)

accumulateChar c ( sum, index ) =
( sum ++ [ span [ hStyle index ] [ c |> String.fromChar |> text ] ], index + 1 )
( sum ++ [ span (hStyle index) [ c |> String.fromChar |> text ] ], index + 1 )

highlight =
String.foldl accumulateChar ( [], 0 ) item
in
div []
[ span
[ style
[ ( "color", "red" )
]
]
[ text ((toString result.score) ++ " ") ]
, span [] (Tuple.first highlight)
div []
[ span
[ style "color" "red"
]
[ text (String.fromInt result.score ++ " ") ]
, span [] (Tuple.first highlight)
]


viewHayStack : Model -> Html Msg
Expand All @@ -128,6 +133,7 @@ viewHayStack model =
processCase item =
if model.caseInsensitive then
String.toLower item

else
item

Expand All @@ -145,10 +151,10 @@ viewHayStack model =
sortedHays =
List.sortBy (\e -> Tuple.first e |> .score) scoredHays
in
div []
(sortedHays
|> List.map viewElement
)
div []
(sortedHays
|> List.map viewElement
)


viewFilter : Model -> Html Msg
Expand All @@ -157,22 +163,23 @@ viewFilter model =
caseText =
if model.caseInsensitive then
"Case insensitive"

else
"Case sensitive"
in
div []
[ input
[ onInput (\e -> Filter e)
, placeholder "Filter"
]
[]
, input
[ onInput (\e -> Separate e)
, placeholder "Separators"
]
[]
, button [ onClick CaseFlip ] [ text caseText ]
div []
[ input
[ onInput (\e -> Filter e)
, placeholder "Filter"
]
[]
, input
[ onInput (\e -> Separate e)
, placeholder "Separators"
]
[]
, button [ onClick CaseFlip ] [ text caseText ]
]


viewAdd : Model -> Html Msg
Expand All @@ -197,4 +204,4 @@ view model =


main =
Html.beginnerProgram { model = init, update = update, view = view }
Browser.sandbox { init = init, update = update, view = view }
16 changes: 0 additions & 16 deletions demo/elm-package.json

This file was deleted.

25 changes: 25 additions & 0 deletions demo/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
".",
"../src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
16 changes: 0 additions & 16 deletions elm-package.json

This file was deleted.

15 changes: 15 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "package",
"name": "tripokey/elm-fuzzy",
"summary": "A library for fuzzy string matching",
"license": "BSD-3-Clause",
"version": "5.2.0",
"exposed-modules": [
"Fuzzy"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {}
}
Loading