Skip to content

Commit b5572ac

Browse files
authored
Merge pull request #156 from juanvico/juanvico/fix_torch_generator
Fix slime generator
2 parents 011569a + 48b1231 commit b5572ac

File tree

16 files changed

+164
-27
lines changed

16 files changed

+164
-27
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ plug(
4040
```
4141
config :torch,
4242
otp_app: :my_app_name,
43-
template_format: "eex" || "slim"
43+
template_format: "eex" || "slime"
4444
```
4545

4646
4. Run `mix torch.install`
4747

48-
**NOTE:** You can also choose to use `slim` templates, but you will need to
49-
first [install Phoenix Slim](https://github.com/slime-lang/phoenix_slime) and
50-
then update your configuration to specify `template_format: "slim"`.
48+
**NOTE:** You can also choose to use `slime` templates, but you will need to
49+
first [install Phoenix Slime](https://github.com/slime-lang/phoenix_slime) and
50+
then update your configuration to specify `template_format: "slime"`.
5151

5252
Now you're ready to start generating your admin! :tada:
5353

@@ -100,9 +100,9 @@ You will want to update it to include your new navigation link:
100100

101101
There may be times when you are adding Torch into an already existing system
102102
where your application already contains the modules and controllers and you just
103-
want to use the Torch admin interface. Since the `torch.gen` mix tasks are just
103+
want to use the Torch admin interface. Since the `torch.gen` mix tasks are just
104104
wrappers around the existing `phx.gen` tasks, you can use most of the same
105-
flags. To add an admin interface for `Posts` in the previous example, where the
105+
flags. To add an admin interface for `Posts` in the previous example, where the
106106
model and controller modules already exist, use the following command:
107107

108108
```bash
@@ -180,14 +180,14 @@ own stylesheet with the specific overrides.
180180

181181
## Internationalization
182182

183-
Torch comes with `.po` files for `en`, `ru` and `es` locales. If you are using
183+
Torch comes with `.po` files for `en`, `ru` and `es` locales. If you are using
184184
torch and can provide us with translation files for other languages, please
185-
submit a Pull Request with the translation file. We'd love to add as many
185+
submit a Pull Request with the translation file. We'd love to add as many
186186
translations as possible.
187187

188188
If you wish to add your own customized translations, you can configure Torch to
189-
use your own custom `MessagesBackend` and adding it in your Torch configuration
190-
settings in `config.exs`. You can find the all messages that can be customized
189+
use your own custom `MessagesBackend` and adding it in your Torch configuration
190+
settings in `config.exs`. You can find the all messages that can be customized
191191
in the default [i18n/backend.ex](lib/torch/i18n/backend.ex) file.
192192

193193
If you are customizing a backend for a "standard" spoken language, please submit
@@ -214,5 +214,5 @@ end
214214
config :torch,
215215
otp_app: :my_app_name,
216216
i18n_backend: MyApp.CustomMessagesBackend
217-
template_format: "eex" || "slim"
217+
template_format: "eex" || "slime"
218218
```

assets/css/theme/components/_table.sass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ section#torch-table
8181
max-width: 30px
8282

8383
button
84-
@extend %red-button
84+
@extend %red-button

lib/mix/tasks/torch.gen.html.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ defmodule Mix.Tasks.Torch.Gen.Html do
2727
Enum.each(@commands, &Mix.Torch.inject_templates(&1, format))
2828

2929
# Run the Phoenix generator
30-
Mix.Task.run("phx.gen.html", args)
30+
if format == "slime" do
31+
Mix.Task.run("phx.gen.html.slime", args)
32+
else
33+
Mix.Task.run("phx.gen.html", args)
34+
end
3135

3236
# Remove the injected templates from priv/ so they will not
3337
# affect future Phoenix generator commands

lib/mix/tasks/torch.install.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Mix.Tasks.Torch.Install do
1717
1818
Also accepts `--format` and `--app` options:
1919
20-
mix torch.install --format slim --app my_app
20+
mix torch.install --format slime --app my_app
2121
"""
2222

2323
def run(args) do

lib/mix/torch.ex

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Mix.Torch do
66
def parse_config!(task, args) do
77
{opts, _, _} = OptionParser.parse(args, switches: [format: :string, app: :string])
88

9-
format = opts[:format] || Config.template_format()
9+
format = convert_format(opts[:format] || Config.template_format())
1010
otp_app = opts[:app] || Config.otp_app()
1111

1212
unless otp_app do
@@ -22,18 +22,18 @@ defmodule Mix.Torch do
2222
""")
2323
end
2424

25-
unless format in ["eex", "slim"] do
25+
unless format in ["eex", "slime"] do
2626
Mix.raise("""
2727
Template format is invalid: #{inspect(format)}. Either configure it as
2828
shown below or pass it via the `--format` option.
2929
3030
config :torch,
31-
template_format: :slim
31+
template_format: :slime
3232
3333
# Alternatively
34-
mix #{task} --format slim
34+
mix #{task} --format slime
3535
36-
Supported formats: eex, slim
36+
Supported formats: eex, slime
3737
""")
3838
end
3939

@@ -53,13 +53,15 @@ defmodule Mix.Torch do
5353

5454
def inject_templates("phx.gen.html", format) do
5555
copy_from("priv/templates/#{format}/phx.gen.html", [
56+
{"edit.html.eex", "priv/templates/phx.gen.html/edit.html.eex"},
57+
{"form.html.eex", "priv/templates/phx.gen.html/form.html.eex"},
58+
{"index.html.eex", "priv/templates/phx.gen.html/index.html.eex"},
59+
{"new.html.eex", "priv/templates/phx.gen.html/new.html.eex"},
60+
{"show.html.eex", "priv/templates/phx.gen.html/show.html.eex"},
61+
])
62+
copy_from("priv/templates/common/phx.gen.html", [
5663
{"controller_test.exs", "priv/templates/phx.gen.html/controller_test.exs"},
5764
{"controller.ex", "priv/templates/phx.gen.html/controller.ex"},
58-
{"edit.html.#{format}", "priv/templates/phx.gen.html/edit.html.#{format}"},
59-
{"form.html.#{format}", "priv/templates/phx.gen.html/form.html.#{format}"},
60-
{"index.html.#{format}", "priv/templates/phx.gen.html/index.html.#{format}"},
61-
{"new.html.#{format}", "priv/templates/phx.gen.html/new.html.#{format}"},
62-
{"show.html.#{format}", "priv/templates/phx.gen.html/show.html.#{format}"},
6365
{"view.ex", "priv/templates/phx.gen.html/view.ex"}
6466
])
6567
end
@@ -85,4 +87,7 @@ defmodule Mix.Torch do
8587
def remove_templates(template_dir) do
8688
File.rm_rf("priv/templates/#{template_dir}/")
8789
end
90+
91+
defp convert_format("slim"), do: "slime"
92+
defp convert_format(format), do: format
8893
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
html
2+
head
3+
title Admin
4+
/ Uncomment to just use the bare bones torch styles rather than the theme
5+
/link rel="stylesheet" href="#{Routes.static_path(@conn, "/torch/base.css")}"
6+
link rel="stylesheet" href="#{Routes.static_path(@conn, "/torch/theme.css")}"
7+
8+
body class="#{Torch.PageView.body_classes(@conn)}"
9+
header
10+
section id="torch-account-info"
11+
div class="torch-container"
12+
a href="/" user@example.com
13+
a href="/" Logout
14+
15+
section id="torch-nav"
16+
div class="torch-container"
17+
div class="torch-logo"
18+
a href="/"
19+
h3 Torch
20+
nav class="torch-nav"
21+
/ nav links here
22+
23+
= Torch.FlashView.render("_flash_messages.html", assigns)
24+
= @inner_content
25+
script src="#{Routes.static_path(@conn, "/torch/torch.js")}"

0 commit comments

Comments
 (0)