Module: ApplicationSidebarHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/application_sidebar_helper.rb

Overview

Helpers for displaying sidebars in pages.

Instance Method Summary collapse

Instance Method Details

Generates the link to the given sidebar item.

Parameters:

  • item

    The sidebar item.

Returns:

  • (String)

    The HTML string which will display the link.


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/application_sidebar_helper.rb', line 50

def link_to_sidebar_item(item)
  link_to(item[:path]) do
    concat(
      (:span, class: ['nav-icons']) do
        fa_icon item[:icon]
      end
    )
    concat(item[:title])
    concat(
      (:span, class: ['unread']) do
        badge(item[:unread]) if item[:unread] && item[:unread] > 0
      end
    )
  end
end

Defines the sidebar for the current page.

Parameters:

  • classes (Array<String>)

    An array of classes to apply to the sidebar container.

Returns:

  • (String)

    The buffer containing the markup for the sidebar.


24
25
26
27
28
29
30
# File 'app/helpers/application_sidebar_helper.rb', line 24

def sidebar(classes: ['col-lg-2', 'col-md-3', 'col-sm-4'])
  sidebar!

  render layout: 'layouts/sidebar', locals: { sidebar_classes: classes } do
    yield
  end
end

#sidebar!Object

Sets the current page to have a sidebar.

The view must still render the sidebar in its content area.


14
15
16
17
18
# File 'app/helpers/application_sidebar_helper.rb', line 14

def sidebar!
  content_for(:layout_sidebar) do
    'true'
  end
end

#sidebar?Boolean

Checks if the current page has a sidebar.

Returns:

  • (Boolean)

    True if there is a sidebar for the current page.


7
8
9
# File 'app/helpers/application_sidebar_helper.rb', line 7

def sidebar?
  content_for?(:layout_sidebar)
end

Display the given sidebar items.

Parameters:

  • items (Array)

    An array of sidebar items to be displayed.

  • classes (Array<String>)

    An array of classes to apply to the sidebar items container.

Returns:

  • (String)

    The HTML string which will display the sidebar items.


37
38
39
40
41
42
43
44
# File 'app/helpers/application_sidebar_helper.rb', line 37

def sidebar_items(items, classes: ['nav', 'nav-pills', 'nav-stacked'])
  sidebar!

  links = items.map { |item| link_to_sidebar_item(item) }
  (:ul, class: classes) do
    links.map { |link| concat((:li, link)) }
  end
end