Skip to content

Add Projections for LiveComponent and JSON View Controllers #80

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lua/elixir/projectionist/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ local config = {
"end",
},
},
["lib/**/controllers/*_json.ex"] = {
type = "json",
alternate = "test/{dirname}/controllers/{basename}_json_test.exs",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}JSON do",
"end",
},
},
["test/**/controllers/*_json_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/controllers/{basename}_json.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}JSONTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}JSON",
"end",
},
},
["lib/**/components/*.ex"] = {
type = "component",
alternate = "test/{dirname}/components/{basename}_test.exs",
Expand All @@ -95,6 +114,26 @@ local config = {
"end",
},
},
["lib/**/live/*_component.ex"] = {
type = "livecomponent",
alternate = "test/{dirname}/live/{basename}_component_test.exs",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Component do",
" use {dirname|camelcase|capitalize}, :live_component",
"end",
},
},
["test/**/live/*_component_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/live/{basename}_component.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ComponentTest do",
" use {dirname|camelcase|capitalize}.ConnCase",
"",
" import Phoenix.LiveViewTest",
"end",
},
},
["lib/**/live/*_live.ex"] = {
type = "liveview",
alternate = "test/{dirname}/live/{basename}_live_test.exs",
Expand Down
20 changes: 20 additions & 0 deletions tests/projectionist_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe("projectionist", function()
})
end)

it("Ejson", function()
vim.cmd.Ejson("project_a_web/user")
vim.cmd.write()

assert.are.same(
vim.fn.readfile("lib/project_a_web/controllers/user_json.ex"),
{ "defmodule ProjectAWeb.UserJSON do", "end" }
)
end)

it("Ecomponent", function()
vim.cmd.Ecomponent("project_a_web/user")
vim.cmd.write()
Expand All @@ -66,6 +76,16 @@ describe("projectionist", function()
)
end)

it("Elivecomponent", function()
vim.cmd.Elivecomponent("project_a_web/user")
vim.cmd.write()

assert.are.same(
vim.fn.readfile("lib/project_a_web/live/user_component.ex"),
{ "defmodule ProjectAWeb.UserComponent do", " use ProjectAWeb, :live_component", "end" }
)
end)

it("Etask", function()
vim.cmd.Etask("foo.bar")
vim.cmd.write()
Expand Down