Module: ToolbarHelper

Includes:
SocialStream::ToolbarConfig
Defined in:
app/helpers/toolbar_helper.rb

Instance Method Summary collapse

Methods included from SocialStream::ToolbarConfig

#default_home_toolbar_menu, #default_profile_toolbar_menu

Instance Method Details

#home_toolbar_menuObject

Prints the home toolbar menu.



84
85
86
# File 'app/helpers/toolbar_helper.rb', line 84

def home_toolbar_menu
  default_home_toolbar_menu
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cache menu options for toolbar



79
80
81
# File 'app/helpers/toolbar_helper.rb', line 79

def menu_options #:nodoc:
  @menu_options ||= {}
end

#profile_toolbar_menu(subject = current_subject) ⇒ Object

Prints the home profile menu.



89
90
91
# File 'app/helpers/toolbar_helper.rb', line 89

def profile_toolbar_menu(subject=current_subject)
  default_profile_toolbar_menu(subject)
end

#render_items(items) ⇒ Object

Renders array of navigation items with simple_navigation



95
96
97
98
# File 'app/helpers/toolbar_helper.rb', line 95

def render_items(items)
  menu = render_navigation :items => items
  return raw menu
end

#toolbar(options = {}, &block) ⇒ Object

Define the toolbar content for your view. There are two typical cases, depending on the value of options

  • If present, render the profile menu for the subject

  • If blank, render the home menu

The menu option allows overwriting a menu slot with the content of the given block

Autoexpanding 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, “:option => :messages” in the mentioned example. This will try, automatically, to expand the section of the menu where its root list link, the one expanding the section, has an id equal to “#messages_menu”. If you use “:options => :contacts” it will try to expand “#contacts_menu”.

For now its working with :option => :messages, :contacts or :groups

Examples:

Render the home toolbar:

<% toolbar %>

Render the profile toolbar for a user:

<% toolbar :profile => @user %>

Render the home toolbar changing the messages menu option:

<% toolbar :option => :messages %>

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

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


41
42
43
44
45
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
71
72
73
74
# File 'app/helpers/toolbar_helper.rb', line 41

def toolbar(options = {}, &block)
  if options[:option] && block_given?
    menu_options[options[:option]] = capture(&block)
  end

  content = capture do
    if options[:profile]
      render :partial => 'toolbar/profile', :locals => { :subject => options[:profile] }
    else
      render :partial => 'toolbar/home'
    end
  end

  case request.format
  when Mime::JS
    response = "\n        $('#toolbar').html(\"\#{ escape_javascript(content) }\");\n        initMenu();\n        expandSubMenu('\#{ options[:option] }');\n        EOJ\n\n    response.html_safe\n  else\n  content_for(:toolbar) do\n  content\n  end\n  content_for(:javascript) do\n  <<-EOJ\n  expandSubMenu('\#{ options[:option] }');\n  EOJ\n  end\n  end\nend\n"