Module: ToolbarHelper

Includes:
SocialStream::Views::Toolbar
Defined in:
app/helpers/toolbar_helper.rb

Overview

The toolbar is the left-side bar in Social Stream’s layout

Instance Method Summary collapse

Instance Method Details

#toolbar(type = :home, options = {}) ⇒ Object

This method define the toolbar content for your view. The toolbar is at the left side of the screen in vanilla SocialStream distribution.

The type argument chooses diffent configurations. There are three build-in cases:

  • :home, render the home menu

  • :profile, render the profile menu for the subject this type needs a :subject option with the subject in the sidebar

  • :messages, render the messages menu

Autoexpand a menu section on your view:

Toolbar allows you to autoexpand certain menu section that may be of interest for your view. For example, the messages menu when you are looking your inbox. This is done through :option element.

To get it working, you should use the proper :option to be expanded. For instance, “:options => :contacts” it will try to expand “#contacts_menu”.

Examples:

Render the home toolbar:

<% toolbar %>

or

<% toolbar :home %>

Render the profile toolbar for a user:

<% toolbar :profile, :subject => @user %>

Render the messages menu:

<% toolbar :messages %>

Render the profile toolbar for group changing the contacts menu option:

<% toolbar :profile, :subject => @group, :option => :contacts %>


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/toolbar_helper.rb', line 46

def toolbar(type = :home, options = {})
  content = toolbar_items(type, options).inject(ActiveSupport::SafeBuffer.new){ |result, item|
    result + item[:html]
  }

  case request.format
  when Mime::JS
    response = <<-EOJ
      $('#toolbarContent').html("#{ escape_javascript(content) }");
      SocialStream.Toolbar.init({ option: '#{ options[:option] }' });
    EOJ

    response.html_safe
  else
    content_for(:toolbar) do
      content
    end

    content_for(:javascript) do
    <<-EOJ
      SocialStream.Toolbar.init({ option: '#{ options[:option] }' });
    EOJ
    end
  end
end

#toolbar_menu(type, options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'app/helpers/toolbar_helper.rb', line 72

def toolbar_menu(type, options = {})
  ActiveSupport::SafeBuffer.new.tap do |menu|
    menu << '<div class="toolbar_menu">'.html_safe

    toolbar_menu_render(toolbar_menu_items(type, options), menu)

    menu << '</div>'.html_safe
  end
end

#toolbar_menu_render(items, menu) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/toolbar_helper.rb', line 82

def toolbar_menu_render(items, menu)
  menu << '<ul>'.html_safe
  items.each do |item|
    menu << '<li>'.html_safe

    menu << item[:html]
    if item[:items].present?
      toolbar_menu_render(item[:items], menu)
    end

    menu << '</li>'.html_safe
  end
  menu << '</ul>'.html_safe
end