Current section
37 Versions
Jump to
Current section
37 Versions
Compare versions
5
files changed
+51
additions
-12
deletions
| @@ -26,7 +26,7 @@ | |
| 26 26 | <<"mix.exs">>,<<"README.md">>,<<"package.json">>]}. |
| 27 27 | {<<"licenses">>,[<<"MIT">>]}. |
| 28 28 | {<<"links">>, |
| 29 | - [{<<"Docs">>,<<"https://hexdocs.pm/thesis/0.0.2/api-reference.html">>}, |
| 29 | + [{<<"Docs">>,<<"https://hexdocs.pm/thesis/0.0.3/api-reference.html">>}, |
| 30 30 | {<<"GitHub">>,<<"https://github.com/infinite_red/thesis">>}]}. |
| 31 31 | {<<"maintainers">>, |
| 32 32 | [<<"Jamon Holmgren">>,<<"Ken Miller">>,<<"Daniel Berkompas">>]}. |
| @@ -52,4 +52,4 @@ | |
| 52 52 | [{<<"app">>,<<"plug">>}, |
| 53 53 | {<<"optional">>,false}, |
| 54 54 | {<<"requirement">>,<<"~> 1.0">>}]}]}. |
| 55 | - {<<"version">>,<<"0.0.2">>}. |
| 55 | + {<<"version">>,<<"0.0.3">>}. |
| @@ -12,6 +12,7 @@ defmodule Mix.Tasks.Thesis.Install do | |
| 12 12 | thesis_templates |
| 13 13 | thesis_npm |
| 14 14 | thesis_config |
| 15 | + thesis_web |
| 15 16 | end |
| 16 17 | |
| 17 18 | def thesis_templates do |
| @@ -34,11 +35,43 @@ defmodule Mix.Tasks.Thesis.Install do | |
| 34 35 | |
| 35 36 | def thesis_config do |
| 36 37 | status_msg("updating", "config/config.exs") |
| 37 | - dest_path = Path.join [File.cwd! | ~w(config)] |
| 38 | - dest_file_path = Path.join dest_path, "config.exs" |
| 38 | + dest_file_path = Path.join [File.cwd! | ~w(config config.exs)] |
| 39 39 | File.read!(dest_file_path) |
| 40 40 | |> insert_thesis |
| 41 | - |> append_to_file(dest_file_path) |
| 41 | + |> overwrite_file(dest_file_path) |
| 42 | + end |
| 43 | + |
| 44 | + def thesis_web do |
| 45 | + status_msg("updating", "web/web.exs") |
| 46 | + view_pattern = "def view do\n quote do" |
| 47 | + router_pattern = "def router do\n quote do" |
| 48 | + dest_file_path = Path.join [File.cwd! | ~w(web web.ex)] |
| 49 | + File.read!(dest_file_path) |
| 50 | + |> insert_controller |
| 51 | + |> insert_view |
| 52 | + |> insert_router |
| 53 | + |> IO.puts |
| 54 | + |> overwrite_file(dest_file_path) |
| 55 | + end |
| 56 | + |
| 57 | + defp insert_controller(source) do |
| 58 | + insert_at(source, "def controller do\n quote do", "\n use Thesis.Controller\n") |
| 59 | + end |
| 60 | + |
| 61 | + defp insert_view(source) do |
| 62 | + insert_at(source, "def view do\n quote do", "\n use Thesis.View\n") |
| 63 | + end |
| 64 | + |
| 65 | + defp insert_router(source) do |
| 66 | + insert_at(source, "def router do\n quote do", "\n use Thesis.Router\n") |
| 67 | + end |
| 68 | + |
| 69 | + defp insert_at(source, pattern, inserted) do |
| 70 | + unless String.contains?(source, inserted) do |
| 71 | + String.replace(source, pattern, pattern <> inserted) |
| 72 | + else |
| 73 | + source |
| 74 | + end |
| 42 75 | end |
| 43 76 | |
| 44 77 | defp insert_thesis(source) do |
| @@ -29,8 +29,8 @@ defmodule Mix.Thesis.Utils do | |
| 29 29 | @doc "Print an error message in red" |
| 30 30 | def error(message), do: IO.puts "==> #{IO.ANSI.red}#{message}#{IO.ANSI.reset}" |
| 31 31 | |
| 32 | - def append_to_file(:skip, _dest_file_path), do: :ok |
| 33 | - def append_to_file(contents, dest_file_path) do |
| 32 | + def overwrite_file(:skip, _dest_file_path), do: :ok |
| 33 | + def overwrite_file(contents, dest_file_path) do |
| 34 34 | File.write! dest_file_path, contents |
| 35 35 | end |
| @@ -1,9 +1,15 @@ | |
| 1 1 | defmodule Thesis.Router do |
| 2 2 | use Phoenix.Router |
| 3 | - alias Thesis.ApiController |
| 4 3 | |
| 5 | - get "/", Api.Controller, :index |
| 4 | + scope "/thesis", Thesis do |
| 5 | + get "/thesis-editor.js", ApiController, :js |
| 6 | + put "/update", ApiController, :update |
| 7 | + end |
| 6 8 | |
| 7 | - get "/thesis-editor.js", ApiController, :js |
| 8 | - put "/update", ApiController, :update |
| 9 | + defmacro __using__(_) do |
| 10 | + # Reserved for future use |
| 11 | + quote do |
| 12 | + import unquote(__MODULE__) |
| 13 | + end |
| 14 | + end |
| 9 15 | end |
| @@ -1,6 +1,6 @@ | |
| 1 1 | defmodule Thesis.Mixfile do |
| 2 2 | use Mix.Project |
| 3 | - @version "0.0.2" |
| 3 | + @version "0.0.3" |
| 4 4 | |
| 5 5 | def project do |
| 6 6 | [ |