komposable / komponent

An opinionated way of organizing front-end code in Ruby on Rails, based on components
http://komponent.io
MIT License
427 stars 31 forks source link

Question - What is the proper way to organize subdomain-specific components ? #168

Open tdutreui opened 3 years ago

tdutreui commented 3 years ago

Hi guys :) Hope you're fine ! First, thank you for this very nice gem.

I'm currently setting up Komponent 2.2.0 in our Rails app with subdomains and I would like to completely dissociate their frontends, let's say :

domain.net
pro.domain.net

Problem : With 2 different komponent root directories, a conflict regarding the components ruby classes occurs because the modules have the same name.

Example for an "icon" component :

./frontend/components/icon/_icon.html.slim
./frontend-pro/components/icon/_icon.html.slim

Using component 'icon' on the pro subdomain views resolves the ruby class IconComponent of ./frontend instead of ./frontend-pro. The _icon.html.slim partial is correctly resolved (using prepend_view_path as stated in your doc)

I guess I should not change Rails.application.config.komponent.component_paths using before_action in a "pro" controller since its shared between subdomains, and changing global config on each request seems dangerous.

I would like to avoid namespacing my entire 'pro' component directory like ./frontend-pro/components/pro/icon/_pro_icon.html.slim since it does not look clean.

What do you advise?