@@ -37,34 +37,43 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
37
37
default_opts = Application . get_env ( :phoenix , :generators , [ ] )
38
38
opts = Keyword . merge ( default_opts , opts )
39
39
40
- attrs = Mix.Phoenix.Schema . attrs ( attrs )
40
+ attrs = Mix.Phoenix.Schema . attrs ( attrs )
41
41
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
+ ]
50
58
51
59
Mix.Phoenix . check_module_name_availability! ( binding [ :module ] <> "Controller" )
52
60
Mix.Phoenix . check_module_name_availability! ( binding [ :module ] <> "View" )
53
61
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
+ ] )
68
77
69
78
instructions = """
70
79
@@ -74,9 +83,9 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
74
83
"""
75
84
76
85
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 ] )
78
87
else
79
- Mix . shell . info instructions
88
+ Mix . shell ( ) . info ( instructions )
80
89
end
81
90
end
82
91
@@ -92,8 +101,12 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
92
101
cond do
93
102
String . contains? ( plural , ":" ) ->
94
103
raise_with_help ( )
104
+
95
105
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
+
97
110
true ->
98
111
args
99
112
end
@@ -104,41 +117,54 @@ defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do
104
117
end
105
118
106
119
defp raise_with_help do
107
- Mix . raise """
120
+ Mix . raise ( """
108
121
mix phoenix_slime.gen.html expects both singular and plural names
109
122
of the generated resource followed by any number of attributes:
110
123
111
124
mix phoenix_slime.gen.html User users name:string
112
- """
125
+ """ )
113
126
end
114
127
115
128
defp inputs ( attrs ) do
116
- Enum . map attrs , fn
129
+ Enum . map ( attrs , fn
117
130
{ _ , { :array , _ } } ->
118
131
{ nil , nil , nil }
132
+
119
133
{ _ , { :references , _ } } ->
120
134
{ nil , nil , nil }
121
- { key , :integer } ->
135
+
136
+ { key , :integer } ->
122
137
{ 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 } ->
128
148
{ label ( key ) , ~s( = checkbox f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
129
- { key , :text } ->
149
+
150
+ { key , :text } ->
130
151
{ label ( key ) , ~s( = textarea f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
131
- { key , :date } ->
152
+
153
+ { key , :date } ->
132
154
{ label ( key ) , ~s( = date_select f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
133
- { key , :time } ->
155
+
156
+ { key , :time } ->
134
157
{ label ( key ) , ~s( = time_select f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
135
- { key , :utc_datetime } ->
158
+
159
+ { key , :utc_datetime } ->
136
160
{ label ( key ) , ~s( = datetime_select f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
137
- { key , :naive_datetime } ->
161
+
162
+ { key , :naive_datetime } ->
138
163
{ label ( key ) , ~s( = datetime_select f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
139
- { key , _ } ->
164
+
165
+ { key , _ } ->
140
166
{ label ( key ) , ~s( = text_input f, #{ inspect ( key ) } , class: "form-control") , error ( key ) }
141
- end
167
+ end )
142
168
end
143
169
144
170
defp label ( key ) do
0 commit comments