Skip to content

Commit 32342b9

Browse files
committed
updating todo example
1 parent c267869 commit 32342b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+586
-632
lines changed

.babelrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
{
3+
"presets": [
4+
["env", {
5+
"targets": {
6+
"chrome": 52
7+
},
8+
"modules": "commonjs",
9+
"loose": true
10+
}]
11+
]
12+
}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/deps
55
/*.ez
66

7-
# Generate on crash by the VM
7+
# Generated on crash by the VM
88
erl_crash.dump
99

1010
# Static artifacts
@@ -22,3 +22,4 @@ erl_crash.dump
2222
# secrets file as long as you replace its contents by environment
2323
# variables.
2424
/config/prod.secret.exs
25+
web/static/js/build/

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Todo
22

3-
A Todo app built using Elixirscript.
4-
5-
63
To start your Phoenix app:
74

85
* Install dependencies with `mix deps.get`
9-
* Create and migrate your database with `mix ecto.create && mix ecto.migrate`
106
* Install Node.js dependencies with `npm install`
117
* Start Phoenix endpoint with `mix phoenix.server`
128

139
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
10+
11+
Ready to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).
12+
13+
## Learn more
14+
15+
* Official website: http://www.phoenixframework.org/
16+
* Guides: http://phoenixframework.org/docs/overview
17+
* Docs: https://hexdocs.pm/phoenix
18+
* Mailing list: http://groups.google.com/group/phoenix-talk
19+
* Source: https://github.com/phoenixframework/phoenix

brunch-config.js

+20-37
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,57 @@ exports.config = {
22
// See http://brunch.io/#documentation for docs.
33
files: {
44
javascripts: {
5-
joinTo: "js/app.js"
6-
75
// To use a separate vendor.js bundle, specify two files path
8-
// https://github.com/brunch/brunch/blob/stable/docs/config.md#files
6+
// http://brunch.io/docs/config#-files-
97
// joinTo: {
108
// "js/app.js": /^(web\/static\/js)/,
119
// "js/vendor.js": /^(web\/static\/vendor)|(deps)/
1210
// }
1311
//
1412
// To change the order of concatenation of files, explicitly mention here
15-
// https://github.com/brunch/brunch/tree/master/docs#concatenation
1613
// order: {
1714
// before: [
1815
// "web/static/vendor/js/jquery-2.1.1.js",
1916
// "web/static/vendor/js/bootstrap.min.js"
2017
// ]
2118
// }
19+
joinTo: 'js/app.js',
2220
},
2321
stylesheets: {
24-
joinTo: "css/app.css"
22+
joinTo: 'css/app.css',
23+
order: {
24+
// concat app.css last
25+
after: [ 'web/static/css/app.css' ],
26+
},
2527
},
26-
templates: {
27-
joinTo: "js/app.js"
28-
}
28+
templates: { joinTo: 'js/app.js' },
2929
},
30-
3130
conventions: {
3231
// This option sets where we should place non-css and non-js assets in.
3332
// By default, we set this to "/web/static/assets". Files in this directory
3433
// will be copied to `paths.public`, which is "priv/static" by default.
35-
assets: /^(web\/static\/assets)/
34+
assets: /^(web\/static\/assets)/,
3635
},
37-
3836
// Phoenix paths configuration
3937
paths: {
4038
// Dependencies and current project directories to watch
41-
watched: [
42-
"web/static",
43-
"test/static"
44-
],
45-
39+
watched: [ 'web/static', 'test/static' ],
4640
// Where to compile files to
47-
public: "priv/static"
41+
public: 'priv/static',
4842
},
49-
5043
// Configure your plugins
5144
plugins: {
5245
babel: {
46+
presets: [
47+
[
48+
'env',
49+
{ targets: { chrome: 52 }, modules: 'commonjs', loose: true },
50+
],
51+
],
5352
// Do not use ES6 compiler in vendor code
54-
ignore: [/web\/static\/vendor/]
53+
ignore: [ /web\/static\/vendor/ ],
5554
},
56-
elixirscript: {
57-
inputFolder: "web/static/exjs",
58-
outputFolder: "web/static/js",
59-
mainModule: "Todo"
60-
}
6155
},
62-
63-
modules: {
64-
autoRequire: {
65-
"js/app.js": ["web/static/js/main"]
66-
}
67-
},
68-
69-
npm: {
70-
enabled: true,
71-
// Whitelist the npm deps to be pulled in as front-end assets.
72-
// All other deps in package.json will be excluded from the bundle.
73-
whitelist: ["phoenix", "phoenix_html"]
74-
}
56+
modules: { autoRequire: { 'js/app.js': [ 'web/static/js/app' ] } },
57+
npm: { enabled: true },
7558
};

config/config.exs

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use Mix.Config
88
# Configures the endpoint
99
config :todo, Todo.Endpoint,
1010
url: [host: "localhost"],
11-
root: Path.dirname(__DIR__),
12-
secret_key_base: "iyanJp73OeHaopWgaSRc3dazQENLfmMw6/+gy7QGjAoLqE17fKBSJskQPFPs8Fbr",
13-
render_errors: [accepts: ~w(html json)],
11+
secret_key_base: "DSFpJTbLbzxovpyVZ0kynrtvPaeCpZHgWL9Dh7GRDZC6adtg4+7g7D52/uN1zpR+",
12+
render_errors: [view: Todo.ErrorView, accepts: ~w(html json)],
1413
pubsub: [name: Todo.PubSub,
1514
adapter: Phoenix.PubSub.PG2]
1615

@@ -22,8 +21,3 @@ config :logger, :console,
2221
# Import environment specific config. This must remain at the bottom
2322
# of this file so it overrides the configuration defined above.
2423
import_config "#{Mix.env}.exs"
25-
26-
# Configure phoenix generators
27-
config :phoenix, :generators,
28-
migration: true,
29-
binary_id: false

config/dev.exs

+5-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ config :todo, Todo.Endpoint,
1111
debug_errors: true,
1212
code_reloader: true,
1313
check_origin: false,
14-
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin"]]
14+
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
15+
cd: Path.expand("../", __DIR__)], mix: ["elixirscript.watch"]]
16+
1517

1618
# Watch static and templates for browser reloading.
1719
config :todo, Todo.Endpoint,
@@ -27,16 +29,6 @@ config :todo, Todo.Endpoint,
2729
# Do not include metadata nor timestamps in development logs
2830
config :logger, :console, format: "[$level] $message\n"
2931

30-
# Set a higher stacktrace during development.
31-
# Do not configure such in production as keeping
32-
# and calculating stacktraces is usually expensive.
32+
# Set a higher stacktrace during development. Avoid configuring such
33+
# in production as building large stacktraces may be expensive.
3334
config :phoenix, :stacktrace_depth, 20
34-
35-
# Configure your database
36-
config :todo, Todo.Repo,
37-
adapter: Ecto.Adapters.Postgres,
38-
username: "postgres",
39-
password: "postgres",
40-
database: "todo_dev",
41-
hostname: "localhost",
42-
pool_size: 10

config/prod.exs

-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ config :logger, level: :info
5555
#
5656
# config :todo, Todo.Endpoint, server: true
5757
#
58-
# You will also need to set the application root to `.` in order
59-
# for the new static assets to be served after a hot upgrade:
60-
#
61-
# config :todo, Todo.Endpoint, root: "."
6258

6359
# Finally import the config/prod.secret.exs
6460
# which should be versioned separately.

config/test.exs

-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,3 @@ config :todo, Todo.Endpoint,
88

99
# Print only warnings and errors during test
1010
config :logger, level: :warn
11-
12-
# Configure your database
13-
config :todo, Todo.Repo,
14-
adapter: Ecto.Adapters.Postgres,
15-
username: "postgres",
16-
password: "postgres",
17-
database: "todo_test",
18-
hostname: "localhost",
19-
pool: Ecto.Adapters.SQL.Sandbox
File renamed without changes.

lib/todo.ex

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ defmodule Todo do
44
# See http://elixir-lang.org/docs/stable/elixir/Application.html
55
# for more information on OTP Applications
66
def start(_type, _args) do
7-
import Supervisor.Spec, warn: false
7+
import Supervisor.Spec
88

9+
# Define workers and child supervisors to be supervised
910
children = [
1011
# Start the endpoint when the application starts
1112
supervisor(Todo.Endpoint, []),
12-
# Start the Ecto repository
13-
supervisor(Todo.Repo, []),
14-
worker(Todo.Store, []),
15-
# Here you could define other workers and supervisors as children
13+
worker(Todo.Store, [])
14+
# Start your own worker by calling: Todo.Worker.start_link(arg1, arg2, arg3)
1615
# worker(Todo.Worker, [arg1, arg2, arg3]),
1716
]
1817

lib/todo/endpoint.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ defmodule Todo.Endpoint do
3030
plug Plug.MethodOverride
3131
plug Plug.Head
3232

33+
# The session will be stored in the cookie and signed,
34+
# this means its contents can be read but not tampered with.
35+
# Set :encryption_salt if you would also like to encrypt it.
3336
plug Plug.Session,
3437
store: :cookie,
3538
key: "_todo_key",
36-
signing_salt: "CAuLmP0F"
39+
signing_salt: "8ZOUykEx"
3740

3841
plug Todo.Router
3942
end

lib/todo/repo.ex

-3
This file was deleted.

lib/todo/store.ex

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ defmodule Todo.Store do
55
end
66

77
def list() do
8-
Agent.get(__MODULE__, fn(state) ->
9-
Enum.map(Dict.to_list(state), fn({key, value}) ->
10-
value
11-
end)
8+
Agent.get(__MODULE__, fn(state) ->
9+
Enum.map(Dict.to_list(state), fn({key, value}) ->
10+
value
11+
end)
1212
end)
1313
end
1414

@@ -38,5 +38,5 @@ defmodule Todo.Store do
3838
end
3939
end)
4040
end
41-
41+
4242
end

mix.exs

+14-23
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ defmodule Todo.Mixfile do
44
def project do
55
[app: :todo,
66
version: "0.0.1",
7-
elixir: "~> 1.0",
7+
elixir: "~> 1.2",
88
elixirc_paths: elixirc_paths(Mix.env),
9-
compilers: [:phoenix, :gettext] ++ Mix.compilers,
9+
compilers: [:phoenix, :gettext, :elixir_script] ++ Mix.compilers,
1010
build_embedded: Mix.env == :prod,
1111
start_permanent: Mix.env == :prod,
12-
aliases: aliases,
13-
deps: deps]
12+
deps: deps(),
13+
elixir_script: [ input: ["web/static/exjs", "lib/shared"], output: "web/static/js/build" ]
14+
]
1415
end
1516

1617
# Configuration for the OTP application.
1718
#
1819
# Type `mix help compile.app` for more information.
1920
def application do
2021
[mod: {Todo, []},
21-
applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext,
22-
:phoenix_ecto, :postgrex]]
22+
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext]]
2323
end
2424

2525
# Specifies which paths to compile per environment.
@@ -30,23 +30,14 @@ defmodule Todo.Mixfile do
3030
#
3131
# Type `mix help deps` for examples and options.
3232
defp deps do
33-
[{:phoenix, "~> 1.1.4"},
34-
{:postgrex, ">= 0.0.0"},
35-
{:phoenix_ecto, "~> 2.0"},
36-
{:phoenix_html, "~> 2.4"},
33+
[{:phoenix, "~> 1.2.1"},
34+
{:phoenix_pubsub, "~> 1.0"},
35+
{:phoenix_html, "~> 2.6"},
3736
{:phoenix_live_reload, "~> 1.0", only: :dev},
38-
{:gettext, "~> 0.9"},
39-
{:cowboy, "~> 1.0"}]
40-
end
41-
42-
# Aliases are shortcut or tasks specific to the current project.
43-
# For example, to create, migrate and run the seeds file at once:
44-
#
45-
# $ mix ecto.setup
46-
#
47-
# See the documentation for `Mix` for more info on aliases.
48-
defp aliases do
49-
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
50-
"ecto.reset": ["ecto.drop", "ecto.setup"]]
37+
{:gettext, "~> 0.11"},
38+
{:cowboy, "~> 1.0"},
39+
{:elixir_script, "~> 0.24.0"},
40+
{:fs, "2.12.0", override: true}
41+
]
5142
end
5243
end

mix.lock

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
%{"connection": {:hex, :connection, "1.0.2"},
2-
"cowboy": {:hex, :cowboy, "1.0.4"},
3-
"cowlib": {:hex, :cowlib, "1.0.2"},
4-
"db_connection": {:hex, :db_connection, "0.2.3"},
5-
"decimal": {:hex, :decimal, "1.1.1"},
6-
"ecto": {:hex, :ecto, "1.1.3"},
7-
"fs": {:hex, :fs, "0.9.2"},
8-
"gettext": {:hex, :gettext, "0.9.0"},
9-
"phoenix": {:hex, :phoenix, "1.1.4"},
10-
"phoenix_ecto": {:hex, :phoenix_ecto, "2.0.1"},
11-
"phoenix_html": {:hex, :phoenix_html, "2.5.0"},
12-
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.3"},
13-
"plug": {:hex, :plug, "1.1.1"},
14-
"poison": {:hex, :poison, "1.5.2"},
15-
"poolboy": {:hex, :poolboy, "1.5.1"},
16-
"postgrex": {:hex, :postgrex, "0.11.1"},
17-
"ranch": {:hex, :ranch, "1.2.1"}}
1+
%{"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:make, :rebar], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]},
2+
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []},
3+
"elixir_script": {:hex, :elixir_script, "0.24.0", "cb4d827a3082984f317ff8c30d61b839e0c5b8c5d44c63ce881ae2ce5aa1691d", [:mix], [{:estree, "~> 2.5", [hex: :estree, optional: false]}, {:fs, "~> 0.9.1", [hex: :fs, optional: false]}]},
4+
"estree": {:hex, :estree, "2.5.0", "9776c1705a72dc5a0d56cdf431173c3e75f9e509278a857ec55374a49f5699ef", [:mix], []},
5+
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []},
6+
"gettext": {:hex, :gettext, "0.13.0", "daafbddc5cda12738bb93b01d84105fe75b916a302f1c50ab9fb066b95ec9db4", [:mix], []},
7+
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []},
8+
"phoenix": {:hex, :phoenix, "1.2.1", "6dc592249ab73c67575769765b66ad164ad25d83defa3492dc6ae269bd2a68ab", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.1", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
9+
"phoenix_html": {:hex, :phoenix_html, "2.9.2", "371160b30cf4e10443b015efce6f03e1f19aae98ff6487620477b13a5b2ef660", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
10+
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.7", "167ab0942e88d1d4a597996cf7dd8d2b014cc14d3f9472b58858cde8dd9ac2e4", [:mix], [{:fs, "~> 2.12.0", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]},
11+
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.1", "c10ddf6237007c804bf2b8f3c4d5b99009b42eca3a0dfac04ea2d8001186056a", [:mix], []},
12+
"plug": {:hex, :plug, "1.3.0", "6e2b01afc5db3fd011ca4a16efd9cb424528c157c30a44a0186bcc92c7b2e8f3", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
13+
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
14+
"ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []}}

0 commit comments

Comments
 (0)