forked from phoenixframework/phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.ex
More file actions
89 lines (74 loc) · 2.19 KB
/
Copy pathproject.ex
File metadata and controls
89 lines (74 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
defmodule Phx.New.Project do
@moduledoc false
alias Phx.New.Project
defstruct base_path: nil,
app: nil,
app_mod: nil,
app_path: nil,
lib_web_name: nil,
root_app: nil,
root_mod: nil,
project_path: nil,
web_app: nil,
web_namespace: nil,
web_path: nil,
opts: :unset,
in_umbrella?: false,
binding: [],
cached_build_path: nil,
generators: [timestamp_type: :utc_datetime]
def new(project_path, opts) do
project_path = Path.expand(project_path)
app = opts[:app] || Path.basename(project_path)
app_mod = Module.concat([opts[:module] || Macro.camelize(app)])
%Project{
base_path: project_path,
app: app,
app_mod: app_mod,
root_app: app,
root_mod: app_mod,
opts: opts
}
end
def ecto?(%Project{binding: binding}) do
Keyword.fetch!(binding, :ecto)
end
def html?(%Project{binding: binding}) do
Keyword.fetch!(binding, :html)
end
def gettext?(%Project{binding: binding}) do
Keyword.fetch!(binding, :gettext)
end
def live?(%Project{binding: binding}) do
Keyword.fetch!(binding, :live)
end
def dashboard?(%Project{binding: binding}) do
Keyword.fetch!(binding, :dashboard)
end
def javascript?(%Project{binding: binding}) do
Keyword.fetch!(binding, :javascript)
end
def css?(%Project{binding: binding}) do
Keyword.fetch!(binding, :css)
end
def mailer?(%Project{binding: binding}) do
Keyword.fetch!(binding, :mailer)
end
def verbose?(%Project{opts: opts}) do
Keyword.get(opts, :verbose, false)
end
def join_path(%Project{} = project, location, path)
when location in [:project, :app, :web] do
base = Map.fetch!(project, :"#{location}_path")
expanded = expand_path_with_bindings(path, project)
Path.join(base, expanded)
end
defp expand_path_with_bindings(path, %Project{} = project) do
Regex.replace(Regex.recompile!(~r/:[a-zA-Z0-9_]+/), path, fn ":" <> key, _ ->
case Map.fetch(project, :"#{key}") do
{:ok, value} -> to_string(value)
:error -> ":#{key}"
end
end)
end
end