Class: Nav::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/nav/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}) {|_self| ... } ⇒ Builder

Returns a new instance of Builder.

Yields:

  • (_self)

Yield Parameters:

  • _self (Nav::Builder)

    the object that the method was called on



3
4
5
6
7
8
# File 'lib/nav/builder.rb', line 3

def initialize( template, options = {} )
  @template, @options = template, options
  @actions = []
  
  yield self if block_given?
end

Instance Method Details

#action(name = nil, options = {}, html_options = {}) ⇒ Object

Examples:

A basic action

action "Home", home_url
action "Tome, home_url, :current => true

Given a block

action do
  content_tag :span, "A simple text""
end

action :current => true do
  content_tag :span, "A simple text""
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nav/builder.rb', line 22

def action( name = nil, options = {}, html_options = {} )
  @actions << if block_given?
    [ yield, name || {}, {} ]
  else
    wrapper_options = {
      :current => html_options.delete(:current),
      :disabled => html_options.delete(:disabled),
      :force_current => html_options.delete(:force_current),
      :prepend => html_options.delete(:prepend),
      :append => html_options.delete(:append)
    }
  
    [ link_to(name, options, html_options), wrapper_options, options ]
  end
end

#to_sObject



38
39
40
# File 'lib/nav/builder.rb', line 38

def to_s
  ( :ul, actions.html_safe, @options ).html_safe if actions?
end