diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..16fac6c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# editorconfig.org +# from https://devhints.io/editorconfig +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/README.md b/README.md index d786c67..9a4737e 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,70 @@ # Hello -To start your Phoenix app: +To start your Phoenix server: * Install dependencies with `mix deps.get` - * Create and migrate your database with `mix ecto.create && mix ecto.migrate` - * Install Node.js dependencies with `npm install` - * Start Phoenix endpoint with `mix phoenix.server` + * Create and migrate your database with `mix ecto.setup` + * Install Node.js dependencies with `npm install` inside the `assets` directory + * Start Phoenix endpoint with `mix phx.server` Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. -Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment). +Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). ## Learn more - * Official website: http://www.phoenixframework.org/ - * Guides: http://phoenixframework.org/docs/overview + * Official website: https://www.phoenixframework.org/ + * Guides: https://hexdocs.pm/phoenix/overview.html * Docs: https://hexdocs.pm/phoenix - * Mailing list: http://groups.google.com/group/phoenix-talk + * Forum: https://elixirforum.com/c/phoenix-forum * Source: https://github.com/phoenixframework/phoenix + +## Phoenix Diagram + +A simplified view of a Phoenix Web Application + +``` +connection +|> endpoint +|> router +|> pipelines # typically one for browser requests, another for json/api requests +|> controller +``` + +Controller as pipe chain of functions + +``` +connection +|> controller +|> common_services +|> action +``` + +``` +connection # Plug.Conn +|> endpoint # lib/hello/endpoint.ex +|> browser # web/router.ex +|> HelloController.world # web/controllers/hello_controller.ex +|> HelloView.render( # web/views/hello_view.ex + "world.html") # web/templates/hello/world.html.eex +``` + +> Plugs are functions. Your web applications are pipelines of plugs. + +## Commands + +initial setup + +```bash +$ mix phoenix.new . --app hello +$ mix ecto.create +$ mix phoenix.server +``` + +## Editor + +![](./editor.png) + +## Browser + +![](./browser.png) diff --git a/browser.png b/browser.png new file mode 100644 index 0000000..59b65e1 Binary files /dev/null and b/browser.png differ diff --git a/editor.png b/editor.png new file mode 100644 index 0000000..d046fe2 Binary files /dev/null and b/editor.png differ diff --git a/notes.md b/notes.md index 0f38394..b862d56 100644 --- a/notes.md +++ b/notes.md @@ -63,3 +63,10 @@ $ dc up ``` visit + +open interactive elixir (iex) and load the `mix phoenix.server` script + +```bash +$ dc run app \ + iex -S mix phoenix.server +``` diff --git a/web/controllers/hello_controller.ex b/web/controllers/hello_controller.ex new file mode 100644 index 0000000..e7afc39 --- /dev/null +++ b/web/controllers/hello_controller.ex @@ -0,0 +1,7 @@ +defmodule Hello.HelloController do + use Hello.Web, :controller + + def world(conn, %{"name" => name}) do + render conn, "world.html", name: name + end +end diff --git a/web/router.ex b/web/router.ex index e7a505b..f1f7f5b 100644 --- a/web/router.ex +++ b/web/router.ex @@ -16,6 +16,7 @@ defmodule Hello.Router do scope "/", Hello do pipe_through :browser # Use the default browser stack + get "/hello/:name", HelloController, :world get "/", PageController, :index end diff --git a/web/templates/hello/world.html.eex b/web/templates/hello/world.html.eex new file mode 100644 index 0000000..aa74c8c --- /dev/null +++ b/web/templates/hello/world.html.eex @@ -0,0 +1,4 @@ +

+ From template: Hello, + <%= String.capitalize(@name) %>! +

\ No newline at end of file diff --git a/web/views/hello_view.ex b/web/views/hello_view.ex new file mode 100644 index 0000000..c675a76 --- /dev/null +++ b/web/views/hello_view.ex @@ -0,0 +1,3 @@ +defmodule Hello.HelloView do + use Hello.Web, :view +end \ No newline at end of file