Start adding templating to configurator.
parent
cc6836b8b6
commit
a1287a485a
|
@ -9,7 +9,10 @@ config :farmbot, data_path: "tmp/"
|
|||
|
||||
# Configure your our system.
|
||||
# Default implementation needs no special stuff.
|
||||
config :farmbot, :init, []
|
||||
config :farmbot, :init, [
|
||||
# DELETEME
|
||||
Farmbot.Bootstrap.Configurator,
|
||||
]
|
||||
|
||||
# Transports.
|
||||
config :farmbot, :transport, [
|
||||
|
|
|
@ -42,7 +42,7 @@ defmodule Farmbot.Bootstrap.Configurator do
|
|||
Logger.info "Building new config."
|
||||
import Supervisor.Spec
|
||||
children = [
|
||||
|
||||
Plug.Adapters.Cowboy.child_spec(:http, Farmbot.Bootstrap.Configurator.Router, [], [port: 4001])
|
||||
]
|
||||
opts = [strategy: :one_for_one]
|
||||
supervise(children, opts)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Farmbot.Bootstrap.Configurator.HTML do
|
||||
@moduledoc """
|
||||
Helpers for HTML parsing and stuff.
|
||||
"""
|
||||
|
||||
@doc "Helper for evaulating a file."
|
||||
def eval_file(file, opts \\ []) do
|
||||
EEx.eval_file("#{:code.priv_dir(:farmbot)}/templates/#{file}.html.eex", opts)
|
||||
end
|
||||
|
||||
@doc "Render a page in the `priv/templates/page` dir."
|
||||
def render(page) do
|
||||
eval_file("page", [page: page, render: fn -> eval_file("page/#{page}") end])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
defmodule Farmbot.Bootstrap.Configurator.Router do
|
||||
@moduledoc "Routes web connections."
|
||||
|
||||
use Plug.Router
|
||||
|
||||
plug Plug.Static, from: {:farmbot, "priv/static"}, at: "/static"
|
||||
plug :match
|
||||
plug :dispatch
|
||||
|
||||
import Farmbot.Bootstrap.Configurator.HTML
|
||||
|
||||
get "/" do
|
||||
conn |> send_resp(200, render("index"))
|
||||
end
|
||||
|
||||
match _ do
|
||||
send_resp(conn, 404, "oops")
|
||||
end
|
||||
end
|
3
mix.exs
3
mix.exs
|
@ -83,6 +83,9 @@ defmodule Farmbot.Mixfile do
|
|||
# {:fs, "~> 0.9.1"},
|
||||
{:nerves_uart, "0.1.2"},
|
||||
{:uuid, "~> 1.1" },
|
||||
|
||||
{:cowboy, "~> 1.0.0"},
|
||||
{:plug, "~> 1.0"},
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [], [], "hexpm"},
|
||||
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [], [], "hexpm"},
|
||||
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [], [], "hexpm"},
|
||||
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [], [{:cowlib, "~> 1.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [], [], "hexpm"},
|
||||
"credo": {:hex, :credo, "0.8.6", "335f723772d35da499b5ebfdaf6b426bfb73590b6fcbc8908d476b75f8cbca3f", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"distillery": {:hex, :distillery, "1.5.1", "7ad7354214959c0f65f57ddd49478c81c3b2733ca2e5ccfb9eb55351108466aa", [], [], "hexpm"},
|
||||
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [], [], "hexpm"},
|
||||
|
@ -18,11 +20,14 @@
|
|||
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [], [], "hexpm"},
|
||||
"meck": {:hex, :meck, "0.8.8", "eeb3efe811d4346e1a7f65b2738abc2ad73cbe1a2c91b5dd909bac2ea0414fa6", [], [], "hexpm"},
|
||||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], [], "hexpm"},
|
||||
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [], [], "hexpm"},
|
||||
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
|
||||
"mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves": {:hex, :nerves, "0.7.5", "3aa6a336b2ad6c1c9589cc2b577511b3c4c375c1ba6c533ab9f88adb8c21f0c3", [], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"nerves_uart": {:hex, :nerves_uart, "0.1.2", "4310dbb1721a5a007b8e5c416cf81754415bde6b7e2c9aa65a059886b85e637c", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [], [], "hexpm"},
|
||||
"ranch": {:hex, :ranch, "1.4.0", "10272f95da79340fa7e8774ba7930b901713d272905d0012b06ca6d994f8826b", [], [], "hexpm"},
|
||||
"rsa": {:hex, :rsa, "0.0.1", "a63069f88ce342ffdf8448b7cdef4b39ba7dee3c1510644a39385c7e63ba246f", [], [], "hexpm"},
|
||||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [], [], "hexpm"},
|
||||
"timex": {:hex, :timex, "3.1.24", "d198ae9783ac807721cca0c5535384ebdf99da4976be8cefb9665a9262a1e9e3", [], [{:combine, "~> 0.7", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>
|
||||
Configure your Farmbot! - <%= page %>
|
||||
</title>
|
||||
</head>
|
||||
<div id=<%= page %>>
|
||||
<%= render.() %>
|
||||
</div>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
whoops
|
Loading…
Reference in New Issue