Sha256: c73c34bb08a18e7b7c57ad827545cb95fefcf4edc19d23bbcb893c54ae1e3b4b

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module AbAdmin
  module Menu
    class Group < BaseGroup
      def initialize(title, options, &block)
        @menu_tree = []
        @title = title.is_a?(Symbol) ? I18n.t(title, scope: [:admin, :navigation]) : title
        @options = options
        instance_eval &block if block_given?
      end

      def render(template)
        return if @options[:if] && !call_method_or_proc_on(template, @options[:if])
        return if @options[:unless] && call_method_or_proc_on(template, @options[:unless])

        <<-HTML.html_safe
      <li class="dropdown">
        <a class="dropdown-toggle" href="#{@options[:url] || '#'}" >#{title(template)}<b class="caret"></b></a>
        <ul class="dropdown-menu">#{render_nested(template)}</ul>
      <li>
        HTML
      end

      private

      def title(template)
        return @title unless @options[:badge]
        badge = call_method_or_proc_on(template, @options[:badge])
        return @title if !badge || badge == 0
        "#{@title}&nbsp;<span class='badge badge-#{@options[:badge_type] || 'important'}'>#{badge}</span>".html_safe
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ab_admin-0.6.1 lib/ab_admin/menu/group.rb
ab_admin-0.6.0 lib/ab_admin/menu/group.rb