Sha256: 74c8a22f6c8f33de470c7fa4058d011418af7be4e1691b46bfa80a517773ab7d

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

require 'active_support/core_ext/string'

module Tabulous
  class BootstrapRenderer < CombinedRenderer

    def tabs_html
      <<-HTML.strip_heredoc
        <ul class="nav nav-tabs">
          #{ tab_list_html }
        </ul>
      HTML
    end

  protected

    def tab_html(tab)
      return '' unless tab.visible?(@view)
      html = ''
      klass = ''
      klass << 'active' if tab.active?(@view)
      klass << ' disabled' unless tab.enabled?(@view)
      klass << ' dropdown' if tab.subtabs.any?
      klass.strip!
      if klass.empty?
        html << '<li>'
      else
        html << %Q{<li class="#{klass}">}
      end
      if tab.subtabs.empty?
        html << tab_link(tab)
      else
        html << tab_link_with_subtabs(tab)
      end
      html << "</li>"
      html
    end

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

    def tab_link_with_subtabs(tab)
      html = ''
      html << %Q{<a class="dropdown-toggle" data-toggle="dropdown" href="#">#{tab_text(tab)}<b class="caret"></b></a>}
      html << %Q{<ul class="dropdown-menu">}
      for subtab in tab.subtabs
        next unless subtab.visible?(@view)
        klass = (subtab.enabled?(@view) ? '' : 'disabled')
        if klass.empty?
          html << '<li>'
        else
          html << %Q{<li class="#{klass}">}
        end
        html << tab_link(subtab)
        html << "</li>"
      end
      html << "</ul>"
      html
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tabulous-2.1.4 lib/tabulous/renderers/bootstrap_renderer.rb
tabulous-2.1.3 lib/tabulous/renderers/bootstrap_renderer.rb
tabulous-2.1.2 lib/tabulous/renderers/bootstrap_renderer.rb
tabulous-2.1.1 lib/tabulous/renderers/bootstrap_renderer.rb
tabulous-2.1.0 lib/tabulous/renderers/bootstrap_renderer.rb