Remove part9 and part10
This commit is contained in:
@@ -1,140 +0,0 @@
|
|||||||
module ElmHub exposing (..)
|
|
||||||
|
|
||||||
import Html exposing (..)
|
|
||||||
import Html.Attributes exposing (..)
|
|
||||||
import Html.Events exposing (..)
|
|
||||||
import Html.App as Html
|
|
||||||
import Http
|
|
||||||
import Auth
|
|
||||||
import Task exposing (Task)
|
|
||||||
import Json.Decode exposing (Decoder)
|
|
||||||
import Dict exposing (Dict)
|
|
||||||
import SearchResult
|
|
||||||
|
|
||||||
|
|
||||||
searchFeed : String -> Cmd Msg
|
|
||||||
searchFeed query =
|
|
||||||
let
|
|
||||||
url =
|
|
||||||
"https://api.github.com/search/repositories?access_token="
|
|
||||||
++ Auth.token
|
|
||||||
++ "&q="
|
|
||||||
++ query
|
|
||||||
++ "+language:elm&sort=stars&order=desc"
|
|
||||||
in
|
|
||||||
Task.perform HandleSearchError HandleSearchResponse (Http.get responseDecoder url)
|
|
||||||
|
|
||||||
|
|
||||||
responseDecoder : Decoder (List SearchResult.Model)
|
|
||||||
responseDecoder =
|
|
||||||
Json.Decode.at [ "items" ] (Json.Decode.list SearchResult.decoder)
|
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
|
||||||
{ query : String
|
|
||||||
, results : Dict Int SearchResult.Model
|
|
||||||
, errorMessage : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
initialModel : Model
|
|
||||||
initialModel =
|
|
||||||
{ query = "tutorial"
|
|
||||||
, results = Dict.empty
|
|
||||||
, errorMessage = Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
|
||||||
view model =
|
|
||||||
div [ class "content" ]
|
|
||||||
[ header []
|
|
||||||
[ h1 [] [ text "ElmHub" ]
|
|
||||||
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
|
|
||||||
]
|
|
||||||
, input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
|
|
||||||
, button [ class "search-button", onClick Search ] [ text "Search" ]
|
|
||||||
, viewErrorMessage model.errorMessage
|
|
||||||
, ul [ class "results" ] (viewSearchResults model.results)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
viewErrorMessage : Maybe String -> Html a
|
|
||||||
viewErrorMessage errorMessage =
|
|
||||||
case errorMessage of
|
|
||||||
Just message ->
|
|
||||||
div [ class "error" ] [ text message ]
|
|
||||||
|
|
||||||
Nothing ->
|
|
||||||
text ""
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResults : Dict Int SearchResult.Model -> List (Html Msg)
|
|
||||||
viewSearchResults results =
|
|
||||||
results
|
|
||||||
|> Dict.values
|
|
||||||
|> List.sortBy (.stars >> negate)
|
|
||||||
|> List.map viewSearchResult
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResult : SearchResult.Model -> Html Msg
|
|
||||||
viewSearchResult result =
|
|
||||||
-- TODO call SearchResult.view to render a search result.
|
|
||||||
--
|
|
||||||
-- Hint: Use Html.map and UpdateSearchResult to translate from
|
|
||||||
-- SearchResult.Msg into the Msg type we have defined in this module.
|
|
||||||
div [] []
|
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
|
||||||
= Search
|
|
||||||
| SetQuery String
|
|
||||||
| UpdateSearchResult Int SearchResult.Msg
|
|
||||||
| HandleSearchResponse (List SearchResult.Model)
|
|
||||||
| HandleSearchError Http.Error
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
||||||
update msg model =
|
|
||||||
case msg of
|
|
||||||
Search ->
|
|
||||||
model ! [ searchFeed model.query ]
|
|
||||||
|
|
||||||
SetQuery query ->
|
|
||||||
{ model | query = query, errorMessage = Nothing } ! []
|
|
||||||
|
|
||||||
HandleSearchError error ->
|
|
||||||
case error of
|
|
||||||
Http.UnexpectedPayload str ->
|
|
||||||
{ model | errorMessage = Just str } ! []
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
{ model | errorMessage = Just "Error loading search results" } ! []
|
|
||||||
|
|
||||||
HandleSearchResponse results ->
|
|
||||||
let
|
|
||||||
resultsById : Dict Int SearchResult.Model
|
|
||||||
resultsById =
|
|
||||||
results
|
|
||||||
|> List.map (\result -> ( result.id, result ))
|
|
||||||
|> Dict.fromList
|
|
||||||
in
|
|
||||||
{ model | results = resultsById } ! []
|
|
||||||
|
|
||||||
UpdateSearchResult id childMsg ->
|
|
||||||
case Dict.get id model.results of
|
|
||||||
Nothing ->
|
|
||||||
model ! []
|
|
||||||
|
|
||||||
Just childModel ->
|
|
||||||
let
|
|
||||||
( newChildModel, childCmd ) =
|
|
||||||
SearchResult.update childMsg childModel
|
|
||||||
|
|
||||||
cmd =
|
|
||||||
Cmd.map (UpdateSearchResult id) childCmd
|
|
||||||
|
|
||||||
newResults =
|
|
||||||
Dict.insert id newChildModel model.results
|
|
||||||
in
|
|
||||||
{ model | results = newResults } ! [ cmd ]
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
module Main exposing (..)
|
|
||||||
|
|
||||||
import ElmHub exposing (..)
|
|
||||||
import Html.App as Html
|
|
||||||
|
|
||||||
|
|
||||||
main : Program Never
|
|
||||||
main =
|
|
||||||
Html.program
|
|
||||||
{ view = view
|
|
||||||
, update = update
|
|
||||||
, init = ( initialModel, searchFeed initialModel.query )
|
|
||||||
, subscriptions = \_ -> Sub.none
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
Part 10
|
|
||||||
=======
|
|
||||||
|
|
||||||
The instructor will paste notes from the lesson, including code examples from
|
|
||||||
Q&A, in [this document](https://docs.google.com/document/d/1ApuSOk9DP0YsQrxhW7-WE8UOEAV4PPnLDDeqUOL2o5k/edit?usp=sharing).
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
elm-package install
|
|
||||||
```
|
|
||||||
|
|
||||||
(Answer `y` when prompted.)
|
|
||||||
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
```bash
|
|
||||||
elm-live Main.elm --open --output=elm.js
|
|
||||||
```
|
|
||||||
|
|
||||||
## References
|
|
||||||
|
|
||||||
* [Elm Architecture Tutorial](https://github.com/evancz/elm-architecture-tutorial)
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
module SearchResult exposing (..)
|
|
||||||
|
|
||||||
import Html exposing (..)
|
|
||||||
import Html.Attributes exposing (class, target, href, property, defaultValue)
|
|
||||||
import Html.Events exposing (..)
|
|
||||||
import Json.Decode exposing (Decoder)
|
|
||||||
import Json.Decode.Pipeline exposing (..)
|
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
|
||||||
{ id : Int
|
|
||||||
, name : String
|
|
||||||
, stars : Int
|
|
||||||
, expanded : Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
|
||||||
= Expand
|
|
||||||
| Collapse
|
|
||||||
|
|
||||||
|
|
||||||
decoder : Decoder Model
|
|
||||||
decoder =
|
|
||||||
decode Model
|
|
||||||
|> required "id" Json.Decode.int
|
|
||||||
|> required "full_name" Json.Decode.string
|
|
||||||
|> required "stargazers_count" Json.Decode.int
|
|
||||||
|> hardcoded True
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
||||||
update msg model =
|
|
||||||
-- TODO implement Expand and Collapse logic
|
|
||||||
model ! []
|
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
|
||||||
view model =
|
|
||||||
if model.expanded then
|
|
||||||
li []
|
|
||||||
[ span [ class "star-count" ] [ text (toString model.stars) ]
|
|
||||||
, a [ href ("https://github.com/" ++ model.name), target "_blank" ]
|
|
||||||
[ text model.name ]
|
|
||||||
-- TODO send a Collapse message on click
|
|
||||||
, button [ class "hide-result" ]
|
|
||||||
[ text "X" ]
|
|
||||||
]
|
|
||||||
else
|
|
||||||
li []
|
|
||||||
-- TODO send an Expand message on click
|
|
||||||
[ button [ class "expand-result" ]
|
|
||||||
[ text "Show" ]
|
|
||||||
]
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"summary": "Like GitHub, but for Elm stuff.",
|
|
||||||
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"source-directories": [
|
|
||||||
".",
|
|
||||||
".."
|
|
||||||
],
|
|
||||||
"exposed-modules": [],
|
|
||||||
"dependencies": {
|
|
||||||
"NoRedInk/elm-decode-pipeline": "1.1.2 <= v < 2.0.0",
|
|
||||||
"elm-lang/core": "4.0.1 <= v < 5.0.0",
|
|
||||||
"elm-lang/html": "1.0.0 <= v < 2.0.0",
|
|
||||||
"evancz/elm-http": "3.0.1 <= v < 4.0.0"
|
|
||||||
},
|
|
||||||
"elm-version": "0.17.0 <= v < 0.18.0"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>ElmHub</title>
|
|
||||||
<script type="text/javascript" src="elm.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
<link rel="icon" type="image/png" href="elm-hub.png">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
var app = Elm.Main.fullscreen();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
|
|
||||||
.content {
|
|
||||||
width: 960px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 30px;
|
|
||||||
font-family: Helvetica, Arial, serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
position: relative;
|
|
||||||
padding: 6px 12px;
|
|
||||||
height: 36px;
|
|
||||||
background-color: rgb(96, 181, 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: white;
|
|
||||||
font-weight: normal;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tagline {
|
|
||||||
color: #eee;
|
|
||||||
position: absolute;
|
|
||||||
right: 16px;
|
|
||||||
top: 12px;
|
|
||||||
font-size: 24px;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.results {
|
|
||||||
list-style-image: url('http://img-cache.cdn.gaiaonline.com/76bd5c99d8f2236e9d3672510e933fdf/http://i278.photobucket.com/albums/kk81/d3m3nt3dpr3p/Tiny-Star-Icon.png');
|
|
||||||
list-style-position: inside;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.results li {
|
|
||||||
font-size: 18px;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.star-count {
|
|
||||||
font-weight: bold;
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-query {
|
|
||||||
padding: 8px;
|
|
||||||
font-size: 24px;
|
|
||||||
margin-bottom: 18px;
|
|
||||||
margin-top: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-button {
|
|
||||||
padding: 8px 16px;
|
|
||||||
font-size: 24px;
|
|
||||||
color: white;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
background-color: rgb(96, 181, 204);
|
|
||||||
margin-left: 12px
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-button:hover {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide-result {
|
|
||||||
background-color: transparent;
|
|
||||||
border: 0;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 18px;
|
|
||||||
margin-left: 18px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide-result:hover {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
button:focus, input:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
132
part9/ElmHub.elm
132
part9/ElmHub.elm
@@ -1,132 +0,0 @@
|
|||||||
module ElmHub exposing (..)
|
|
||||||
|
|
||||||
import Html exposing (..)
|
|
||||||
import Html.Attributes exposing (class, target, href, property, defaultValue)
|
|
||||||
import Html.Events exposing (..)
|
|
||||||
import Auth
|
|
||||||
import Json.Decode exposing (Decoder)
|
|
||||||
import Json.Decode.Pipeline exposing (..)
|
|
||||||
import Dict exposing (Dict)
|
|
||||||
import Http
|
|
||||||
import Task
|
|
||||||
|
|
||||||
|
|
||||||
searchFeed : String -> Cmd Msg
|
|
||||||
searchFeed query =
|
|
||||||
let
|
|
||||||
url =
|
|
||||||
"https://api.github.com/search/repositories?access_token="
|
|
||||||
++ Auth.token
|
|
||||||
++ "&q="
|
|
||||||
++ query
|
|
||||||
++ "+language:elm&sort=stars&order=desc"
|
|
||||||
in
|
|
||||||
Task.perform HandleSearchError HandleSearchResponse (Http.get responseDecoder url)
|
|
||||||
|
|
||||||
|
|
||||||
responseDecoder : Decoder (List SearchResult)
|
|
||||||
responseDecoder =
|
|
||||||
Json.Decode.at [ "items" ] (Json.Decode.list searchResultDecoder)
|
|
||||||
|
|
||||||
|
|
||||||
searchResultDecoder : Decoder SearchResult
|
|
||||||
searchResultDecoder =
|
|
||||||
decode SearchResult
|
|
||||||
|> required "id" Json.Decode.int
|
|
||||||
|> required "full_name" Json.Decode.string
|
|
||||||
|> required "stargazers_count" Json.Decode.int
|
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
|
||||||
{ query : String
|
|
||||||
, results : Dict Int SearchResult
|
|
||||||
, errorMessage : Maybe String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type alias SearchResult =
|
|
||||||
{ id : Int
|
|
||||||
, name : String
|
|
||||||
, stars : Int
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
initialModel : Model
|
|
||||||
initialModel =
|
|
||||||
{ query = "tutorial"
|
|
||||||
, results = Dict.empty
|
|
||||||
, errorMessage = Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
|
||||||
view model =
|
|
||||||
div [ class "content" ]
|
|
||||||
[ header []
|
|
||||||
[ h1 [] [ text "ElmHub" ]
|
|
||||||
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
|
|
||||||
]
|
|
||||||
, input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
|
|
||||||
, button [ class "search-button", onClick Search ] [ text "Search" ]
|
|
||||||
, ul [ class "results" ] (viewSearchResults model.results)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResults : Dict Int SearchResult -> List (Html Msg)
|
|
||||||
viewSearchResults results =
|
|
||||||
-- TODO sort by star count and render
|
|
||||||
[]
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResult : SearchResult -> Html Msg
|
|
||||||
viewSearchResult result =
|
|
||||||
li []
|
|
||||||
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
|
||||||
, a [ href ("https://github.com/" ++ result.name), target "_blank" ]
|
|
||||||
[ text result.name ]
|
|
||||||
, button [ class "hide-result", onClick (DeleteById result.id) ]
|
|
||||||
[ text "X" ]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
|
||||||
= Search
|
|
||||||
| SetQuery String
|
|
||||||
| DeleteById Int
|
|
||||||
| HandleSearchResponse (List SearchResult)
|
|
||||||
| HandleSearchError Http.Error
|
|
||||||
| DoNothing
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
||||||
update msg model =
|
|
||||||
case msg of
|
|
||||||
Search ->
|
|
||||||
model ! [ searchFeed model.query ]
|
|
||||||
|
|
||||||
SetQuery query ->
|
|
||||||
{ model | query = query } ! []
|
|
||||||
|
|
||||||
HandleSearchError error ->
|
|
||||||
case error of
|
|
||||||
Http.UnexpectedPayload str ->
|
|
||||||
{ model | errorMessage = Just str } ! []
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
{ model | errorMessage = Just "Error loading search results" } ! []
|
|
||||||
|
|
||||||
HandleSearchResponse results ->
|
|
||||||
let
|
|
||||||
resultsById : Dict Int SearchResult
|
|
||||||
resultsById =
|
|
||||||
-- TODO convert results list into a Dict
|
|
||||||
Dict.empty
|
|
||||||
in
|
|
||||||
{ model | results = resultsById } ! []
|
|
||||||
|
|
||||||
DeleteById id ->
|
|
||||||
-- TODO delete the result with the given id
|
|
||||||
model ! []
|
|
||||||
|
|
||||||
DoNothing ->
|
|
||||||
model ! []
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
module Main exposing (..)
|
|
||||||
|
|
||||||
import ElmHub exposing (..)
|
|
||||||
import Html.App as Html
|
|
||||||
|
|
||||||
|
|
||||||
main : Program Never
|
|
||||||
main =
|
|
||||||
Html.program
|
|
||||||
{ view = view
|
|
||||||
, update = update
|
|
||||||
, init = ( initialModel, searchFeed initialModel.query )
|
|
||||||
, subscriptions = \_ -> Sub.none
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
Part 9
|
|
||||||
======
|
|
||||||
|
|
||||||
The instructor will paste notes from the lesson, including code examples from
|
|
||||||
Q&A, in [this document](https://docs.google.com/document/d/1ApuSOk9DP0YsQrxhW7-WE8UOEAV4PPnLDDeqUOL2o5k/edit?usp=sharing).
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
elm-package install
|
|
||||||
```
|
|
||||||
|
|
||||||
(Answer `y` when prompted.)
|
|
||||||
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
```bash
|
|
||||||
elm-live Main.elm --open --output=elm.js
|
|
||||||
```
|
|
||||||
|
|
||||||
## Running Tests
|
|
||||||
|
|
||||||
Do either (or both!) of the following:
|
|
||||||
|
|
||||||
#### Running tests on the command line
|
|
||||||
|
|
||||||
```bash
|
|
||||||
elm-test
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Running tests in a browser
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd tests
|
|
||||||
elm-reactor
|
|
||||||
```
|
|
||||||
|
|
||||||
Then visit [localhost:8000](http://localhost:8000) and choose `HtmlRunner.elm`.
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"summary": "Like GitHub, but for Elm stuff.",
|
|
||||||
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"source-directories": [
|
|
||||||
".",
|
|
||||||
".."
|
|
||||||
],
|
|
||||||
"exposed-modules": [],
|
|
||||||
"dependencies": {
|
|
||||||
"NoRedInk/elm-decode-pipeline": "1.1.2 <= v < 2.0.0",
|
|
||||||
"elm-lang/core": "4.0.1 <= v < 5.0.0",
|
|
||||||
"elm-lang/html": "1.0.0 <= v < 2.0.0",
|
|
||||||
"evancz/elm-http": "3.0.1 <= v < 4.0.0"
|
|
||||||
},
|
|
||||||
"elm-version": "0.17.0 <= v < 0.18.0"
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>ElmHub</title>
|
|
||||||
<script type="text/javascript" src="elm.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
<link rel="icon" type="image/png" href="elm-hub.png">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
var app = Elm.Main.fullscreen();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
101
part9/style.css
101
part9/style.css
@@ -1,101 +0,0 @@
|
|||||||
|
|
||||||
.content {
|
|
||||||
width: 960px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 30px;
|
|
||||||
font-family: Helvetica, Arial, serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
position: relative;
|
|
||||||
padding: 6px 12px;
|
|
||||||
height: 36px;
|
|
||||||
background-color: rgb(96, 181, 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: white;
|
|
||||||
font-weight: normal;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tagline {
|
|
||||||
color: #eee;
|
|
||||||
position: absolute;
|
|
||||||
right: 16px;
|
|
||||||
top: 12px;
|
|
||||||
font-size: 24px;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.results {
|
|
||||||
list-style-image: url('http://img-cache.cdn.gaiaonline.com/76bd5c99d8f2236e9d3672510e933fdf/http://i278.photobucket.com/albums/kk81/d3m3nt3dpr3p/Tiny-Star-Icon.png');
|
|
||||||
list-style-position: inside;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.results li {
|
|
||||||
font-size: 18px;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.star-count {
|
|
||||||
font-weight: bold;
|
|
||||||
margin-right: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-query {
|
|
||||||
padding: 8px;
|
|
||||||
font-size: 24px;
|
|
||||||
margin-bottom: 18px;
|
|
||||||
margin-top: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-button {
|
|
||||||
padding: 8px 16px;
|
|
||||||
font-size: 24px;
|
|
||||||
color: white;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
background-color: rgb(96, 181, 204);
|
|
||||||
margin-left: 12px
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-button:hover {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide-result {
|
|
||||||
background-color: transparent;
|
|
||||||
border: 0;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 18px;
|
|
||||||
margin-left: 18px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide-result:hover {
|
|
||||||
color: rgb(96, 181, 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
button:focus, input:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.error {
|
|
||||||
background-color: #FF9632;
|
|
||||||
padding: 20px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
overflow-x: auto;
|
|
||||||
font-family: monospace;
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
module HtmlRunner exposing (..)
|
|
||||||
|
|
||||||
import Tests
|
|
||||||
import Test.Runner.Html as Runner
|
|
||||||
|
|
||||||
|
|
||||||
-- To run this:
|
|
||||||
--
|
|
||||||
-- cd into part8/test
|
|
||||||
-- elm-reactor
|
|
||||||
-- navigate to HtmlRunner.elm
|
|
||||||
|
|
||||||
|
|
||||||
main : Program Never
|
|
||||||
main =
|
|
||||||
Runner.run Tests.all
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
port module Main exposing (..)
|
|
||||||
|
|
||||||
import Tests
|
|
||||||
import Test.Runner.Node as Runner
|
|
||||||
import Json.Decode exposing (Value)
|
|
||||||
|
|
||||||
|
|
||||||
-- To run this:
|
|
||||||
--
|
|
||||||
-- elm-test
|
|
||||||
|
|
||||||
|
|
||||||
main : Program Value
|
|
||||||
main =
|
|
||||||
Runner.run emit Tests.all
|
|
||||||
|
|
||||||
|
|
||||||
port emit : ( String, Value ) -> Cmd msg
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
module Tests exposing (..)
|
|
||||||
|
|
||||||
import Test exposing (..)
|
|
||||||
import Fuzz exposing (..)
|
|
||||||
import Expect exposing (Expectation)
|
|
||||||
import ElmHub exposing (responseDecoder)
|
|
||||||
import Json.Decode exposing (decodeString, Value)
|
|
||||||
import String
|
|
||||||
|
|
||||||
|
|
||||||
all : Test
|
|
||||||
all =
|
|
||||||
describe "GitHub Response Decoder"
|
|
||||||
[ test "it results in an Err for invalid JSON" <|
|
|
||||||
\() ->
|
|
||||||
let
|
|
||||||
json =
|
|
||||||
"""{ "pizza": [] }"""
|
|
||||||
|
|
||||||
isErrorResult result =
|
|
||||||
-- TODO return True if the given Result is an Err of some sort,
|
|
||||||
-- and False if it is an Ok of some sort.
|
|
||||||
--
|
|
||||||
-- Result docs: http://package.elm-lang.org/packages/elm-lang/core/4.0.1/Result
|
|
||||||
False
|
|
||||||
in
|
|
||||||
json
|
|
||||||
|> decodeString responseDecoder
|
|
||||||
|> isErrorResult
|
|
||||||
|> Expect.true "Expected decoding an invalid response to return an Err."
|
|
||||||
, test "it successfully decodes a valid response" <|
|
|
||||||
\() ->
|
|
||||||
"""{ "items": [
|
|
||||||
/* TODO: put JSON here! */
|
|
||||||
] }"""
|
|
||||||
|> decodeString responseDecoder
|
|
||||||
|> Expect.equal
|
|
||||||
(Ok
|
|
||||||
[ { id = 5, name = "foo", stars = 42 }
|
|
||||||
, { id = 3, name = "bar", stars = 77 }
|
|
||||||
]
|
|
||||||
)
|
|
||||||
, test "it decodes one SearchResult for each 'item' in the JSON" <|
|
|
||||||
\() ->
|
|
||||||
let
|
|
||||||
-- TODO convert this to a fuzz test that generates a random
|
|
||||||
-- list of ids instead of this hardcoded list of three ids.
|
|
||||||
--
|
|
||||||
-- fuzz test docs: http://package.elm-lang.org/packages/project-fuzzball/test/2.0.1/Test#fuzz
|
|
||||||
-- Fuzzer docs: http://package.elm-lang.org/packages/project-fuzzball/test/2.0.1/Fuzz
|
|
||||||
ids =
|
|
||||||
[ 12, 5, 76 ]
|
|
||||||
|
|
||||||
jsonFromId id =
|
|
||||||
"""{"id": """ ++ toString id ++ """, "full_name": "foo", "stargazers_count": 42}"""
|
|
||||||
|
|
||||||
jsonItems =
|
|
||||||
String.join ", " (List.map jsonFromId ids)
|
|
||||||
|
|
||||||
json =
|
|
||||||
"""{ "items": [""" ++ jsonItems ++ """] }"""
|
|
||||||
in
|
|
||||||
case decodeString responseDecoder json of
|
|
||||||
Ok results ->
|
|
||||||
List.length results
|
|
||||||
|> Expect.equal (List.length ids)
|
|
||||||
|
|
||||||
Err err ->
|
|
||||||
Expect.fail ("JSON decoding failed unexpectedly: " ++ err)
|
|
||||||
]
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1.0.0",
|
|
||||||
"summary": "Like GitHub, but for Elm stuff.",
|
|
||||||
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"source-directories": [
|
|
||||||
".",
|
|
||||||
".."
|
|
||||||
],
|
|
||||||
"exposed-modules": [],
|
|
||||||
"dependencies": {
|
|
||||||
"NoRedInk/elm-decode-pipeline": "1.1.2 <= v < 2.0.0",
|
|
||||||
"elm-community/elm-test": "2.0.1 <= v < 3.0.0",
|
|
||||||
"elm-lang/core": "4.0.1 <= v < 5.0.0",
|
|
||||||
"elm-lang/html": "1.0.0 <= v < 2.0.0",
|
|
||||||
"evancz/elm-http": "3.0.1 <= v < 4.0.0",
|
|
||||||
"rtfeldman/html-test-runner": "1.0.0 <= v < 2.0.0",
|
|
||||||
"rtfeldman/node-test-runner": "2.0.0 <= v < 3.0.0"
|
|
||||||
},
|
|
||||||
"elm-version": "0.17.0 <= v < 0.18.0"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user