Module: BootstrapRailsHelper

Defined in:
lib/bootstrap_rails_helpers/helpers.rb

Instance Method Summary collapse

Instance Method Details

active_li_link_to

options

:module
  The controller or module that defines what this <li> is active for.
:li_options
  Any valid options that you can pass to content_tag helper
:link_to_options
  Any valid options supported by the standard rails link_to helper
:icon
  CSS class name of the icon to be displayed with the link


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bootstrap_rails_helpers/helpers.rb', line 15

def active_li_link_to(link_text, link_to_path, options={})
  li_options      = options.fetch(:li_options, {})
  link_to_options = options.fetch(:link_to_options, {})
  icon_class      = options.fetch(:icon_class, nil)
  module_pattern  = options.fetch(:module, nil)
  action_pattern  = options.fetch(:action, nil)

  unless module_pattern.nil?
    module_match    = Regexp.escape(controller.class.to_s).match(module_pattern).present?
    action_match    = (action_pattern.nil?) ? true : Regexp.escape(action_name).match(action_pattern).present?
    active          = module_match && action_match
    

    # Mark the LI as active
    if active
      if li_options.key?(:class)
        css_classes = li_options[:class].split(/\s/)
        css_classes << "active"
        li_options[:class] = css_classes.join(' ')
      else
        li_options[:class] = "active"
      end
    end
  end
   
  link_text = (icon_class.blank?) ? link_text : "<i class=\"icon #{icon_class}\"></i> #{link_text}"
   
   :li, li_options do
    link_to link_to_path, link_to_options do
      link_text.html_safe
    end
  end
end

Breadcrumb Helper Generates HTML for displaying breadcrumbs.

Built for the Twitter Bootstrap CSS rules

USAGE

Will yield: Home / Section 1 / …

<% breadcrumbs(

{ :name => "Home", :path => path_to_link_to },
{ :name => "Section1", :path => path_to_link_to },
...

) %>

In your layout file, where you want the breadcrumbs to appear, add: <%= yield :breadcrumbs %>



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bootstrap_rails_helpers/helpers.rb', line 98

def breadcrumbs(*trail)
  html =  "<div id=\"breadcrumb_wrapper\">"
  html += "<div class=\"container\">"
  html += "<ul class=\"breadcrumb\">"
  trail.each_with_index do |step,idx|
    html += "<li>"
    html += (step[:path].blank?) ? step[:name] : "#{link_to step[:name], step[:path]}"
    html += "<span class=\"divider\">/</span>" unless idx == (trail.size - 1)
    html += "</li>"
  end
  html += "</ul>"
  html += "</div>"
  html += "</div>"

  content_for :breadcrumbs do
    html.html_safe
  end
end

button_link_to

If you want to include an icon with your button link, use the :icon_class option to specify which icon-class you want to use.

type can be any valid twitter bootstrap button type

btn-primary  => "primary"
btn-warning  => "warning"
btn-info     => "info"
btn-success  => "success"
btn-danger   => "danger"
btn-inverse  => "inverse"
btn-link     => "link" - Bootstrap v2.1.x ONLY


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bootstrap_rails_helpers/helpers.rb', line 64

def button_link_to(link_text, link_to_path, type=nil, options={})
  link_to_options = options.fetch(:link_to_options, {})
  icon_class      = options.fetch(:icon_class, nil)
  css_classes     = (link_to_options[:class] || []).split(/\s/)
  
  link_text = (icon_class.blank?) ? link_text : "<i class=\"icon #{icon_class}\"></i> #{link_text}"
  
  css_classes << "btn"
  css_classes << "btn-#{type}" unless type.blank?
  link_to_options[:class] = css_classes.join(" ")
  
  link_to link_to_path, link_to_options do
    link_text.html_safe
  end
end