Skip to content

Commit bcbceff

Browse files
authored
Apply formatter (#58)
1 parent 0107948 commit bcbceff

File tree

6 files changed

+115
-73
lines changed

6 files changed

+115
-73
lines changed

lib/mix/tasks/phoenix.gen.html.slime.ex

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,43 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
3737
default_opts = Application.get_env(:phoenix, :generators, [])
3838
opts = Keyword.merge(default_opts, opts)
3939

40-
attrs = Mix.Phoenix.Schema.attrs(attrs)
40+
attrs = Mix.Phoenix.Schema.attrs(attrs)
4141
binding = Mix.Phoenix.inflect(singular)
42-
path = binding[:path]
43-
route = String.split(path, "/") |> Enum.drop(-1) |> Kernel.++([plural]) |> Enum.join("/")
44-
binding = binding ++ [plural: plural, route: route, attrs: attrs,
45-
binary_id: opts[:binary_id],
46-
sample_id: sample_id(opts),
47-
inputs: inputs(attrs), params: Mix.Phoenix.Schema.params(attrs),
48-
template_singular: String.replace(binding[:singular], "_", " "),
49-
template_plural: String.replace(plural, "_", " ")]
42+
path = binding[:path]
43+
route = String.split(path, "/") |> Enum.drop(-1) |> Kernel.++([plural]) |> Enum.join("/")
44+
45+
binding =
46+
binding ++
47+
[
48+
plural: plural,
49+
route: route,
50+
attrs: attrs,
51+
binary_id: opts[:binary_id],
52+
sample_id: sample_id(opts),
53+
inputs: inputs(attrs),
54+
params: Mix.Phoenix.Schema.params(attrs),
55+
template_singular: String.replace(binding[:singular], "_", " "),
56+
template_plural: String.replace(plural, "_", " ")
57+
]
5058

5159
Mix.Phoenix.check_module_name_availability!(binding[:module] <> "Controller")
5260
Mix.Phoenix.check_module_name_availability!(binding[:module] <> "View")
5361

54-
Mix.Phoenix.copy_from paths(), "priv/templates/phoenix.gen.html", binding, [
55-
{:eex, "controller.ex", "web/controllers/#{path}_controller.ex"},
56-
{:eex, "view.ex", "web/views/#{path}_view.ex"},
57-
{:eex, "controller_test.exs", "test/controllers/#{path}_controller_test.exs"},
58-
]
59-
60-
extension = PhoenixSlime.ConfiguredExtension.file_extension
61-
Mix.Phoenix.copy_from slime_paths(), "priv/templates/phoenix.gen.html.slime", binding, [
62-
{:eex, "edit.html.eex", "web/templates/#{path}/edit.html.#{extension}"},
63-
{:eex, "form.html.eex", "web/templates/#{path}/form.html.#{extension}"},
64-
{:eex, "index.html.eex", "web/templates/#{path}/index.html.#{extension}"},
65-
{:eex, "new.html.eex", "web/templates/#{path}/new.html.#{extension}"},
66-
{:eex, "show.html.eex", "web/templates/#{path}/show.html.#{extension}"},
67-
]
62+
Mix.Phoenix.copy_from(paths(), "priv/templates/phoenix.gen.html", binding, [
63+
{:eex, "controller.ex", "web/controllers/#{path}_controller.ex"},
64+
{:eex, "view.ex", "web/views/#{path}_view.ex"},
65+
{:eex, "controller_test.exs", "test/controllers/#{path}_controller_test.exs"}
66+
])
67+
68+
extension = PhoenixSlime.ConfiguredExtension.file_extension()
69+
70+
Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.html.slime", binding, [
71+
{:eex, "edit.html.eex", "web/templates/#{path}/edit.html.#{extension}"},
72+
{:eex, "form.html.eex", "web/templates/#{path}/form.html.#{extension}"},
73+
{:eex, "index.html.eex", "web/templates/#{path}/index.html.#{extension}"},
74+
{:eex, "new.html.eex", "web/templates/#{path}/new.html.#{extension}"},
75+
{:eex, "show.html.eex", "web/templates/#{path}/show.html.#{extension}"}
76+
])
6877

6978
instructions = """
7079
@@ -74,9 +83,9 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
7483
"""
7584

7685
if opts[:model] != false do
77-
Mix.Task.run "phoenix.gen.model", ["--instructions", instructions|args]
86+
Mix.Task.run("phoenix.gen.model", ["--instructions", instructions | args])
7887
else
79-
Mix.shell.info instructions
88+
Mix.shell().info(instructions)
8089
end
8190
end
8291

@@ -92,8 +101,12 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
92101
cond do
93102
String.contains?(plural, ":") ->
94103
raise_with_help()
104+
95105
plural != Phoenix.Naming.underscore(plural) ->
96-
Mix.raise "Expected the second argument, #{inspect plural}, to be all lowercase using snake_case convention"
106+
Mix.raise(
107+
"Expected the second argument, #{inspect(plural)}, to be all lowercase using snake_case convention"
108+
)
109+
97110
true ->
98111
args
99112
end
@@ -104,41 +117,54 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
104117
end
105118

106119
defp raise_with_help do
107-
Mix.raise """
120+
Mix.raise("""
108121
mix phoenix_slime.gen.html expects both singular and plural names
109122
of the generated resource followed by any number of attributes:
110123
111124
mix phoenix_slime.gen.html User users name:string
112-
"""
125+
""")
113126
end
114127

115128
defp inputs(attrs) do
116-
Enum.map attrs, fn
129+
Enum.map(attrs, fn
117130
{_, {:array, _}} ->
118131
{nil, nil, nil}
132+
119133
{_, {:references, _}} ->
120134
{nil, nil, nil}
121-
{key, :integer} ->
135+
136+
{key, :integer} ->
122137
{label(key), ~s(= number_input f, #{inspect(key)}, class: "form-control"), error(key)}
123-
{key, :float} ->
124-
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), error(key)}
125-
{key, :decimal} ->
126-
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), error(key)}
127-
{key, :boolean} ->
138+
139+
{key, :float} ->
140+
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"),
141+
error(key)}
142+
143+
{key, :decimal} ->
144+
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"),
145+
error(key)}
146+
147+
{key, :boolean} ->
128148
{label(key), ~s(= checkbox f, #{inspect(key)}, class: "form-control"), error(key)}
129-
{key, :text} ->
149+
150+
{key, :text} ->
130151
{label(key), ~s(= textarea f, #{inspect(key)}, class: "form-control"), error(key)}
131-
{key, :date} ->
152+
153+
{key, :date} ->
132154
{label(key), ~s(= date_select f, #{inspect(key)}, class: "form-control"), error(key)}
133-
{key, :time} ->
155+
156+
{key, :time} ->
134157
{label(key), ~s(= time_select f, #{inspect(key)}, class: "form-control"), error(key)}
135-
{key, :utc_datetime} ->
158+
159+
{key, :utc_datetime} ->
136160
{label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)}
137-
{key, :naive_datetime} ->
161+
162+
{key, :naive_datetime} ->
138163
{label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)}
139-
{key, _} ->
164+
165+
{key, _} ->
140166
{label(key), ~s(= text_input f, #{inspect(key)}, class: "form-control"), error(key)}
141-
end
167+
end)
142168
end
143169

144170
defp label(key) do

lib/mix/tasks/phoenix.gen.layout.slime.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ defmodule Mix.Tasks.Phoenix.Gen.Layout.Slime do
1010
1111
"""
1212
def run(_args) do
13-
1413
binding = [application_module: "ApplicationName"]
1514

16-
extension = PhoenixSlime.ConfiguredExtension.file_extension
17-
Mix.Phoenix.copy_from slime_paths(), "priv/templates/phoenix.gen.layout.slime", binding, [
18-
{:eex, "app.html.eex", "web/templates/layout/app.html.#{extension}"}
19-
]
15+
extension = PhoenixSlime.ConfiguredExtension.file_extension()
16+
17+
Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.layout.slime", binding, [
18+
{:eex, "app.html.eex", "web/templates/layout/app.html.#{extension}"}
19+
])
2020

2121
instructions = """
2222
2323
A new web/templates/layout/app.html.#{extension} file was generated.
2424
"""
25-
Mix.shell.info instructions
25+
26+
Mix.shell().info(instructions)
2627
end
2728

2829
defp slime_paths do

lib/mix/tasks/phx.gen.html.slime.ex

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ defmodule Mix.Tasks.Phx.Gen.Html.Slime do
105105

106106
@doc false
107107
def run(args) do
108-
if Mix.Project.umbrella? do
109-
Mix.raise "mix phx.gen.html.slime can only be run inside an application directory"
108+
if Mix.Project.umbrella?() do
109+
Mix.raise("mix phx.gen.html.slime can only be run inside an application directory")
110110
end
111+
111112
{context, schema} = Gen.Context.build(args)
112113
binding = [context: context, schema: schema, inputs: inputs(schema)]
113114
paths = [".", :phoenix_slime, :phoenix]
@@ -125,9 +126,11 @@ defmodule Mix.Tasks.Phx.Gen.Html.Slime do
125126
|> Kernel.++(context_files(context))
126127
|> Mix.Phoenix.prompt_for_conflicts()
127128
end
129+
128130
defp context_files(%Context{generate?: true} = context) do
129131
Gen.Context.files_to_be_generated(context)
130132
end
133+
131134
defp context_files(%Context{generate?: false}) do
132135
[]
133136
end
@@ -136,10 +139,10 @@ defmodule Mix.Tasks.Phx.Gen.Html.Slime do
136139
def files_to_be_generated(context) do
137140
to_gen = Mix.Tasks.Phx.Gen.Html.files_to_be_generated(context)
138141

139-
extension = PhoenixSlime.ConfiguredExtension.file_extension
142+
extension = PhoenixSlime.ConfiguredExtension.file_extension()
140143

141-
Enum.map(to_gen, fn
142-
{type, name, path} -> {type, name, String.replace_suffix(path, "eex", extension)}
144+
Enum.map(to_gen, fn {type, name, path} ->
145+
{type, name, String.replace_suffix(path, "eex", extension)}
143146
end)
144147
end
145148

@@ -155,32 +158,44 @@ defmodule Mix.Tasks.Phx.Gen.Html.Slime do
155158
Enum.map(attrs, fn
156159
{_, {:array, _}} ->
157160
{nil, nil, nil}
161+
158162
{_, {:references, _}} ->
159163
{nil, nil, nil}
160-
{key, :integer} ->
164+
165+
{key, :integer} ->
161166
{label(key), ~s(= number_input f, #{inspect(key)}, class: "form-control"), error(key)}
162-
{key, :float} ->
163-
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), error(key)}
164-
{key, :decimal} ->
165-
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), error(key)}
166-
{key, :boolean} ->
167+
168+
{key, :float} ->
169+
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"),
170+
error(key)}
171+
172+
{key, :decimal} ->
173+
{label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"),
174+
error(key)}
175+
176+
{key, :boolean} ->
167177
{label(key), ~s(= checkbox f, #{inspect(key)}, class: "form-control"), error(key)}
168-
{key, :text} ->
178+
179+
{key, :text} ->
169180
{label(key), ~s(= textarea f, #{inspect(key)}, class: "form-control"), error(key)}
170-
{key, :date} ->
181+
182+
{key, :date} ->
171183
{label(key), ~s(= date_select f, #{inspect(key)}, class: "form-control"), error(key)}
172-
{key, :time} ->
184+
185+
{key, :time} ->
173186
{label(key), ~s(= time_select f, #{inspect(key)}, class: "form-control"), error(key)}
174-
{key, :utc_datetime} ->
187+
188+
{key, :utc_datetime} ->
175189
{label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)}
176-
{key, :naive_datetime} ->
190+
191+
{key, :naive_datetime} ->
177192
{label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)}
178-
{key, _} ->
193+
194+
{key, _} ->
179195
{label(key), ~s(= text_input f, #{inspect(key)}, class: "form-control"), error(key)}
180196
end)
181197
end
182198

183-
184199
defp label(key) do
185200
~s(= label f, #{inspect(key)}, class: "control-label")
186201
end

lib/mix/tasks/phx.gen.layout.slime.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ defmodule Mix.Tasks.Phx.Gen.Layout.Slime do
1414
web_prefix = Mix.Phoenix.web_path(context_app)
1515
binding = [application_module: Mix.Phoenix.base()]
1616

17-
extension = PhoenixSlime.ConfiguredExtension.file_extension
17+
extension = PhoenixSlime.ConfiguredExtension.file_extension()
18+
1819
Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.layout.slime", binding, [
1920
{:eex, "app.html.eex", "#{web_prefix}/templates/layout/app.html.#{extension}"}
2021
])
@@ -23,7 +24,8 @@ defmodule Mix.Tasks.Phx.Gen.Layout.Slime do
2324
2425
A new #{web_prefix}/templates/layout/app.html.#{extension} file was generated.
2526
"""
26-
Mix.shell.info instructions
27+
28+
Mix.shell().info(instructions)
2729
end
2830

2931
defp slime_paths do

lib/phoenix_slime/engine.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule PhoenixSlime.Engine do
1212

1313
defp read!(file_path) do
1414
file_path
15-
|> File.read!
16-
|> Slime.Renderer.precompile
15+
|> File.read!()
16+
|> Slime.Renderer.precompile()
1717
end
1818
end

mix.exs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ defmodule PhoenixSlime.Mixfile do
77
[
88
app: :phoenix_slime,
99
deps: deps(),
10-
description: """
11-
Phoenix Template Engine for Slim-like templates
12-
""",
10+
description: "Phoenix Template Engine for Slim-like templates",
1311
elixir: "~> 1.4",
1412
package: package(),
1513
version: @version]

0 commit comments

Comments
 (0)