tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.09k stars 381 forks source link

View-component projections #574

Closed kirin121 closed 3 years ago

kirin121 commented 3 years ago

Hi. Nice tool! I'm using it for years.

I'm using https://github.com/github/view_component to build Rails views. With "Sidecar directory approach" every component has it's own "example_component" dir with 3-5 files:

app/components
├── ...
├── example_component
|   ├── component.rb
|   ├── component.scss
|   ├── component.haml
|   ├── component.spec
|   └── component.js
├── ...

Is there any way to setup multiple(3-5) alternatve projections per one file and use them all with different keybindings? So i would be able to navigate from one file, for instance - "component.rb", to any of those 4 alternative files with different keybindings. Something like this:

<Leader>r1 " follows to "component.rb" 
<Leader>r2 " follows to "component.spec" 
<Leader>r3 " follows to "component.haml"  
<Leader>r4 " follows to "component.js" 
<Leader>r5 " follows to "component.scss" 

Those keybindings just an example, maybe i will use mappings with different keys, but general idea is the same.

tpope commented 3 years ago

What you want isn't a perfect fit for how rails.vim works, but you could probably shoehorn it in with projections like these:

{
  "app/components/*_component/component.scss": {"type": "componentstylesheet", "affinity": "model"},
  "app/components/*_component/component.haml": {"type": "componentview", "affinity": "model"},
  ...
}

Then you'll get commands like :Ecomponentstylesheet, :Ecomponentview, etc, and you can map those commands to achieve the desired effect.

The weird part of that is "affinity": "model", which is a lie because it's a component not a model, but that will enable the commands to work with zero arguments.