mayu-live / framework

Mayu is a live updating server-side component-based VDOM rendering framework written in Ruby
https://mayu.live
GNU Affero General Public License v3.0
137 stars 4 forks source link

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

Closed aalin closed 5 months ago

aalin commented 1 year ago

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.