I’m wondering what the best practices are around naming and organizing LiveView
s and their components. How do you go about naming them, and how do you organize your directory structure?
I’m currently doing this (and I’m not in love with it, but maybe it’s OK)
» tree lib/widget_web/views/live/
lib/widget_web/views/live/
├── shared
│ └── x_live.ex ------------ # WidgetWeb.Shared.XLive
├── foo_live.ex -------------- # WidgetWeb.FooLiveView
└── table
├── components
│ └── row_component.ex - # WidgetWeb.TableLiveView.RowComponent
└── table_live.ex -------- # WidgetWeb.TableLiveView
I forgot where I found the following projectionist snippet, but it’s by default generating module names like WidgetWeb.Views.Live.FooView
which also kinda seems OK but a little too tied to the dir structure.
.projections.json
{
"lib/**/views/*_view.ex": {
"type": "view",
"alternate": "test/{dirname}/views/{basename}_view_test.exs",
"template": [
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
" use {dirname|camelcase|capitalize}, :view",
"end"
]
}
}
I’d love to hear your thoughts, thanks!