Skip to content

Commit

Permalink
Apply elm-format to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
debois committed Dec 30, 2016
1 parent 5a4485c commit 7da99e8
Show file tree
Hide file tree
Showing 23 changed files with 5,266 additions and 4,635 deletions.
609 changes: 334 additions & 275 deletions demo/Demo.elm

Large diffs are not rendered by default.

366 changes: 194 additions & 172 deletions demo/Demo/Badges.elm

Large diffs are not rendered by default.

510 changes: 301 additions & 209 deletions demo/Demo/Buttons.elm

Large diffs are not rendered by default.

1,091 changes: 575 additions & 516 deletions demo/Demo/Cards.elm

Large diffs are not rendered by default.

448 changes: 228 additions & 220 deletions demo/Demo/Chips.elm

Large diffs are not rendered by default.

278 changes: 152 additions & 126 deletions demo/Demo/Code.elm
Original file line number Diff line number Diff line change
@@ -1,185 +1,211 @@
module Demo.Code exposing (..)
module Demo.Code exposing (..)

import Html exposing (Html, text)

import Platform.Cmd exposing (Cmd)
import String
import Markdown

import Material.Elevation as Elevation
import Material.Options as Options exposing (css, div, stylesheet, Property)
import Material.Helpers as Helpers exposing (cmd)
import Material.Color as Color


type State
= Idle
| First String
| Showing String
| FadingIn String
| FadingOut (String, String)
type State
= Idle
| First String
| Showing String
| FadingIn String
| FadingOut ( String, String )


type alias Model = State
type alias Model =
State


model : Model
model = Idle
model : Model
model =
Idle

type Msg
= Set String
| Timeout String

type Msg
= Set String
| Timeout String


delay : Float
delay =
200
delay =
200


later : String -> Cmd Msg
later s =
Helpers.delay delay (Timeout s)

later : String -> Cmd Msg
later s =
Helpers.delay delay (Timeout s)

update : Msg -> State -> ( State, Cmd Msg )
update action state =
let
guard b x =
if b then
x
else
( state, Cmd.none )
in
case action of
Set s ->
case state of
Idle ->
( First s, cmd (Timeout s) )

update : Msg -> State -> (State, Cmd Msg)
update action state =
let
guard b x =
if b then
x
else
(state, Cmd.none)
in
case action of
Set s ->
case state of
Idle ->
(First s, cmd (Timeout s))
First _ ->
( First s, Cmd.none )

First _ ->
(First s, Cmd.none)

Showing s_ ->
guard (s /= s_) ( FadingOut (s_, s), later s_ )
Showing s_ ->
guard (s /= s_) ( FadingOut ( s_, s ), later s_ )

FadingIn s_ ->
guard (s /= s_) ( FadingOut (s_, s), later s )
FadingIn s_ ->
guard (s /= s_) ( FadingOut ( s_, s ), later s )

FadingOut (s_, _) ->
(FadingOut (s_, s), Cmd.none)
FadingOut ( s_, _ ) ->
( FadingOut ( s_, s ), Cmd.none )

Timeout s ->
case state of
Idle ->
( state, Cmd.none ) -- Can't happen
Timeout s ->
case state of
Idle ->
( state, Cmd.none )

First _ ->
( FadingIn s, later s )
-- Can't happen
First _ ->
( FadingIn s, later s )

Showing s_ ->
( state, Cmd.none ) -- Also can't happen
Showing s_ ->
( state, Cmd.none )

FadingIn s_ ->
guard (s == s_) ( Showing s, Cmd.none )
-- Also can't happen
FadingIn s_ ->
guard (s == s_) ( Showing s, Cmd.none )

FadingOut (s_, s__) ->
guard (s == s_) ( FadingIn s__, later s__ )
FadingOut ( s_, s__ ) ->
guard (s == s_) ( FadingIn s__, later s__ )


-- Shenanigans to strip extra whitespace from code examples.

-- Shenanigans to strip extra whitespace from code examples.


lead : Int -> String -> Int
lead k str =
case String.uncons str of
Just (' ', str_) ->
lead (k+1) str_
lead k str =
case String.uncons str of
Just ( ' ', str_ ) ->
lead (k + 1) str_

_ ->
k
_ ->
k


dropWhile : (a -> Bool) -> List a -> List a
dropWhile f xs =
case xs of
[] ->
xs
(x :: xs_) as xs ->
if f x then dropWhile f xs_ else xs
case xs of
[] ->
xs

(x :: xs_) as xs ->
if f x then
dropWhile f xs_
else
xs


trim : String -> String
trim s =
let
-- Drop initial empty lines
lines =
String.trimRight s
|> String.lines
|> dropWhile (String.trim >> (==) "")
-- Find the amount of lead space on the first line
k =
List.head lines
|> Maybe.map (lead 0)
|> Maybe.withDefault 0
in
-- Remove that amount of space from every line
lines
|> List.map (String.dropLeft k)
|> String.join "\n"
trim s =
let
-- Drop initial empty lines
lines =
String.trimRight s
|> String.lines
|> dropWhile (String.trim >> (==) "")

-- Find the amount of lead space on the first line
k =
List.head lines
|> Maybe.map (lead 0)
|> Maybe.withDefault 0
in
-- Remove that amount of space from every line
lines
|> List.map (String.dropLeft k)
|> String.join "\n"


format : String -> List (Property c m) -> String -> Html m
format language options str =
Options.styled
(Markdown.toHtmlWith Markdown.defaultOptions)
(Options.many
[ css "overflow" "auto"
, css "border-radius" "2px"
, css "font-size" "10pt"
, Color.background (Color.color Color.BlueGrey Color.S50)
, Elevation.e2
] :: options)
("```" ++ language ++ "\n" ++ trim str ++ "\n```")
format language options str =
Options.styled
(Markdown.toHtmlWith Markdown.defaultOptions)
(Options.many
[ css "overflow" "auto"
, css "border-radius" "2px"
, css "font-size" "10pt"
, Color.background (Color.color Color.BlueGrey Color.S50)
, Elevation.e2
]
:: options
)
("```" ++ language ++ "\n" ++ trim str ++ "\n```")


code : List (Property c m) -> String -> Html m
code =
format "elm"
code =
format "elm"


html : List (Property c m) -> String -> Html m
html =
format "xml"
format "xml"



-- VIEW


view : State -> List (Property c a) -> Html a
view state options =
let
opacity =
case state of
Idle -> 0
First _ -> 0
FadingIn _ -> 1.0
FadingOut _ -> 0
Showing _ -> 1.0
body =
case state of
Idle -> text ""
First s -> code options s
FadingIn s -> code options s
FadingOut (s, _) -> code options s
Showing s -> code options s
in
div
[ css "transition" ("opacity " ++ toString delay ++ "ms ease-in-out")
, css "opacity" (toString opacity)
]
[ body ]






view state options =
let
opacity =
case state of
Idle ->
0

First _ ->
0

FadingIn _ ->
1.0

FadingOut _ ->
0

Showing _ ->
1.0

body =
case state of
Idle ->
text ""

First s ->
code options s

FadingIn s ->
code options s

FadingOut ( s, _ ) ->
code options s

Showing s ->
code options s
in
div
[ css "transition" ("opacity " ++ toString delay ++ "ms ease-in-out")
, css "opacity" (toString opacity)
]
[ body ]
Loading

0 comments on commit 7da99e8

Please sign in to comment.