mayu-live/framework

Resolve components automatically when transforming so they don't have to be required explicitly

aalin opened this issue · 0 comments

aalin commented

Instead of requiring every component in the beginning of the file like this:

:ruby
  Heading = import("Layout/Heading")
  Section = import("Layout/Section")

%Section
  %Heading(level=1) Hello world

Maybe something like the following would be possible?

%Layout::Section
  %Layout::Heading(level=1) Hello world

I'm thinking a new module system would be nice, something like this:

App = ModuleSystem.new(File.join(__dir__, "app"))

# The following will resolve app/Components/Button.haml
App::Components::Button.haml

And inside app/Components/Button.haml, the constant M would refer to the current module.

:ruby
  # Get something from app/Components/Button.css
  M.css.class_names

%button
  %slot
  = if $icon
    -# This will get app/Components/Icon
    %M::Parent::Icon(name=$icon)
  = if $icon
    -# This will get app/Components/Icon
    %App::Components::Icon(name=$icon)

Or maybe cleaner to specify the full path always...

:ruby
  Icon = App::Components::Icon

%button
  %slot
  = if $icon
    %Icon(name=$icon)

Anyways, I think this way, it would be possible to generate type information for modules. And marshalling should work for classes defined inside components because all modules would have names.