move morse to seperate module

This commit is contained in:
Pim Kunis 2019-07-14 15:05:45 +02:00
parent b93d48920a
commit cbec08aae8
11 changed files with 98 additions and 12 deletions

4
morse/.formatter.exs Normal file
View file

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

24
morse/.gitignore vendored Normal file
View file

@ -0,0 +1,24 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
morse-*.tar

21
morse/README.md Normal file
View file

@ -0,0 +1,21 @@
# Morse
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `morse` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:morse, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/morse](https://hexdocs.pm/morse).

13
morse/lib/morse.ex Normal file
View file

@ -0,0 +1,13 @@
defmodule Morse do
@moduledoc """
Functions to control the signal lamp connected with GPIO.
"""
@doc """
Takes a string composed of dots and dashes, and signals them with the
signal lamp.
"""
def signal(msg) do
IO.puts(msg)
end
end

28
morse/mix.exs Normal file
View file

@ -0,0 +1,28 @@
defmodule Morse.MixProject do
use Mix.Project
def project do
[
app: :morse,
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end

View file

@ -0,0 +1,4 @@
defmodule MorseTest do
use ExUnit.Case
doctest Morse
end

View file

@ -0,0 +1 @@
ExUnit.start()

View file

@ -1,5 +0,0 @@
defmodule Ui.SignalMorse do
def signal do
IO.puts("bleep bloop")
end
end

View file

@ -22,7 +22,7 @@ defmodule UiWeb.PageController do
case get_start_time() do case get_start_time() do
start_time when start_time + 35 <= now -> start_time when start_time + 35 <= now ->
System.put_env("MORSE_START_TIME", Integer.to_string(now)) System.put_env("MORSE_START_TIME", Integer.to_string(now))
Ui.SignalMorse.signal() Morse.signal("...---...")
text(conn, "Done.") text(conn, "Done.")
_ -> _ ->
text(conn, "It is still in progress...") text(conn, "It is still in progress...")

View file

@ -38,7 +38,8 @@ defmodule Ui.MixProject do
{:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_reload, "~> 1.2", only: :dev},
{:gettext, "~> 0.11"}, {:gettext, "~> 0.11"},
{:jason, "~> 1.0"}, {:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"} {:plug_cowboy, "~> 2.0"},
{:morse, path: "../morse"}
] ]
end end
end end

View file

@ -1,8 +1,3 @@
defmodule UiWeb.PageControllerTest do defmodule UiWeb.PageControllerTest do
use UiWeb.ConnCase use UiWeb.ConnCase
test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end end