techiferous / tabulous

Easy tabbed navigation for Rails
Other
322 stars 35 forks source link

Converting old syntax to new DSL (special case) #27

Closed jh125486 closed 11 years ago

jh125486 commented 11 years ago

Howdy, In the old syntax I was able to insert dynamic tabs/subtabs into the tabs array. For example if I wanted a tab named "Cars", and subtabs with links to each car under "Cars":

Tabuluous.setup do |config| config.tabs do [ [:cars_tab, 'Cars', cars_path, true, true], *Car.order(:name).map { |car| [ "#{car.name}_subtab".to_sym, car.name, car_path(car)], true, true]}, ] end end

Ugly, but this would produce: ,, tabs: | Cars | ,____, ,____, ,__, subtabs: | Mustang |__| Corvette |_| Prius |

Unfortunately since tabs/subtabs are created through method_missing in the new DSL, my ruby-fu isn't strong enough to figure this out. I've tried 'define_method', but my meta-programming is too weak at this point: Cars.order(:name).each do |car| define_method "#{car.name}_subtab".underscore.to_sym do text { car.name} link_path { cars_path(car } visible_when { true } enabled_when { true } active_when { in_action('show').of_controller('cars') } end end

jh125486 commented 11 years ago

Sorry for the poor formatting of the code. I'm only authorized IE8 at work, and github barely works with this old browser.

techiferous commented 11 years ago

Ah, I see what you're doing. This is the ruby-fu that you need: use the send method. It takes a symbol or a string that's the name of the method you wish to call.

send("#{car.name}_subtab") do
  text { car.name}
  link_path { cars_path(car }
  visible_when { true }
  enabled_when { true }
  active_when { in_action('show').of_controller('cars') }
end
jh125486 commented 11 years ago

Awesome. Thanks for the help!

techiferous commented 11 years ago

You're welcome!