From a16cf2d34f420ba8366accb3217727e746ddd474 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 25 Apr 2016 17:15:22 -0400 Subject: [PATCH] Initial commit --- .gitignore | 17 +++++ README.md | 14 ++++ priv/.gitignore | 2 + priv/elm-package.json | 19 ++++++ priv/src/App.elm | 128 +++++++++++++++++++++++++++++++++++++ rebar.config | 32 ++++++++++ src/elmdap-app.lfe | 22 +++++++ src/elmdap-sup.lfe | 30 +++++++++ src/elmdap.app.src | 16 +++++ src/elmdap.lfe | 4 ++ test/unit-elmdap-tests.lfe | 12 ++++ 11 files changed, 296 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 priv/.gitignore create mode 100644 priv/elm-package.json create mode 100644 priv/src/App.elm create mode 100644 rebar.config create mode 100644 src/elmdap-app.lfe create mode 100644 src/elmdap-sup.lfe create mode 100644 src/elmdap.app.src create mode 100644 src/elmdap.lfe create mode 100644 test/unit-elmdap-tests.lfe diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..203efa2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +.rebar3 +rebar3 +_* +.eunit +*.o +*.beam +*.plt +.erlang.cookie +ebin +log +erl_crash.dump +.rebar +_rel +_deps +_plugins +_tdeps +logs diff --git a/README.md b/README.md new file mode 100644 index 0000000..f492bbf --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +elmdap +========== + +An LFE application + +## Build +``` +$ rebar3 lfe release +``` + +## Test +``` +$ rebar3 lfe test +``` diff --git a/priv/.gitignore b/priv/.gitignore new file mode 100644 index 0000000..0c3f49a --- /dev/null +++ b/priv/.gitignore @@ -0,0 +1,2 @@ +elm-stuff/ +elm.js diff --git a/priv/elm-package.json b/priv/elm-package.json new file mode 100644 index 0000000..9b01f81 --- /dev/null +++ b/priv/elm-package.json @@ -0,0 +1,19 @@ +{ + "version": "1.0.0", + "summary": "helpful summary of your project, less than 80 characters", + "repository": "https://github.com/user/project.git", + "license": "BSD3", + "source-directories": [ + "src" + ], + "exposed-modules": [], + "dependencies": { + "debois/elm-mdl": "2.1.3 <= v < 3.0.0", + "elm-lang/core": "3.0.0 <= v < 4.0.0", + "evancz/elm-effects": "2.0.1 <= v < 3.0.0", + "evancz/elm-html": "4.0.2 <= v < 5.0.0", + "evancz/elm-http": "3.0.0 <= v < 4.0.0", + "evancz/start-app": "2.0.2 <= v < 3.0.0" + }, + "elm-version": "0.16.0 <= v < 0.17.0" +} \ No newline at end of file diff --git a/priv/src/App.elm b/priv/src/App.elm new file mode 100644 index 0000000..059a409 --- /dev/null +++ b/priv/src/App.elm @@ -0,0 +1,128 @@ +module App (main) where + +import StartApp +import Effects exposing (Effects, Never) +import Task exposing (Task) +import Html exposing (Html) +import Http +import Material +import Material.Color as Color +import Material.Layout as Layout exposing (defaultLayoutModel) +import Material.Scheme as Scheme +import Material.Textfield as Textfield +import Material.Button as Button + + +type alias Model = + { uid : String + , password : String + , authenticated : Bool + , mdl : Material.Model + } + + +type Action + = UpdateUID String + | UpdatePassword String + | Authenticate + | AuthenticationResponse (Result Http.Error Bool) + | MDL (Material.Action Action) + | LayoutAction Layout.Action + + +init : ( Model, Effects Action ) +init = + ( { uid = "" + , password = "" + , authenticated = False + , mdl = Material.model + } + , Effects.none + ) + + +update : Action -> Model -> ( Model, Effects Action ) +update action model = + case action of + MDL action' -> + let + ( mdl', fx ) = + Material.update MDL action' model.mdl + in + ( { model | mdl = mdl' }, fx ) + + _ -> + ( model, Effects.none ) + + +uidInput : Textfield.Instance Material.Model Action +uidInput = + let + model = + Textfield.model + in + Textfield.instance + 0 + MDL + { model | label = Just { text = "User ID", float = True } } + [ Textfield.fwdInput UpdateUID ] + + +passwordInput : Textfield.Instance Material.Model Action +passwordInput = + let + model = + Textfield.model + in + Textfield.instance + 1 + MDL + { model | label = Just { text = "Password", float = True } } + [ Textfield.fwdInput UpdatePassword ] + + +submitButton : Button.Instance Material.Model Action +submitButton = + Button.instance + 0 + MDL + Button.raised + (Button.model True) + [ Button.fwdClick Authenticate ] + + +view : Signal.Address Action -> Model -> Html +view address model = + Layout.view + (Signal.forwardTo address LayoutAction) + defaultLayoutModel + { header = [] + , drawer = [] + , tabs = [] + , main = + [ Html.h1 [] [ Html.text "Log In" ] + , Html.div [] [ uidInput.view address model.mdl [] ] + , Html.div [] [ passwordInput.view address model.mdl [] ] + , Html.div [] [ submitButton.view address model.mdl [ Button.colored ] [ Html.text "Log In" ] ] + ] + } + + +app : StartApp.App Model +app = + StartApp.start + { init = init + , view = view + , update = update + , inputs = [ Layout.setupSignals LayoutAction ] + } + + +main : Signal Html +main = + Signal.map (Scheme.topWithScheme Color.Teal Color.Red) app.html + + +port tasks : Signal (Task.Task Never ()) +port tasks = + app.tasks diff --git a/rebar.config b/rebar.config new file mode 100644 index 0000000..ad16bbd --- /dev/null +++ b/rebar.config @@ -0,0 +1,32 @@ +{erl_opts, [debug_info]}. +{lfe_first_files, []}. + +{deps, [ + {lfe, {git, "git://github.com/rvirding/lfe", {tag, "1.0"}}} +]}. + +{plugins, [ + {'lfe-compile', {git, "https://github.com/lfe-rebar3/compile.git", {tag, "0.3.0"}}} +]}. + +{provider_hooks, [ + {pre, [{compile, {lfe, compile}}]} +]}. + +{profiles, [ + {dev, [ + {plugins, [ + {'lfe-version', ".*", {git, "https://github.com/lfe-rebar3/version.git", {tag, "0.3.0"}}}, + {'lfe-repl', ".*", {git, "https://github.com/lfe-rebar3/repl.git", {tag, "0.2.0"}}}, + {'lfe-clean', ".*", {git, "https://github.com/lfe-rebar3/clean.git", {tag, "0.2.0"}}} + ]} + ]}, + + {test, [ + {eunit_compile_opts, [ + {src_dirs, ["test", "src"]} + ]}, + {deps, [ + {ltest, ".*", {git, "git://github.com/lfex/ltest.git", {tag, "0.8.0"}}}]} + ]} + ]}. diff --git a/src/elmdap-app.lfe b/src/elmdap-app.lfe new file mode 100644 index 0000000..258890b --- /dev/null +++ b/src/elmdap-app.lfe @@ -0,0 +1,22 @@ +#| +@doc + elmdap public API +@end +|# + +(defmodule elmdap-app + (behaviour application) + + ;; Application callbacks + (export (start 2) + (stop 1))) + +;;; API + +(defun start (_type _args) + (elmdap-sup:start_link)) + +(defun stop (_state) + 'ok) + +;;; Internal functions diff --git a/src/elmdap-sup.lfe b/src/elmdap-sup.lfe new file mode 100644 index 0000000..f693a3c --- /dev/null +++ b/src/elmdap-sup.lfe @@ -0,0 +1,30 @@ +#| +@doc + elmdap top level supervisor +@end +|# + +(defmodule elmdap-sup + (behaviour supervisor) + + ;; API + (export (start_link 0)) + + ;; Supervisor callbacks + (export (init 1))) + +;;; API functions + +(defun server-name () + 'elmdap-sup) + +(defun start_link () + (supervisor:start_link + `#(local ,(server-name)) (MODULE) '())) + +;;; Supervisor callbacks + +(defun init (_args) + `#(ok #(#(one_for_one 0 1) ()))) + +;;; Internal functions diff --git a/src/elmdap.app.src b/src/elmdap.app.src new file mode 100644 index 0000000..3f9d4f7 --- /dev/null +++ b/src/elmdap.app.src @@ -0,0 +1,16 @@ +{application, 'elmdap', + [{description, "An LFE Application"}, + {vsn, "0.0.1"}, + {registered, []}, + {applications, + [kernel, + stdlib + ]}, + {mod, {'elmdap-app', []}}, + {env, []}, + {modules, []}, + + {contributors, []}, + {licenses, []}, + {links, []} + ]}. diff --git a/src/elmdap.lfe b/src/elmdap.lfe new file mode 100644 index 0000000..f7c5d8a --- /dev/null +++ b/src/elmdap.lfe @@ -0,0 +1,4 @@ +(defmodule elmdap + (export all)) + +;; Public API diff --git a/test/unit-elmdap-tests.lfe b/test/unit-elmdap-tests.lfe new file mode 100644 index 0000000..02485f1 --- /dev/null +++ b/test/unit-elmdap-tests.lfe @@ -0,0 +1,12 @@ +(defmodule unit-elmdap-tests + (behaviour ltest-unit) + (export all) + (import + (from ltest + (check-failed-assert 2) + (check-wrong-assert-exception 2)))) + +(include-lib "ltest/include/ltest-macros.lfe") + +(deftest elmdap-hello-world + (is 'true))