Project-relative `require`?

Yes that why. (It’s funny I made a post about a similar need recently)

All is not always directly possible with macro, but with some tricks it often possible to does what we need.

Actually, I found a solution without nested macro:

macro src(file)
  {% path = (__DIR__.starts_with?(ROOT) ? __DIR__[ROOT.size..] : __DIR__) %}
  {% path = path.gsub(%r{[^/]+}, "..").id  %}
  require "{{path[1..]}}/src/{{file.id}}"
end

src "./file.cr"
1 Like