techiferous/tabulous

Open tab to a new window with :target => "_blank"

Closed this issue · 3 comments

jbat commented

I have a request for a menu option to open to an external help section in another browser tab. It looks like this is not possible with the current implementation of the link_path method. Do you have any tips as to how I could get this working.
Thanks for your great work on this Gem!

Writing a custom renderer will do the trick for you, since a custom renderer gives you complete control over the HTML that's produced. Note that Tab objects have a name attribute, which you can use in your custom renderer to tack on a target="_blank" attribute to an anchor tag for a particularly named tab.

It's not 100% ideal because then your tabs are not being described completely in your tabulous.rb file, but this should work.

jbat commented

Thanks for that tip .. I was trying to extend the parent Tab Class and add a link_target method but got a bit lost. Ended up adding the following in an initializer giving the ability to call a subtab something like help_home_blank_subtab. ie any object with tab.name ending in _blank opens to target='_blank'

module Tabulous

  class ExtendBootstrapNavbarRenderer < BootstrapNavbarRenderer  
    def tab_link(tab)
      html = ''
      if tab.clickable?(@view) && tab.enabled?(@view)
        html << %Q{<a href="#{tab_url(tab)}" #{tab_target(tab)} #{tab_http_verb_attributes(tab)}>#{tab_text(tab)}</a>}
      else
        html << %Q{<a>#{tab_text(tab)}</a>}
      end
      html
    end

    def tab_target(tab)            
      if tab.name[-6..-1] == '_blank'
        %Q{target="_blank"}            
      end
    end

  end
end

Great! Glad you got it working.

By the way, if you don't want that code to live in an initializer, you can put it directly in app/tabs.