-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generators #53
Add generators #53
Conversation
Simply look how Here you have app Here you have
Short: don't complicate and simply raise 😈 If you really want you can add |
Thanks for looking over this with me @Eiji7 ! One bothersome detail is that the tests are failing for the |
You have 2 options:
Application.put_env(String.to_atom(@app_name), :namespace, String.to_atom(@module_name)) |
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
If you apply above suggestions to |
Before merge we would need a simple cleanup:
|
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
It would be nice if you could add 2 extra changes: def tmp_path do
Path.expand("../tmp", __DIR__)
end
# …
def in_tmp(which, function) do
path = Path.join([tmp_path(), random_string(10), to_string(which)])
try do
File.rm_rf!(path)
File.mkdir_p!(path)
File.cd!(path, function)
after
path |> Path.dirname() |> File.rm_rf!()
end
end The first in Secondly |
Regarding tests here goes for @scene_module "TestScene"
@scene_name "test_scene"
test "gen.scene" do
in_project("new with defaults", "my_app", fn _mix_project ->
output = capture_io(fn -> Mix.Tasks.Scenic.Gen.Scene.run([@scene_module]) end)
module_definition = "defmodule MyApp.Scene.#{@scene_module} do"
assert_file("lib/scenes/#{@scene_name}.ex", module_definition)
assert output =~ "Created scene #{@scene_module}."
end)
end
test "gen.scene inside umbrella" do
in_project("umbrella", "my_umbrella", ["--umbrella"], Mix.Tasks.New, fn _mix_project ->
func = fn -> Mix.Tasks.Scenic.Gen.Scene.run([]) end
assert_raise Mix.Error, func
end)
end
test "gen.scene with app" do
in_project("new with app", "my_app", ["--module", "My.App"], fn _mix_project ->
args = [@scene_module, "--app", "My.App"]
output = capture_io(fn -> Mix.Tasks.Scenic.Gen.Scene.run(args) end)
assert output =~ "Created scene #{@scene_module}."
module_definition = "defmodule My.App.Scene.#{@scene_module} do"
assert_file("lib/scenes/#{@scene_name}.ex", module_definition)
end)
end
test "gen.scene without args displays help" do
in_project("help", "help", fn _mix_project ->
output1 = capture_io(fn -> Mix.Tasks.Scenic.Gen.Scene.run([]) end)
output2 = capture_io(fn -> Mix.Tasks.Help.run(["scenic.gen.scene"]) end)
assert output1 == output2
end)
end
defp in_project(tmp_dir, app_name, extra_args \\ [], task \\ Mix.Tasks.Scenic.New, project_func) do
in_tmp(tmp_dir, fn ->
capture_io(fn -> task.run([app_name | extra_args]) end)
app_name |> String.to_atom() |> Mix.Project.in_project(app_name, project_func)
end)
end |
And for @component_module "TestComponent"
@component_name "test_component"
test "gen.component" do
in_project("new with defaults", "my_app", fn _mix_project ->
output = capture_io(fn -> Mix.Tasks.Scenic.Gen.Component.run([@component_module]) end)
module_definition = "defmodule MyApp.Component.#{@component_module} do"
assert_file("lib/components/#{@component_name}.ex", module_definition)
assert output =~ "Created component #{@component_module}."
end)
end
test "gen.component inside umbrella" do
in_project("umbrella", "my_umbrella", ["--umbrella"], Mix.Tasks.New, fn _mix_project ->
func = fn -> Mix.Tasks.Scenic.Gen.Component.run([]) end
assert_raise Mix.Error, func
end)
end
test "gen.component with app" do
in_project("new with app", "my_app", ["--module", "My.App"], fn _mix_project ->
args = [@component_module, "--app", "My.App"]
output = capture_io(fn -> Mix.Tasks.Scenic.Gen.Component.run(args) end)
assert output =~ "Created component #{@component_module}."
module_definition = "defmodule My.App.Component.#{@component_module} do"
assert_file("lib/components/#{@component_name}.ex", module_definition)
end)
end
test "gen.component without args displays help" do
in_project("help", "help", fn _mix_project ->
output1 = capture_io(fn -> Mix.Tasks.Scenic.Gen.Component.run([]) end)
output2 = capture_io(fn -> Mix.Tasks.Help.run(["scenic.gen.component"]) end)
assert output1 == output2
end)
end
defp in_project(tmp_dir, app_name, extra_args \\ [], task \\ Mix.Tasks.Scenic.New, project_func) do
in_tmp(tmp_dir, fn ->
capture_io(fn -> task.run([app_name | extra_args]) end)
app_name |> String.to_atom() |> Mix.Project.in_project(app_name, project_func)
end)
end Look that Those changes should satisfy |
Okay, that should get us into a happier spot. |
After that remove |
Co-authored-by: Tomasz Marek Sulima <Eiji7@users.noreply.github.com>
Okiedokie, let's get @boydm to take a look. |
Only update `new`, `gen_scene`, and `gen_component` Switch to scenic_driver_local Add a usage statement for gen_component A few stylistic changes Switch build_embedded to false to workaround a bug Switch the scenic dep to the v0.11 branch (will need to be updated once a release is cut)
Update to Scenic v0.11
Broughtt in the awesome work @axelson did! |
@crertel This code is unfortunately invalid now as |
I'm doing cleanup right now, and switched us over to the hex v0.11 RC. More on the way. |
@boydm Should be ready for proper consideration now! |
Talked to Boyd today; we're going to move the generators over to single-file mix tasks in core scenic (and swap the templates for heredocs), and then move @axelson 's work here for |
Sounds good 👍 |
Talked to Cretel. The generators are better off in the main scenic tasks and should not go into scenic_new. @axelson, sorry but I've done a bunch of work to scenic_new and now I'm thinking it would be too hard to merge your changes in. Take a look at the current version and lets talk if there are things you want to do to it. |
This PR is about adding
mix scenic.gen.scene
andmix scenic.gen.component
helpers.It's currently a work in progress, but if this is looking like a good idea we can wrap it up.
Current questions are:
MyApp
inMyApp.Scenes.SceneName
when we've runmix scenic.gen.scene scene_name
?