diff --git a/assets/.gitignore b/assets/.gitignore new file mode 100644 index 0000000..07e6e47 --- /dev/null +++ b/assets/.gitignore @@ -0,0 +1 @@ +/node_modules diff --git a/brunch-config.js b/assets/brunch-config.js similarity index 56% rename from brunch-config.js rename to assets/brunch-config.js index 70e3a9a..d138f99 100644 --- a/brunch-config.js +++ b/assets/brunch-config.js @@ -14,8 +14,8 @@ exports.config = { // To change the order of concatenation of files, explicitly mention here order: { before: [ - "web/static/vendor/js/jquery-2.2.4.min.js", - "web/static/vendor/js/bootstrap.js" + "vendor/js/jquery-2.2.4.min.js", + "vendor/js/bootstrap.js" ] } }, @@ -23,19 +23,19 @@ exports.config = { joinTo: "css/app.css", order: { before: [ - "web/static/vendor/css/bootstrap.css", - "web/static/css/source-sans-pro.css", - "web/static/css/base.sass", - "web/static/css/header.sass", - "web/static/css/flash.sass", - "web/static/css/footer.sass", - "web/static/css/home.sass", - "web/static/css/asciicasts.sass", - "web/static/css/users.sass", - "web/static/css/preview.sass", - "web/static/css/player.sass", - "web/static/css/contributing.sass", - "web/static/css/simple-layout.sass", + "vendor/css/bootstrap.css", + "css/source-sans-pro.css", + "css/base.sass", + "css/header.sass", + "css/flash.sass", + "css/footer.sass", + "css/home.sass", + "css/asciicasts.sass", + "css/users.sass", + "css/preview.sass", + "css/player.sass", + "css/contributing.sass", + "css/simple-layout.sass", ] } }, @@ -46,34 +46,31 @@ exports.config = { conventions: { // This option sets where we should place non-css and non-js assets in. - // By default, we set this to "/web/static/assets". Files in this directory + // By default, we set this to "/assets/static". Files in this directory // will be copied to `paths.public`, which is "priv/static" by default. - assets: /^(web\/static\/assets)/ + assets: /^(static)/ }, // Phoenix paths configuration paths: { // Dependencies and current project directories to watch - watched: [ - "web/static", - "test/static" - ], + watched: ["static", "css", "js", "vendor"], // Where to compile files to - public: "priv/static" + public: "../priv/static" }, // Configure your plugins plugins: { babel: { // Do not use ES6 compiler in vendor code - ignore: [/web\/static\/vendor/] + ignore: [/vendor/] } }, modules: { autoRequire: { - "js/app.js": ["web/static/js/app"] + "js/app.js": ["js/app"] } }, diff --git a/web/static/css/asciicasts.sass b/assets/css/asciicasts.sass similarity index 100% rename from web/static/css/asciicasts.sass rename to assets/css/asciicasts.sass diff --git a/web/static/css/base.sass b/assets/css/base.sass similarity index 100% rename from web/static/css/base.sass rename to assets/css/base.sass diff --git a/web/static/css/contributing.sass b/assets/css/contributing.sass similarity index 100% rename from web/static/css/contributing.sass rename to assets/css/contributing.sass diff --git a/web/static/css/flash.sass b/assets/css/flash.sass similarity index 100% rename from web/static/css/flash.sass rename to assets/css/flash.sass diff --git a/web/static/css/footer.sass b/assets/css/footer.sass similarity index 100% rename from web/static/css/footer.sass rename to assets/css/footer.sass diff --git a/web/static/css/header.sass b/assets/css/header.sass similarity index 100% rename from web/static/css/header.sass rename to assets/css/header.sass diff --git a/web/static/css/home.sass b/assets/css/home.sass similarity index 100% rename from web/static/css/home.sass rename to assets/css/home.sass diff --git a/web/static/css/player.sass b/assets/css/player.sass similarity index 100% rename from web/static/css/player.sass rename to assets/css/player.sass diff --git a/web/static/css/preview.sass b/assets/css/preview.sass similarity index 100% rename from web/static/css/preview.sass rename to assets/css/preview.sass diff --git a/web/static/css/simple-layout.sass b/assets/css/simple-layout.sass similarity index 100% rename from web/static/css/simple-layout.sass rename to assets/css/simple-layout.sass diff --git a/web/static/css/source-sans-pro.css b/assets/css/source-sans-pro.css similarity index 100% rename from web/static/css/source-sans-pro.css rename to assets/css/source-sans-pro.css diff --git a/web/static/css/users.sass b/assets/css/users.sass similarity index 100% rename from web/static/css/users.sass rename to assets/css/users.sass diff --git a/web/static/js/app.js b/assets/js/app.js similarity index 100% rename from web/static/js/app.js rename to assets/js/app.js diff --git a/web/static/js/socket.js b/assets/js/socket.js similarity index 100% rename from web/static/js/socket.js rename to assets/js/socket.js diff --git a/package.json b/assets/package.json similarity index 58% rename from package.json rename to assets/package.json index 86fd5cc..c28a643 100644 --- a/package.json +++ b/assets/package.json @@ -6,16 +6,16 @@ "watch": "brunch watch --stdin" }, "dependencies": { - "phoenix": "file:deps/phoenix", - "phoenix_html": "file:deps/phoenix_html" + "phoenix": "file:../deps/phoenix", + "phoenix_html": "file:../deps/phoenix_html" }, "devDependencies": { - "babel-brunch": "~6.0.0", - "brunch": "2.7.4", - "clean-css-brunch": "~2.0.0", + "babel-brunch": "6.0.6", + "brunch": "2.10.7", + "clean-css-brunch": "2.10.0", "css-brunch": "~2.0.0", "sass-brunch": "^2.6.3", "javascript-brunch": "~2.0.0", - "uglify-js-brunch": "~2.0.1" + "uglify-js-brunch": "2.1.1" } } diff --git a/web/static/assets/fonts/SourceSansPro-Bold.ttf b/assets/static/fonts/SourceSansPro-Bold.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-Bold.ttf rename to assets/static/fonts/SourceSansPro-Bold.ttf diff --git a/web/static/assets/fonts/SourceSansPro-BoldItalic.ttf b/assets/static/fonts/SourceSansPro-BoldItalic.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-BoldItalic.ttf rename to assets/static/fonts/SourceSansPro-BoldItalic.ttf diff --git a/web/static/assets/fonts/SourceSansPro-Italic.ttf b/assets/static/fonts/SourceSansPro-Italic.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-Italic.ttf rename to assets/static/fonts/SourceSansPro-Italic.ttf diff --git a/web/static/assets/fonts/SourceSansPro-Light.ttf b/assets/static/fonts/SourceSansPro-Light.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-Light.ttf rename to assets/static/fonts/SourceSansPro-Light.ttf diff --git a/web/static/assets/fonts/SourceSansPro-LightItalic.ttf b/assets/static/fonts/SourceSansPro-LightItalic.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-LightItalic.ttf rename to assets/static/fonts/SourceSansPro-LightItalic.ttf diff --git a/web/static/assets/fonts/SourceSansPro-Regular.ttf b/assets/static/fonts/SourceSansPro-Regular.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-Regular.ttf rename to assets/static/fonts/SourceSansPro-Regular.ttf diff --git a/web/static/assets/fonts/SourceSansPro-Semibold.ttf b/assets/static/fonts/SourceSansPro-Semibold.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-Semibold.ttf rename to assets/static/fonts/SourceSansPro-Semibold.ttf diff --git a/web/static/assets/fonts/SourceSansPro-SemiboldItalic.ttf b/assets/static/fonts/SourceSansPro-SemiboldItalic.ttf similarity index 100% rename from web/static/assets/fonts/SourceSansPro-SemiboldItalic.ttf rename to assets/static/fonts/SourceSansPro-SemiboldItalic.ttf diff --git a/web/static/assets/fonts/glyphicons-halflings-regular.eot b/assets/static/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from web/static/assets/fonts/glyphicons-halflings-regular.eot rename to assets/static/fonts/glyphicons-halflings-regular.eot diff --git a/web/static/assets/fonts/glyphicons-halflings-regular.svg b/assets/static/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from web/static/assets/fonts/glyphicons-halflings-regular.svg rename to assets/static/fonts/glyphicons-halflings-regular.svg diff --git a/web/static/assets/fonts/glyphicons-halflings-regular.ttf b/assets/static/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from web/static/assets/fonts/glyphicons-halflings-regular.ttf rename to assets/static/fonts/glyphicons-halflings-regular.ttf diff --git a/web/static/assets/fonts/glyphicons-halflings-regular.woff b/assets/static/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from web/static/assets/fonts/glyphicons-halflings-regular.woff rename to assets/static/fonts/glyphicons-halflings-regular.woff diff --git a/web/static/assets/images/brightbox.png b/assets/static/images/brightbox.png similarity index 100% rename from web/static/assets/images/brightbox.png rename to assets/static/images/brightbox.png diff --git a/web/static/assets/images/favicon.png b/assets/static/images/favicon.png similarity index 100% rename from web/static/assets/images/favicon.png rename to assets/static/images/favicon.png diff --git a/web/static/assets/images/home-bg.jpg b/assets/static/images/home-bg.jpg similarity index 100% rename from web/static/assets/images/home-bg.jpg rename to assets/static/images/home-bg.jpg diff --git a/web/static/assets/images/logo-red.svg b/assets/static/images/logo-red.svg similarity index 100% rename from web/static/assets/images/logo-red.svg rename to assets/static/images/logo-red.svg diff --git a/web/static/assets/js/embed.js b/assets/static/js/embed.js similarity index 100% rename from web/static/assets/js/embed.js rename to assets/static/js/embed.js diff --git a/web/static/assets/robots.txt b/assets/static/robots.txt similarity index 100% rename from web/static/assets/robots.txt rename to assets/static/robots.txt diff --git a/web/static/vendor/css/bootstrap.css b/assets/vendor/css/bootstrap.css similarity index 100% rename from web/static/vendor/css/bootstrap.css rename to assets/vendor/css/bootstrap.css diff --git a/web/static/vendor/fonts/glyphicons-halflings-regular.eot b/assets/vendor/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from web/static/vendor/fonts/glyphicons-halflings-regular.eot rename to assets/vendor/fonts/glyphicons-halflings-regular.eot diff --git a/web/static/vendor/fonts/glyphicons-halflings-regular.svg b/assets/vendor/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from web/static/vendor/fonts/glyphicons-halflings-regular.svg rename to assets/vendor/fonts/glyphicons-halflings-regular.svg diff --git a/web/static/vendor/fonts/glyphicons-halflings-regular.ttf b/assets/vendor/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from web/static/vendor/fonts/glyphicons-halflings-regular.ttf rename to assets/vendor/fonts/glyphicons-halflings-regular.ttf diff --git a/web/static/vendor/fonts/glyphicons-halflings-regular.woff b/assets/vendor/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from web/static/vendor/fonts/glyphicons-halflings-regular.woff rename to assets/vendor/fonts/glyphicons-halflings-regular.woff diff --git a/web/static/vendor/fonts/glyphicons-halflings-regular.woff2 b/assets/vendor/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from web/static/vendor/fonts/glyphicons-halflings-regular.woff2 rename to assets/vendor/fonts/glyphicons-halflings-regular.woff2 diff --git a/web/static/vendor/js/bootstrap.js b/assets/vendor/js/bootstrap.js similarity index 100% rename from web/static/vendor/js/bootstrap.js rename to assets/vendor/js/bootstrap.js diff --git a/web/static/vendor/js/jquery-2.2.4.min.js b/assets/vendor/js/jquery-2.2.4.min.js similarity index 100% rename from web/static/vendor/js/jquery-2.2.4.min.js rename to assets/vendor/js/jquery-2.2.4.min.js diff --git a/config/config.exs b/config/config.exs index 50014f8..7fa5a76 100644 --- a/config/config.exs +++ b/config/config.exs @@ -10,10 +10,10 @@ config :asciinema, ecto_repos: [Asciinema.Repo] # Configures the endpoint -config :asciinema, Asciinema.Endpoint, +config :asciinema, AsciinemaWeb.Endpoint, url: [host: "localhost"], secret_key_base: System.get_env("SECRET_KEY_BASE"), - render_errors: [view: Asciinema.ErrorView, accepts: ~w(html json)], + render_errors: [view: AsciinemaWeb.ErrorView, accepts: ~w(html json)], pubsub: [name: Asciinema.PubSub, adapter: Phoenix.PubSub.PG2] diff --git a/config/dev.exs b/config/dev.exs index 52b31d9..887f997 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -6,24 +6,24 @@ use Mix.Config # The watchers configuration can be used to run external # watchers to your application. For example, we use it # with brunch.io to recompile .js and .css sources. -config :asciinema, Asciinema.Endpoint, +config :asciinema, AsciinemaWeb.Endpoint, http: [port: 4000], debug_errors: true, code_reloader: true, check_origin: false, secret_key_base: System.get_env("SECRET_KEY_BASE") || "60BnXnzGGwwiZj91YA9XYKF9BCiM7lQ/1um8VXcWWLSdUp9OcPZV6YnQv7eFTYSY", watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin", - cd: Path.expand("../", __DIR__)]] + cd: Path.expand("../assets", __DIR__)]] # Watch static and templates for browser reloading. -config :asciinema, Asciinema.Endpoint, +config :asciinema, AsciinemaWeb.Endpoint, live_reload: [ patterns: [ ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, ~r{priv/gettext/.*(po)$}, - ~r{web/views/.*(ex)$}, - ~r{web/templates/.*(eex|md)$} + ~r{lib/asciinema_web/views/.*(ex)$}, + ~r{lib/asciinema_web/templates/.*(eex|md)$} ] ] diff --git a/config/prod.exs b/config/prod.exs index fd7edd3..711c48d 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -11,7 +11,7 @@ use Mix.Config # containing the digested version of static files. This # manifest is generated by the mix phoenix.digest task # which you typically run after static files are built. -config :asciinema, Asciinema.Endpoint, +config :asciinema, AsciinemaWeb.Endpoint, http: [port: {:system, "PORT"}], url: [scheme: System.get_env("URL_SCHEME") || "https", host: System.get_env("URL_HOST") || "asciinema.org", @@ -26,7 +26,7 @@ config :logger, level: :info # To get SSL working, you will need to add the `https` key # to the previous section and set your `:url` port to 443: # -# config :asciinema, Asciinema.Endpoint, +# config :asciinema, AsciinemaWeb.Endpoint, # ... # url: [host: "example.com", port: 443], # https: [port: 443, @@ -40,7 +40,7 @@ config :logger, level: :info # We also recommend setting `force_ssl`, ensuring no data is # ever sent via http, always redirecting to https: # -# config :asciinema, Asciinema.Endpoint, +# config :asciinema, AsciinemaWeb.Endpoint, # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. @@ -55,7 +55,7 @@ config :logger, level: :info # Alternatively, you can configure exactly which server to # start per endpoint: # -# config :asciinema, Asciinema.Endpoint, server: true +# config :asciinema, AsciinemaWeb.Endpoint, server: true # config :asciinema, Asciinema.Repo, diff --git a/config/test.exs b/config/test.exs index 59a7ff1..1f23027 100644 --- a/config/test.exs +++ b/config/test.exs @@ -2,7 +2,7 @@ use Mix.Config # We don't run a server during test. If one is required, # you can enable the server option below. -config :asciinema, Asciinema.Endpoint, +config :asciinema, AsciinemaWeb.Endpoint, http: [port: 4001], secret_key_base: "ssecretkeybasesecretkeybasesecretkeybasesecretkeybaseecretkeybase", server: false diff --git a/lib/asciinema.ex b/lib/asciinema/application.ex similarity index 78% rename from lib/asciinema.ex rename to lib/asciinema/application.ex index bcf5362..c9081f0 100644 --- a/lib/asciinema.ex +++ b/lib/asciinema/application.ex @@ -1,4 +1,4 @@ -defmodule Asciinema do +defmodule Asciinema.Application do use Application # See http://elixir-lang.org/docs/stable/elixir/Application.html @@ -13,7 +13,7 @@ defmodule Asciinema do # Start the Ecto repository supervisor(Asciinema.Repo, []), # Start the endpoint when the application starts - supervisor(Asciinema.Endpoint, []), + supervisor(AsciinemaWeb.Endpoint, []), # Start your own worker by calling: Asciinema.Worker.start_link(arg1, arg2, arg3) # worker(Asciinema.Worker, [arg1, arg2, arg3]), :poolboy.child_spec(:worker, Asciinema.PngGenerator.A2png.poolboy_config(), []), @@ -27,11 +27,4 @@ defmodule Asciinema do opts = [strategy: :one_for_one, name: Asciinema.Supervisor] Supervisor.start_link(children, opts) end - - # Tell Phoenix to update the endpoint configuration - # whenever the application is updated. - def config_change(changed, _new, removed) do - Asciinema.Endpoint.config_change(changed, removed) - :ok - end end diff --git a/web/models/asciicast.ex b/lib/asciinema/asciicasts/asciicast.ex similarity index 95% rename from web/models/asciicast.ex rename to lib/asciinema/asciicasts/asciicast.ex index 29df450..f32da1e 100644 --- a/web/models/asciicast.ex +++ b/lib/asciinema/asciicasts/asciicast.ex @@ -1,6 +1,8 @@ -defmodule Asciinema.Asciicast do - use Asciinema.Web, :model - alias Asciinema.{User, Asciicast} +defmodule Asciinema.Asciicasts.Asciicast do + use Ecto.Schema + import Ecto.Changeset + alias Asciinema.Users.User + alias Asciinema.Asciicasts.Asciicast alias Asciinema.PngGenerator.PngParams @default_png_scale 2 diff --git a/lib/asciinema/asciicasts.ex b/lib/asciinema/asciicasts/asciicasts.ex similarity index 98% rename from lib/asciinema/asciicasts.ex rename to lib/asciinema/asciicasts/asciicasts.ex index 0966a93..02885a2 100644 --- a/lib/asciinema/asciicasts.ex +++ b/lib/asciinema/asciicasts/asciicasts.ex @@ -1,7 +1,7 @@ defmodule Asciinema.Asciicasts do import Ecto.Query, warn: false - alias Asciinema.{Repo, Asciicast, FileStore, StringUtils, Vt} - alias Asciinema.Asciicasts.{SnapshotUpdater, FramesGenerator} + alias Asciinema.{Repo, FileStore, StringUtils, Vt} + alias Asciinema.Asciicasts.{Asciicast, SnapshotUpdater, FramesGenerator} def get_asciicast!(id) when is_integer(id) do Repo.get!(Asciicast, id) diff --git a/lib/asciinema/asciicasts/frames_generator.ex b/lib/asciinema/asciicasts/frames_generator.ex index b742e94..0bf672a 100644 --- a/lib/asciinema/asciicasts/frames_generator.ex +++ b/lib/asciinema/asciicasts/frames_generator.ex @@ -1,5 +1,5 @@ defmodule Asciinema.Asciicasts.FramesGenerator do - alias Asciinema.Asciicast + alias Asciinema.Asciicasts.Asciicast @doc "Generates frames file for given asciicast" @callback generate_frames(asciicast :: %Asciicast{}) :: :ok | {:error, term} diff --git a/lib/asciinema/asciicasts/frames_generator/sidekiq.ex b/lib/asciinema/asciicasts/frames_generator/sidekiq.ex index 06b3e35..b6a67c5 100644 --- a/lib/asciinema/asciicasts/frames_generator/sidekiq.ex +++ b/lib/asciinema/asciicasts/frames_generator/sidekiq.ex @@ -1,5 +1,5 @@ defmodule Asciinema.Asciicasts.FramesGenerator.Sidekiq do - alias Asciinema.Asciicast + alias Asciinema.Asciicasts.Asciicast alias Asciinema.SidekiqClient def generate_frames(%Asciicast{id: id}) do diff --git a/lib/asciinema/asciicasts/snapshot_updater.ex b/lib/asciinema/asciicasts/snapshot_updater.ex index fc6f6c2..824b249 100644 --- a/lib/asciinema/asciicasts/snapshot_updater.ex +++ b/lib/asciinema/asciicasts/snapshot_updater.ex @@ -1,5 +1,5 @@ defmodule Asciinema.Asciicasts.SnapshotUpdater do - alias Asciinema.Asciicast + alias Asciinema.Asciicasts.Asciicast @doc "Generates poster for given asciicast" @callback update_snapshot(asciicast :: %Asciicast{}) :: :ok | {:error, term} diff --git a/lib/asciinema/asciicasts/snapshot_updater/exq.ex b/lib/asciinema/asciicasts/snapshot_updater/exq.ex index af5bad8..04a828f 100644 --- a/lib/asciinema/asciicasts/snapshot_updater/exq.ex +++ b/lib/asciinema/asciicasts/snapshot_updater/exq.ex @@ -1,5 +1,6 @@ defmodule Asciinema.Asciicasts.SnapshotUpdater.Exq do - alias Asciinema.{Repo, Asciicasts, Asciicast} + alias Asciinema.{Repo, Asciicasts} + alias Asciinema.Asciicasts.Asciicast def update_snapshot(%Asciicast{id: id}) do {:ok, _jid} = Exq.enqueue(Exq, "default", __MODULE__, [id]) diff --git a/lib/asciinema/asciicasts/snapshot_updater/sync.ex b/lib/asciinema/asciicasts/snapshot_updater/sync.ex index 699ecfe..4c1457c 100644 --- a/lib/asciinema/asciicasts/snapshot_updater/sync.ex +++ b/lib/asciinema/asciicasts/snapshot_updater/sync.ex @@ -1,5 +1,6 @@ defmodule Asciinema.Asciicasts.SnapshotUpdater.Sync do - alias Asciinema.{Asciicast, Asciicasts} + alias Asciinema.Asciicasts + alias Asciinema.Asciicasts.Asciicast def update_snapshot(%Asciicast{} = asciicast) do {:ok, _} = Asciicasts.update_snapshot(asciicast) diff --git a/lib/asciinema/email.ex b/lib/asciinema/email.ex index 79d784e..fa9329a 100644 --- a/lib/asciinema/email.ex +++ b/lib/asciinema/email.ex @@ -1,5 +1,5 @@ defmodule Asciinema.Email do - use Bamboo.Phoenix, view: Asciinema.EmailView + use Bamboo.Phoenix, view: AsciinemaWeb.EmailView import Bamboo.Email def signup_email(email_address, signup_url) do diff --git a/lib/asciinema/png_generator.ex b/lib/asciinema/png_generator.ex index a049658..1bd94f3 100644 --- a/lib/asciinema/png_generator.ex +++ b/lib/asciinema/png_generator.ex @@ -1,5 +1,5 @@ defmodule Asciinema.PngGenerator do - alias Asciinema.Asciicast + alias Asciinema.Asciicasts.Asciicast alias Asciinema.PngGenerator.PngParams @doc "Generates PNG image from asciicast and returns path to it" diff --git a/lib/asciinema/png_generator/a2png.ex b/lib/asciinema/png_generator/a2png.ex index 0cccd9e..1c2fd84 100644 --- a/lib/asciinema/png_generator/a2png.ex +++ b/lib/asciinema/png_generator/a2png.ex @@ -1,7 +1,7 @@ defmodule Asciinema.PngGenerator.A2png do @behaviour Asciinema.PngGenerator use GenServer - alias Asciinema.Asciicast + alias Asciinema.Asciicasts.Asciicast alias Asciinema.PngGenerator.PngParams @pool_name :worker diff --git a/web/models/api_token.ex b/lib/asciinema/users/api_token.ex similarity index 79% rename from web/models/api_token.ex rename to lib/asciinema/users/api_token.ex index e0c0906..bb6a271 100644 --- a/web/models/api_token.ex +++ b/lib/asciinema/users/api_token.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.ApiToken do - use Asciinema.Web, :model - alias Asciinema.{ApiToken, User} +defmodule Asciinema.Users.ApiToken do + use Ecto.Schema + import Ecto.Changeset + alias Asciinema.Users.{ApiToken, User} schema "api_tokens" do field :token, :string @@ -8,7 +9,7 @@ defmodule Asciinema.ApiToken do timestamps(inserted_at: :created_at) - belongs_to :user, Asciinema.User + belongs_to :user, User end @uuid4 ~r/\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\z/ diff --git a/web/models/user.ex b/lib/asciinema/users/user.ex similarity index 85% rename from web/models/user.ex rename to lib/asciinema/users/user.ex index d007e05..421ed7e 100644 --- a/web/models/user.ex +++ b/lib/asciinema/users/user.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.User do - use Asciinema.Web, :model - alias Asciinema.User +defmodule Asciinema.Users.User do + use Ecto.Schema + import Ecto.Changeset + alias Asciinema.Users.User @valid_email_re ~r/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i @@ -16,8 +17,8 @@ defmodule Asciinema.User do timestamps(inserted_at: :created_at) - has_many :asciicasts, Asciinema.Asciicast - has_many :api_tokens, Asciinema.ApiToken + has_many :asciicasts, Asciinema.Asciicasts.Asciicast + has_many :api_tokens, Asciinema.Users.ApiToken end def changeset(struct, params \\ %{}) do diff --git a/lib/asciinema/users.ex b/lib/asciinema/users/users.ex similarity index 90% rename from lib/asciinema/users.ex rename to lib/asciinema/users/users.ex index 71e325d..12f48a5 100644 --- a/lib/asciinema/users.ex +++ b/lib/asciinema/users/users.ex @@ -1,7 +1,8 @@ defmodule Asciinema.Users do import Ecto.Query, warn: false import Ecto, only: [assoc: 2] - alias Asciinema.{Repo, User, ApiToken, Asciicasts, Email, Mailer, Auth} + alias Asciinema.Users.{User, ApiToken} + alias Asciinema.{Repo, Asciicasts, Email, Mailer} def create_asciinema_user!() do attrs = %{username: "asciinema", @@ -80,20 +81,20 @@ defmodule Asciinema.Users do end defp signup_url(email) do - token = Phoenix.Token.sign(Asciinema.Endpoint, "signup", email) - Asciinema.Router.Helpers.users_url(Asciinema.Endpoint, :new, t: token) + token = Phoenix.Token.sign(AsciinemaWeb.Endpoint, "signup", email) + AsciinemaWeb.Router.Helpers.users_url(AsciinemaWeb.Endpoint, :new, t: token) end defp login_url(%User{id: id, last_login_at: last_login_at}) do last_login_at = last_login_at && Timex.to_unix(last_login_at) - token = Phoenix.Token.sign(Asciinema.Endpoint, "login", {id, last_login_at}) - Asciinema.Router.Helpers.session_url(Asciinema.Endpoint, :new, t: token) + token = Phoenix.Token.sign(AsciinemaWeb.Endpoint, "login", {id, last_login_at}) + AsciinemaWeb.Router.Helpers.session_url(AsciinemaWeb.Endpoint, :new, t: token) end @login_token_max_age 15 * 60 # 15 minutes alias Phoenix.Token - alias Asciinema.Endpoint + alias AsciinemaWeb.Endpoint def verify_signup_token(token) do with {:ok, email} <- Token.verify(Endpoint, "signup", token, max_age: @login_token_max_age), @@ -124,11 +125,6 @@ defmodule Asciinema.Users do end end - def log_in(conn, %User{} = user) do - user = user |> User.login_changeset |> Repo.update! - Auth.login(conn, user) - end - def authenticate(api_token) do q = from u in User, join: at in ApiToken, diff --git a/web/web.ex b/lib/asciinema_web.ex similarity index 62% rename from web/web.ex rename to lib/asciinema_web.ex index a63e8c6..8f6e2b4 100644 --- a/web/web.ex +++ b/lib/asciinema_web.ex @@ -1,12 +1,12 @@ -defmodule Asciinema.Web do +defmodule AsciinemaWeb do @moduledoc """ A module that keeps using definitions for controllers, views and so on. This can be used in your application as: - use Asciinema.Web, :controller - use Asciinema.Web, :view + use AsciinemaWeb, :controller + use AsciinemaWeb, :view The definitions below will be executed for every view, controller, etc, so keep them short and clean, focused @@ -16,35 +16,25 @@ defmodule Asciinema.Web do below. """ - def model do - quote do - use Ecto.Schema - @timestamps_opts inserted_at: :created_at - - import Ecto - import Ecto.Changeset - import Ecto.Query - end - end - def controller do quote do - use Phoenix.Controller + use Phoenix.Controller, namespace: AsciinemaWeb alias Asciinema.Repo import Ecto import Ecto.Query - import Asciinema.Router.Helpers - import Asciinema.Router.Helpers.Extra - import Asciinema.Gettext - import Asciinema.Rails.Flash + import AsciinemaWeb.Router.Helpers + import AsciinemaWeb.Router.Helpers.Extra + import AsciinemaWeb.Gettext + import AsciinemaWeb.Rails.Flash end end def view do quote do - use Phoenix.View, root: "web/templates" + use Phoenix.View, root: "lib/asciinema_web/templates", + namespace: AsciinemaWeb # Import convenience functions from controllers import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1] @@ -52,10 +42,10 @@ defmodule Asciinema.Web do # Use all HTML functionality (forms, tags, etc) use Phoenix.HTML - import Asciinema.Router.Helpers - import Asciinema.Router.Helpers.Extra - import Asciinema.ErrorHelpers - import Asciinema.Gettext + import AsciinemaWeb.Router.Helpers + import AsciinemaWeb.Router.Helpers.Extra + import AsciinemaWeb.ErrorHelpers + import AsciinemaWeb.Gettext end end @@ -73,7 +63,7 @@ defmodule Asciinema.Web do alias Asciinema.Repo import Ecto import Ecto.Query - import Asciinema.Gettext + import AsciinemaWeb.Gettext end end diff --git a/lib/asciinema/auth.ex b/lib/asciinema_web/auth.ex similarity index 77% rename from lib/asciinema/auth.ex rename to lib/asciinema_web/auth.ex index 129e30c..d19d1e8 100644 --- a/lib/asciinema/auth.ex +++ b/lib/asciinema_web/auth.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.Auth do +defmodule AsciinemaWeb.Auth do import Plug.Conn - alias Asciinema.{Repo, User} + alias Asciinema.Users.User + alias Asciinema.Repo @user_key "warden.user.user.key" @one_year_in_secs 31557600 @@ -18,10 +19,12 @@ defmodule Asciinema.Auth do assign(conn, :current_user, user) end - def login(conn, %User{id: id, auth_token: auth_token} = user) do + def log_in(conn, %User{} = user) do + user = user |> User.login_changeset |> Repo.update! + conn - |> put_session(@user_key, id) - |> put_resp_cookie("auth_token", auth_token, max_age: @one_year_in_secs) + |> put_session(@user_key, user.id) + |> put_resp_cookie("auth_token", user.auth_token, max_age: @one_year_in_secs) |> assign(:current_user, user) end diff --git a/web/channels/user_socket.ex b/lib/asciinema_web/channels/user_socket.ex similarity index 89% rename from web/channels/user_socket.ex rename to lib/asciinema_web/channels/user_socket.ex index 8570f48..7484457 100644 --- a/web/channels/user_socket.ex +++ b/lib/asciinema_web/channels/user_socket.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.UserSocket do +defmodule AsciinemaWeb.UserSocket do use Phoenix.Socket ## Channels @@ -30,7 +30,7 @@ defmodule Asciinema.UserSocket do # Would allow you to broadcast a "disconnect" event and terminate # all active sockets and channels for a given user: # - # Asciinema.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{}) + # AsciinemaWeb.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{}) # # Returning `nil` makes this socket anonymous. def id(_socket), do: nil diff --git a/web/controllers/api/asciicast_controller.ex b/lib/asciinema_web/controllers/api/asciicast_controller.ex similarity index 91% rename from web/controllers/api/asciicast_controller.ex rename to lib/asciinema_web/controllers/api/asciicast_controller.ex index 70c46f0..6f557a6 100644 --- a/web/controllers/api/asciicast_controller.ex +++ b/lib/asciinema_web/controllers/api/asciicast_controller.ex @@ -1,7 +1,8 @@ -defmodule Asciinema.Api.AsciicastController do - use Asciinema.Web, :controller - import Asciinema.Auth, only: [get_basic_auth: 1, put_basic_auth: 3] - alias Asciinema.{Asciicasts, Users, User} +defmodule AsciinemaWeb.Api.AsciicastController do + use AsciinemaWeb, :controller + import AsciinemaWeb.Auth, only: [get_basic_auth: 1, put_basic_auth: 3] + alias Asciinema.{Asciicasts, Users} + alias Asciinema.Users.User plug :parse_v0_params plug :authenticate diff --git a/web/controllers/asciicast_animation_controller.ex b/lib/asciinema_web/controllers/asciicast_animation_controller.ex similarity index 73% rename from web/controllers/asciicast_animation_controller.ex rename to lib/asciinema_web/controllers/asciicast_animation_controller.ex index f7dfa2a..c664df7 100644 --- a/web/controllers/asciicast_animation_controller.ex +++ b/lib/asciinema_web/controllers/asciicast_animation_controller.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.AsciicastAnimationController do - use Asciinema.Web, :controller +defmodule AsciinemaWeb.AsciicastAnimationController do + use AsciinemaWeb, :controller alias Asciinema.Asciicasts def show(conn, %{"id" => id}) do diff --git a/web/controllers/asciicast_embed_controller.ex b/lib/asciinema_web/controllers/asciicast_embed_controller.ex similarity index 77% rename from web/controllers/asciicast_embed_controller.ex rename to lib/asciinema_web/controllers/asciicast_embed_controller.ex index 809c17d..8ee75d1 100644 --- a/web/controllers/asciicast_embed_controller.ex +++ b/lib/asciinema_web/controllers/asciicast_embed_controller.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.AsciicastEmbedController do - use Asciinema.Web, :controller +defmodule AsciinemaWeb.AsciicastEmbedController do + use AsciinemaWeb, :controller @max_age 60 diff --git a/web/controllers/asciicast_file_controller.ex b/lib/asciinema_web/controllers/asciicast_file_controller.ex similarity index 76% rename from web/controllers/asciicast_file_controller.ex rename to lib/asciinema_web/controllers/asciicast_file_controller.ex index c71e02b..88515c3 100644 --- a/web/controllers/asciicast_file_controller.ex +++ b/lib/asciinema_web/controllers/asciicast_file_controller.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.AsciicastFileController do - use Asciinema.Web, :controller - alias Asciinema.{Asciicasts, Asciicast} +defmodule AsciinemaWeb.AsciicastFileController do + use AsciinemaWeb, :controller + alias Asciinema.Asciicasts + alias Asciinema.Asciicasts.Asciicast def show(conn, %{"id" => id} = params) do asciicast = Asciicasts.get_asciicast!(id) diff --git a/web/controllers/asciicast_image_controller.ex b/lib/asciinema_web/controllers/asciicast_image_controller.ex similarity index 79% rename from web/controllers/asciicast_image_controller.ex rename to lib/asciinema_web/controllers/asciicast_image_controller.ex index 8402a84..5effd14 100644 --- a/web/controllers/asciicast_image_controller.ex +++ b/lib/asciinema_web/controllers/asciicast_image_controller.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.AsciicastImageController do - use Asciinema.Web, :controller - alias Asciinema.{Asciicasts, Asciicast, PngGenerator} +defmodule AsciinemaWeb.AsciicastImageController do + use AsciinemaWeb, :controller + alias Asciinema.{Asciicasts, PngGenerator} + alias Asciinema.Asciicasts.Asciicast alias Plug.MIME @max_age 604800 # 7 days diff --git a/web/controllers/doc_controller.ex b/lib/asciinema_web/controllers/doc_controller.ex similarity index 83% rename from web/controllers/doc_controller.ex rename to lib/asciinema_web/controllers/doc_controller.ex index b700884..7a1df9b 100644 --- a/web/controllers/doc_controller.ex +++ b/lib/asciinema_web/controllers/doc_controller.ex @@ -1,6 +1,6 @@ -defmodule Asciinema.DocController do - use Asciinema.Web, :controller - alias Asciinema.{DocView, ErrorView} +defmodule AsciinemaWeb.DocController do + use AsciinemaWeb, :controller + alias AsciinemaWeb.{DocView, ErrorView} @topics ["how-it-works", "getting-started", "installation", "usage", "config", "embedding", "faq"] diff --git a/web/controllers/login_controller.ex b/lib/asciinema_web/controllers/login_controller.ex similarity index 90% rename from web/controllers/login_controller.ex rename to lib/asciinema_web/controllers/login_controller.ex index 86a153f..fbd8d70 100644 --- a/web/controllers/login_controller.ex +++ b/lib/asciinema_web/controllers/login_controller.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.LoginController do - use Asciinema.Web, :controller +defmodule AsciinemaWeb.LoginController do + use AsciinemaWeb, :controller alias Asciinema.Users def new(conn, _params) do diff --git a/web/controllers/session_controller.ex b/lib/asciinema_web/controllers/session_controller.ex similarity index 90% rename from web/controllers/session_controller.ex rename to lib/asciinema_web/controllers/session_controller.ex index 1dafc22..d48a0de 100644 --- a/web/controllers/session_controller.ex +++ b/lib/asciinema_web/controllers/session_controller.ex @@ -1,7 +1,9 @@ -defmodule Asciinema.SessionController do - use Asciinema.Web, :controller - import Asciinema.UserView, only: [profile_path: 1] - alias Asciinema.{Users, User} +defmodule AsciinemaWeb.SessionController do + use AsciinemaWeb, :controller + import AsciinemaWeb.UserView, only: [profile_path: 1] + alias Asciinema.Users + alias AsciinemaWeb.Auth + alias Asciinema.Users.User def new(conn, %{"t" => login_token}) do conn @@ -34,7 +36,7 @@ defmodule Asciinema.SessionController do case Users.verify_login_token(login_token) do {:ok, user} -> conn - |> Users.log_in(user) + |> Auth.log_in(user) |> put_rails_flash(:notice, "Welcome back!") |> redirect_to_profile {:error, :token_invalid} -> @@ -58,12 +60,12 @@ defmodule Asciinema.SessionController do case {current_user, logging_user} do {nil, %User{email: nil}} -> conn - |> Users.log_in(logging_user) + |> Auth.log_in(logging_user) |> put_rails_flash(:notice, "Welcome! Setting username and email will help you with logging in later.") |> redirect_to_edit_profile {nil, %User{}} -> conn - |> Users.log_in(logging_user) + |> Auth.log_in(logging_user) |> put_rails_flash(:notice, "Welcome back!") |> redirect_to_profile {%User{id: id, email: nil}, %User{id: id}} -> @@ -78,7 +80,7 @@ defmodule Asciinema.SessionController do {%User{email: nil}, %User{}} -> Users.merge!(logging_user, current_user) conn - |> Users.log_in(logging_user) + |> Auth.log_in(logging_user) |> put_rails_flash(:notice, "Recorder token has been added to your account.") |> redirect_to_profile {%User{}, %User{email: nil}} -> diff --git a/web/controllers/user_controller.ex b/lib/asciinema_web/controllers/user_controller.ex similarity index 89% rename from web/controllers/user_controller.ex rename to lib/asciinema_web/controllers/user_controller.ex index f03064d..89a36ac 100644 --- a/web/controllers/user_controller.ex +++ b/lib/asciinema_web/controllers/user_controller.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.UserController do - use Asciinema.Web, :controller +defmodule AsciinemaWeb.UserController do + use AsciinemaWeb, :controller alias Asciinema.Users + alias AsciinemaWeb.Auth def new(conn, %{"t" => signup_token}) do conn @@ -18,7 +19,7 @@ defmodule Asciinema.UserController do case Users.verify_signup_token(signup_token) do {:ok, user} -> conn - |> Users.log_in(user) + |> Auth.log_in(user) |> put_rails_flash(:info, "Welcome to asciinema!") |> redirect(to: "/username/new") {:error, :token_invalid} -> diff --git a/lib/asciinema/endpoint.ex b/lib/asciinema_web/endpoint.ex similarity index 88% rename from lib/asciinema/endpoint.ex rename to lib/asciinema_web/endpoint.ex index f221ed4..5603ef2 100644 --- a/lib/asciinema/endpoint.ex +++ b/lib/asciinema_web/endpoint.ex @@ -1,7 +1,7 @@ -defmodule Asciinema.Endpoint do +defmodule AsciinemaWeb.Endpoint do use Phoenix.Endpoint, otp_app: :asciinema - socket "/socket", Asciinema.UserSocket + socket "/socket", AsciinemaWeb.UserSocket # Serve at "/" the static files from "priv/static" directory. # @@ -41,7 +41,7 @@ defmodule Asciinema.Endpoint do key_digest: :sha, serializer: Poison - plug Asciinema.TrailingFormat + plug AsciinemaWeb.TrailingFormat - plug Asciinema.Router + plug AsciinemaWeb.Router end diff --git a/web/gettext.ex b/lib/asciinema_web/gettext.ex similarity index 95% rename from web/gettext.ex rename to lib/asciinema_web/gettext.ex index 6b4b799..126dc97 100644 --- a/web/gettext.ex +++ b/lib/asciinema_web/gettext.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.Gettext do +defmodule AsciinemaWeb.Gettext do @moduledoc """ A module providing Internationalization with a gettext-based API. diff --git a/lib/asciinema/rails/flash.ex b/lib/asciinema_web/rails/flash.ex similarity index 87% rename from lib/asciinema/rails/flash.ex rename to lib/asciinema_web/rails/flash.ex index 1cd13d9..477209e 100644 --- a/lib/asciinema/rails/flash.ex +++ b/lib/asciinema_web/rails/flash.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.Rails.Flash do +defmodule AsciinemaWeb.Rails.Flash do import Plug.Conn def put_rails_flash(conn, key, value) do diff --git a/web/router.ex b/lib/asciinema_web/router.ex similarity index 87% rename from web/router.ex rename to lib/asciinema_web/router.ex index 487235b..8632840 100644 --- a/web/router.ex +++ b/lib/asciinema_web/router.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.Router do - use Asciinema.Web, :router +defmodule AsciinemaWeb.Router do + use AsciinemaWeb, :router pipeline :browser do plug :accepts, ["html"] @@ -7,14 +7,14 @@ defmodule Asciinema.Router do plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers - plug Asciinema.Auth + plug AsciinemaWeb.Auth end pipeline :asciicast_embed_script do plug :accepts, ["js"] end - scope "/", Asciinema do + scope "/", AsciinemaWeb do pipe_through :asciicast_embed_script # rewritten by TrailingFormat from /a/123.js to /a/123/js @@ -25,7 +25,7 @@ defmodule Asciinema.Router do plug :accepts, ["json"] end - scope "/", Asciinema do + scope "/", AsciinemaWeb do pipe_through :asciicast_file # rewritten by TrailingFormat from /a/123.json to /a/123/json @@ -36,7 +36,7 @@ defmodule Asciinema.Router do plug :accepts, ["png"] end - scope "/", Asciinema do + scope "/", AsciinemaWeb do pipe_through :asciicast_image # rewritten by TrailingFormat from /a/123.png to /a/123/png @@ -47,14 +47,14 @@ defmodule Asciinema.Router do plug :accepts, ["html"] end - scope "/", Asciinema do + scope "/", AsciinemaWeb do pipe_through :asciicast_animation # rewritten by TrailingFormat from /a/123.gif to /a/123/gif get "/a/:id/gif", AsciicastAnimationController, :show end - scope "/", Asciinema do + scope "/", AsciinemaWeb do pipe_through :browser # Use the default browser stack get "/a/:id", AsciicastController, :show @@ -71,7 +71,7 @@ defmodule Asciinema.Router do get "/connect/:api_token", SessionController, :create, as: :connect end - scope "/api", Asciinema.Api, as: :api do + scope "/api", AsciinemaWeb.Api, as: :api do post "/asciicasts", AsciicastController, :create end @@ -81,8 +81,8 @@ defmodule Asciinema.Router do # end end -defmodule Asciinema.Router.Helpers.Extra do - alias Asciinema.Router.Helpers, as: H +defmodule AsciinemaWeb.Router.Helpers.Extra do + alias AsciinemaWeb.Router.Helpers, as: H def user_path(_conn, :edit) do "/user/edit" diff --git a/web/templates/asciicast_animation/show.html.eex b/lib/asciinema_web/templates/asciicast_animation/show.html.eex similarity index 100% rename from web/templates/asciicast_animation/show.html.eex rename to lib/asciinema_web/templates/asciicast_animation/show.html.eex diff --git a/web/templates/doc/config.html.md b/lib/asciinema_web/templates/doc/config.html.md similarity index 100% rename from web/templates/doc/config.html.md rename to lib/asciinema_web/templates/doc/config.html.md diff --git a/web/templates/doc/embedding.html.md b/lib/asciinema_web/templates/doc/embedding.html.md similarity index 100% rename from web/templates/doc/embedding.html.md rename to lib/asciinema_web/templates/doc/embedding.html.md diff --git a/web/templates/doc/faq.html.md b/lib/asciinema_web/templates/doc/faq.html.md similarity index 100% rename from web/templates/doc/faq.html.md rename to lib/asciinema_web/templates/doc/faq.html.md diff --git a/web/templates/doc/getting-started.html.eex b/lib/asciinema_web/templates/doc/getting-started.html.eex similarity index 100% rename from web/templates/doc/getting-started.html.eex rename to lib/asciinema_web/templates/doc/getting-started.html.eex diff --git a/web/templates/doc/how-it-works.html.md b/lib/asciinema_web/templates/doc/how-it-works.html.md similarity index 100% rename from web/templates/doc/how-it-works.html.md rename to lib/asciinema_web/templates/doc/how-it-works.html.md diff --git a/web/templates/doc/installation.html.md b/lib/asciinema_web/templates/doc/installation.html.md similarity index 100% rename from web/templates/doc/installation.html.md rename to lib/asciinema_web/templates/doc/installation.html.md diff --git a/web/templates/doc/quick_install.html.eex b/lib/asciinema_web/templates/doc/quick_install.html.eex similarity index 100% rename from web/templates/doc/quick_install.html.eex rename to lib/asciinema_web/templates/doc/quick_install.html.eex diff --git a/web/templates/doc/topic_link.html.eex b/lib/asciinema_web/templates/doc/topic_link.html.eex similarity index 100% rename from web/templates/doc/topic_link.html.eex rename to lib/asciinema_web/templates/doc/topic_link.html.eex diff --git a/web/templates/doc/topics.html.eex b/lib/asciinema_web/templates/doc/topics.html.eex similarity index 100% rename from web/templates/doc/topics.html.eex rename to lib/asciinema_web/templates/doc/topics.html.eex diff --git a/web/templates/doc/usage.html.md b/lib/asciinema_web/templates/doc/usage.html.md similarity index 100% rename from web/templates/doc/usage.html.md rename to lib/asciinema_web/templates/doc/usage.html.md diff --git a/web/templates/doc/wrapper.html.eex b/lib/asciinema_web/templates/doc/wrapper.html.eex similarity index 100% rename from web/templates/doc/wrapper.html.eex rename to lib/asciinema_web/templates/doc/wrapper.html.eex diff --git a/web/templates/email/login.text.eex b/lib/asciinema_web/templates/email/login.text.eex similarity index 100% rename from web/templates/email/login.text.eex rename to lib/asciinema_web/templates/email/login.text.eex diff --git a/web/templates/email/signup.text.eex b/lib/asciinema_web/templates/email/signup.text.eex similarity index 100% rename from web/templates/email/signup.text.eex rename to lib/asciinema_web/templates/email/signup.text.eex diff --git a/web/templates/error/404.html.eex b/lib/asciinema_web/templates/error/404.html.eex similarity index 100% rename from web/templates/error/404.html.eex rename to lib/asciinema_web/templates/error/404.html.eex diff --git a/web/templates/layout/app.html.eex b/lib/asciinema_web/templates/layout/app.html.eex similarity index 100% rename from web/templates/layout/app.html.eex rename to lib/asciinema_web/templates/layout/app.html.eex diff --git a/lib/asciinema_web/templates/layout/docs.html.eex b/lib/asciinema_web/templates/layout/docs.html.eex new file mode 100644 index 0000000..9f67f2f --- /dev/null +++ b/lib/asciinema_web/templates/layout/docs.html.eex @@ -0,0 +1 @@ +<%= render @view_module, "wrapper.html", Map.merge(assigns, %{layout: {AsciinemaWeb.LayoutView, "app.html"}, topic_template: @view_template}) %> diff --git a/web/templates/layout/flash.html.eex b/lib/asciinema_web/templates/layout/flash.html.eex similarity index 100% rename from web/templates/layout/flash.html.eex rename to lib/asciinema_web/templates/layout/flash.html.eex diff --git a/web/templates/layout/footer.html.eex b/lib/asciinema_web/templates/layout/footer.html.eex similarity index 100% rename from web/templates/layout/footer.html.eex rename to lib/asciinema_web/templates/layout/footer.html.eex diff --git a/web/templates/layout/header.html.eex b/lib/asciinema_web/templates/layout/header.html.eex similarity index 100% rename from web/templates/layout/header.html.eex rename to lib/asciinema_web/templates/layout/header.html.eex diff --git a/web/templates/layout/simple.html.eex b/lib/asciinema_web/templates/layout/simple.html.eex similarity index 100% rename from web/templates/layout/simple.html.eex rename to lib/asciinema_web/templates/layout/simple.html.eex diff --git a/web/templates/login/new.html.eex b/lib/asciinema_web/templates/login/new.html.eex similarity index 100% rename from web/templates/login/new.html.eex rename to lib/asciinema_web/templates/login/new.html.eex diff --git a/web/templates/login/sent.html.eex b/lib/asciinema_web/templates/login/sent.html.eex similarity index 100% rename from web/templates/login/sent.html.eex rename to lib/asciinema_web/templates/login/sent.html.eex diff --git a/web/templates/session/new.html.eex b/lib/asciinema_web/templates/session/new.html.eex similarity index 100% rename from web/templates/session/new.html.eex rename to lib/asciinema_web/templates/session/new.html.eex diff --git a/web/templates/user/new.html.eex b/lib/asciinema_web/templates/user/new.html.eex similarity index 100% rename from web/templates/user/new.html.eex rename to lib/asciinema_web/templates/user/new.html.eex diff --git a/lib/asciinema/trailing_format.ex b/lib/asciinema_web/trailing_format.ex similarity index 93% rename from lib/asciinema/trailing_format.ex rename to lib/asciinema_web/trailing_format.ex index e214f1f..21a872c 100644 --- a/lib/asciinema/trailing_format.ex +++ b/lib/asciinema_web/trailing_format.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.TrailingFormat do +defmodule AsciinemaWeb.TrailingFormat do @known_extensions ["js", "json", "png", "gif"] def init(opts), do: opts diff --git a/web/views/api/asciicast_view.ex b/lib/asciinema_web/views/api/asciicast_view.ex similarity index 75% rename from web/views/api/asciicast_view.ex rename to lib/asciinema_web/views/api/asciicast_view.ex index 7286e0b..fdfbddd 100644 --- a/web/views/api/asciicast_view.ex +++ b/lib/asciinema_web/views/api/asciicast_view.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.Api.AsciicastView do - use Asciinema.Web, :view +defmodule AsciinemaWeb.Api.AsciicastView do + use AsciinemaWeb, :view def translate_errors(changeset) do Ecto.Changeset.traverse_errors(changeset, &translate_error/1) diff --git a/lib/asciinema_web/views/asciicast_animation_view.ex b/lib/asciinema_web/views/asciicast_animation_view.ex new file mode 100644 index 0000000..9b9d7d7 --- /dev/null +++ b/lib/asciinema_web/views/asciicast_animation_view.ex @@ -0,0 +1,3 @@ +defmodule AsciinemaWeb.AsciicastAnimationView do + use AsciinemaWeb, :view +end diff --git a/web/views/doc_view.ex b/lib/asciinema_web/views/doc_view.ex similarity index 89% rename from web/views/doc_view.ex rename to lib/asciinema_web/views/doc_view.ex index 606faef..aac0c2d 100644 --- a/web/views/doc_view.ex +++ b/lib/asciinema_web/views/doc_view.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.DocView do - use Asciinema.Web, :view +defmodule AsciinemaWeb.DocView do + use AsciinemaWeb, :view @titles %{ :"how-it-works" => "How it works", diff --git a/lib/asciinema_web/views/email_view.ex b/lib/asciinema_web/views/email_view.ex new file mode 100644 index 0000000..52445ff --- /dev/null +++ b/lib/asciinema_web/views/email_view.ex @@ -0,0 +1,3 @@ +defmodule AsciinemaWeb.EmailView do + use AsciinemaWeb, :view +end diff --git a/web/views/error_helpers.ex b/lib/asciinema_web/views/error_helpers.ex similarity index 85% rename from web/views/error_helpers.ex rename to lib/asciinema_web/views/error_helpers.ex index 64456cd..a2e5063 100644 --- a/web/views/error_helpers.ex +++ b/lib/asciinema_web/views/error_helpers.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.ErrorHelpers do +defmodule AsciinemaWeb.ErrorHelpers do @moduledoc """ Conveniences for translating and building error messages. """ @@ -32,9 +32,9 @@ defmodule Asciinema.ErrorHelpers do # dgettext "errors", "is invalid" # if count = opts[:count] do - Gettext.dngettext(Asciinema.Gettext, "errors", msg, msg, count, opts) + Gettext.dngettext(AsciinemaWeb.Gettext, "errors", msg, msg, count, opts) else - Gettext.dgettext(Asciinema.Gettext, "errors", msg, opts) + Gettext.dgettext(AsciinemaWeb.Gettext, "errors", msg, opts) end end end diff --git a/web/views/error_view.ex b/lib/asciinema_web/views/error_view.ex similarity index 80% rename from web/views/error_view.ex rename to lib/asciinema_web/views/error_view.ex index 050ea0e..29a6c62 100644 --- a/web/views/error_view.ex +++ b/lib/asciinema_web/views/error_view.ex @@ -1,5 +1,5 @@ -defmodule Asciinema.ErrorView do - use Asciinema.Web, :view +defmodule AsciinemaWeb.ErrorView do + use AsciinemaWeb, :view def render("500.html", _assigns) do "Internal server error" diff --git a/web/views/layout_view.ex b/lib/asciinema_web/views/layout_view.ex similarity index 63% rename from web/views/layout_view.ex rename to lib/asciinema_web/views/layout_view.ex index 39aa40c..a13edbf 100644 --- a/web/views/layout_view.ex +++ b/lib/asciinema_web/views/layout_view.ex @@ -1,6 +1,6 @@ -defmodule Asciinema.LayoutView do - use Asciinema.Web, :view - import Asciinema.UserView, only: [avatar_url: 1, profile_path: 1] +defmodule AsciinemaWeb.LayoutView do + use AsciinemaWeb, :view + import AsciinemaWeb.UserView, only: [avatar_url: 1, profile_path: 1] def page_title(conn) do case conn.assigns[:page_title] do diff --git a/lib/asciinema_web/views/login_view.ex b/lib/asciinema_web/views/login_view.ex new file mode 100644 index 0000000..c139640 --- /dev/null +++ b/lib/asciinema_web/views/login_view.ex @@ -0,0 +1,3 @@ +defmodule AsciinemaWeb.LoginView do + use AsciinemaWeb, :view +end diff --git a/lib/asciinema_web/views/session_view.ex b/lib/asciinema_web/views/session_view.ex new file mode 100644 index 0000000..85c7cc4 --- /dev/null +++ b/lib/asciinema_web/views/session_view.ex @@ -0,0 +1,3 @@ +defmodule AsciinemaWeb.SessionView do + use AsciinemaWeb, :view +end diff --git a/web/views/user_view.ex b/lib/asciinema_web/views/user_view.ex similarity index 77% rename from web/views/user_view.ex rename to lib/asciinema_web/views/user_view.ex index c9e4eba..0f55f4a 100644 --- a/web/views/user_view.ex +++ b/lib/asciinema_web/views/user_view.ex @@ -1,6 +1,7 @@ -defmodule Asciinema.UserView do - use Asciinema.Web, :view - alias Asciinema.{Gravatar, User} +defmodule AsciinemaWeb.UserView do + use AsciinemaWeb, :view + alias Asciinema.Users.User + alias Asciinema.Gravatar def avatar_url(user) do username = user_username(user) diff --git a/mix.exs b/mix.exs index 24d2f1a..dc485a7 100644 --- a/mix.exs +++ b/mix.exs @@ -17,7 +17,7 @@ defmodule Asciinema.Mixfile do # # Type `mix help compile.app` for more information. def application do - [mod: {Asciinema, []}, + [mod: {Asciinema.Application, []}, applications: [ :bamboo, :bamboo_smtp, @@ -44,8 +44,8 @@ defmodule Asciinema.Mixfile do end # Specifies which paths to compile per environment. - defp elixirc_paths(:test), do: ["lib", "web", "test/support"] - defp elixirc_paths(_), do: ["lib", "web"] + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] # Specifies your project dependencies. # diff --git a/test/asciinema/asciicasts_test.exs b/test/asciinema/asciicasts_test.exs index 3418af5..2723ae6 100644 --- a/test/asciinema/asciicasts_test.exs +++ b/test/asciinema/asciicasts_test.exs @@ -1,6 +1,7 @@ defmodule Asciinema.AsciicastsTest do use Asciinema.DataCase - alias Asciinema.{Asciicasts, Asciicast} + alias Asciinema.Asciicasts + alias Asciinema.Asciicasts.Asciicast describe "create_asciicast/3" do test "json file, v0 format with uname" do diff --git a/test/controllers/api/asciicast_controller_test.exs b/test/controllers/api/asciicast_controller_test.exs index 9c85d1f..2813db8 100644 --- a/test/controllers/api/asciicast_controller_test.exs +++ b/test/controllers/api/asciicast_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.Api.AsciicastControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase alias Asciinema.Users setup %{conn: conn} = context do diff --git a/test/controllers/asciicast_animation_controller_test.exs b/test/controllers/asciicast_animation_controller_test.exs index 42a0662..63ce746 100644 --- a/test/controllers/asciicast_animation_controller_test.exs +++ b/test/controllers/asciicast_animation_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.AsciicastAnimationControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase test "shows GIF generation instructions", %{conn: conn} do asciicast = fixture(:asciicast) diff --git a/test/controllers/asciicast_embed_controller_test.exs b/test/controllers/asciicast_embed_controller_test.exs index 9741b10..fabfff1 100644 --- a/test/controllers/asciicast_embed_controller_test.exs +++ b/test/controllers/asciicast_embed_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.AsciicastEmbedControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase test "serves embed js", %{conn: conn} do conn = get conn, "/a/12345.js" diff --git a/test/controllers/asciicast_file_controller_test.exs b/test/controllers/asciicast_file_controller_test.exs index 5c091e0..68d7a66 100644 --- a/test/controllers/asciicast_file_controller_test.exs +++ b/test/controllers/asciicast_file_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.AsciicastFileControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase test "renders asciicast file", %{conn: conn} do asciicast = fixture(:asciicast) diff --git a/test/controllers/asciicast_image_controller_test.exs b/test/controllers/asciicast_image_controller_test.exs index c7ed7d8..ae7c0d2 100644 --- a/test/controllers/asciicast_image_controller_test.exs +++ b/test/controllers/asciicast_image_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.AsciicastImageControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase @tag :a2png diff --git a/test/controllers/doc_controller_test.exs b/test/controllers/doc_controller_test.exs index b60cc0b..78b3d67 100644 --- a/test/controllers/doc_controller_test.exs +++ b/test/controllers/doc_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.DocControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase test "GET /docs", %{conn: conn} do conn = get conn, "/docs" diff --git a/test/controllers/login_controller_test.exs b/test/controllers/login_controller_test.exs index 2b76d01..fd98055 100644 --- a/test/controllers/login_controller_test.exs +++ b/test/controllers/login_controller_test.exs @@ -1,5 +1,5 @@ defmodule Asciinema.LoginControllerTest do - use Asciinema.ConnCase + use AsciinemaWeb.ConnCase test "with valid email", %{conn: conn} do conn = post conn, "/login", %{login: %{email: "new@example.com"}} diff --git a/test/controllers/session_controller_test.exs b/test/controllers/session_controller_test.exs index cffbbf5..72100d8 100644 --- a/test/controllers/session_controller_test.exs +++ b/test/controllers/session_controller_test.exs @@ -1,6 +1,7 @@ defmodule Asciinema.SessionControllerTest do - use Asciinema.ConnCase - alias Asciinema.{Users, User, ApiToken} + use AsciinemaWeb.ConnCase + alias Asciinema.Users + alias Asciinema.Users.{User, ApiToken} @revoked_token "eb927b31-9ca3-4a6a-8a0c-dfba318e2e84" @regular_user_token "c4ecd96a-9a16-464d-be6a-bc1f3c50c4ae" diff --git a/test/models/user_test.exs b/test/models/user_test.exs deleted file mode 100644 index 498d5a7..0000000 --- a/test/models/user_test.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Asciinema.UserTest do - use Asciinema.ModelCase - - alias Asciinema.User - - @valid_attrs %{email: "test@example.com"} - @invalid_attrs %{} - - test "signup changeset with valid attributes" do - changeset = User.signup_changeset(@valid_attrs) - assert changeset.valid? - end - - test "signup changeset with invalid attributes" do - changeset = User.signup_changeset(@invalid_attrs) - refute changeset.valid? - end -end diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 85af6ff..628a563 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.ChannelCase do +defmodule AsciinemaWeb.ChannelCase do @moduledoc """ This module defines the test case to be used by channel tests. @@ -27,7 +27,7 @@ defmodule Asciinema.ChannelCase do # The default endpoint for testing - @endpoint Asciinema.Endpoint + @endpoint AsciinemaWeb.Endpoint end end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 8145cbb..1c11d93 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.ConnCase do +defmodule AsciinemaWeb.ConnCase do @moduledoc """ This module defines the test case to be used by tests that require setting up a connection. @@ -25,12 +25,12 @@ defmodule Asciinema.ConnCase do import Ecto.Changeset import Ecto.Query - import Asciinema.Router.Helpers - import Asciinema.Router.Helpers.Extra + import AsciinemaWeb.Router.Helpers + import AsciinemaWeb.Router.Helpers.Extra import Asciinema.Fixtures # The default endpoint for testing - @endpoint Asciinema.Endpoint + @endpoint AsciinemaWeb.Endpoint end end diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index 5b547ad..54363e8 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -1,5 +1,6 @@ defmodule Asciinema.Fixtures do - alias Asciinema.{Repo, Asciicasts, User} + alias Asciinema.{Repo, Asciicasts} + alias Asciinema.Users.User def fixture(what, attrs \\ %{}) diff --git a/test/support/model_case.ex b/test/support/model_case.ex deleted file mode 100644 index 4199feb..0000000 --- a/test/support/model_case.ex +++ /dev/null @@ -1,65 +0,0 @@ -defmodule Asciinema.ModelCase do - @moduledoc """ - This module defines the test case to be used by - model tests. - - You may define functions here to be used as helpers in - your model tests. See `errors_on/2`'s definition as reference. - - Finally, if the test case interacts with the database, - it cannot be async. For this reason, every test runs - inside a transaction which is reset at the beginning - of the test unless the test case is marked as async. - """ - - use ExUnit.CaseTemplate - - using do - quote do - alias Asciinema.Repo - - import Ecto - import Ecto.Changeset - import Ecto.Query - import Asciinema.ModelCase - end - end - - setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Asciinema.Repo) - - unless tags[:async] do - Ecto.Adapters.SQL.Sandbox.mode(Asciinema.Repo, {:shared, self()}) - end - - :ok - end - - @doc """ - Helper for returning list of errors in a struct when given certain data. - - ## Examples - - Given a User schema that lists `:name` as a required field and validates - `:password` to be safe, it would return: - - iex> errors_on(%User{}, %{password: "password"}) - [password: "is unsafe", name: "is blank"] - - You could then write your assertion like: - - assert {:password, "is unsafe"} in errors_on(%User{}, %{password: "password"}) - - You can also create the changeset manually and retrieve the errors - field directly: - - iex> changeset = User.changeset(%User{}, password: "password") - iex> {:password, "is unsafe"} in changeset.errors - true - """ - def errors_on(struct, data) do - struct.__struct__.changeset(struct, data) - |> Ecto.Changeset.traverse_errors(&Asciinema.ErrorHelpers.translate_error/1) - |> Enum.flat_map(fn {key, errors} -> for msg <- errors, do: {key, msg} end) - end -end diff --git a/test/views/error_view_test.exs b/test/views/error_view_test.exs index ebb260e..194af0d 100644 --- a/test/views/error_view_test.exs +++ b/test/views/error_view_test.exs @@ -1,21 +1,21 @@ defmodule Asciinema.ErrorViewTest do - use Asciinema.ConnCase, async: true + use AsciinemaWeb.ConnCase, async: true # Bring render/3 and render_to_string/3 for testing custom views import Phoenix.View test "renders 404.html" do - assert render_to_string(Asciinema.ErrorView, "404.html", []) =~ + assert render_to_string(AsciinemaWeb.ErrorView, "404.html", []) =~ "not found" end test "render 500.html" do - assert render_to_string(Asciinema.ErrorView, "500.html", []) == + assert render_to_string(AsciinemaWeb.ErrorView, "500.html", []) == "Internal server error" end test "render any other" do - assert render_to_string(Asciinema.ErrorView, "505.html", []) == + assert render_to_string(AsciinemaWeb.ErrorView, "505.html", []) == "Internal server error" end end diff --git a/test/views/layout_view_test.exs b/test/views/layout_view_test.exs index 16029e4..5add0c7 100644 --- a/test/views/layout_view_test.exs +++ b/test/views/layout_view_test.exs @@ -1,3 +1,3 @@ defmodule Asciinema.LayoutViewTest do - use Asciinema.ConnCase, async: true + use AsciinemaWeb.ConnCase, async: true end diff --git a/test/views/page_view_test.exs b/test/views/page_view_test.exs index 719c818..e8fae40 100644 --- a/test/views/page_view_test.exs +++ b/test/views/page_view_test.exs @@ -1,3 +1,3 @@ defmodule Asciinema.PageViewTest do - use Asciinema.ConnCase, async: true + use AsciinemaWeb.ConnCase, async: true end diff --git a/web/templates/layout/docs.html.eex b/web/templates/layout/docs.html.eex deleted file mode 100644 index 1ffa491..0000000 --- a/web/templates/layout/docs.html.eex +++ /dev/null @@ -1 +0,0 @@ -<%= render @view_module, "wrapper.html", Map.merge(assigns, %{layout: {Asciinema.LayoutView, "app.html"}, topic_template: @view_template}) %> diff --git a/web/views/asciicast_animation_view.ex b/web/views/asciicast_animation_view.ex deleted file mode 100644 index c7a7cb3..0000000 --- a/web/views/asciicast_animation_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Asciinema.AsciicastAnimationView do - use Asciinema.Web, :view -end diff --git a/web/views/email_view.ex b/web/views/email_view.ex deleted file mode 100644 index 588cd84..0000000 --- a/web/views/email_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Asciinema.EmailView do - use Asciinema.Web, :view -end diff --git a/web/views/login_view.ex b/web/views/login_view.ex deleted file mode 100644 index 74c46e6..0000000 --- a/web/views/login_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Asciinema.LoginView do - use Asciinema.Web, :view -end diff --git a/web/views/session_view.ex b/web/views/session_view.ex deleted file mode 100644 index 5d39e54..0000000 --- a/web/views/session_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Asciinema.SessionView do - use Asciinema.Web, :view -end