Sha256: 520bdcf88f2342e77d50e5ad2156b4a7aba8518f0195903f3c996368bc09cd0a

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

module Georgia
  class SidebarLinkPresenter < Presenter

    attr_reader :text, :url, :icon, :options, :active, :sublink
    alias :active? :active
    alias :sublink? :sublink

    def initialize view_context, text, url, options={}
      @view_context = view_context
      @text = text
      @url = url
      @options = options
      @icon = options.fetch(:icon, 'bookmark-o')
      @active = options.fetch(:active) { get_active_state_from_controller }
      @sublink = options.fetch(:sublink, false)
      super
    end

    def to_s
      !sublink? ? render_link : render_sublink
    end

    def render_link
      content_tag :li, link_to(sidebar_link_bundle, url), class: "#{'active' if active?}"
    end

    def render_sublink
      content_tag :li, link_to(sidebar_title_tag, url), class: "#{'active' if active?}"
    end

    private

    def sidebar_link_bundle
      sidebar_title_icon + sidebar_title_tag + sidebar_arrow_icon
    end

    def sidebar_title_icon
      content_tag(:span, icon_tag(icon), class: 'icon')
    end

    def sidebar_arrow_icon
      content_tag(:span, icon_tag("angle-#{active? ? 'right' : 'left'}"), class: 'arrow')
    end

    def sidebar_title_tag
      content_tag(:h5, text, class: 'sidebar-link-name')
    end

    def get_active_state_from_controller
      controller = options.fetch(:controller)
      controller.is_a?(Array) ? controller.include?(controller_name) : (controller_name == controller)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/presenters/georgia/sidebar_link_presenter.rb