jfrolich / smoothie

Beautiful emails for your elixir application
MIT License
46 stars 5 forks source link

Smoothie should use @external_resource to declare its dependency on built templates #12

Open aaronjensen opened 7 years ago

aaronjensen commented 7 years ago

Right now, if a built template changes w/o running smoothie.compile (as it may if you were to check out a different branch that had a new template), the templates module will not be rebuilt and you may get compile errors.

I believe the proper thing for smoothie to do is to declare its dependency upon external files like the built templates.

Right now I'm working around this like this in my module that has use Smoothie

template_files_glob = Path.join(__DIR__, "templates/build/*")
template_files_glob
|> Path.wildcard
|> Enum.filter_map(&File.regular?/1, fn file ->
  @external_resource file
end)
aaronjensen commented 7 years ago

It's apparently not this simple. This works/helps for changes in existing templates as far as I can tell but it does not work when you add a new template.

Phoenix has this problem too and the way they solve it is somewhat involved.

The view modules export __phoenix_recompile__?/0 which is checked by a mix task that touches the file if it says yes before compilation.

jfrolich commented 7 years ago

@external_resource is used already. Indeed it might not detect new files. Good to figure out how phoenix does it and implement it as well. A way to resolve it when switching branches etc. is running mix clean.