Module: BootstrapRailsHelper
- Defined in:
- lib/bootstrap_rails_helpers/helpers.rb
Instance Method Summary collapse
-
#active_li_link_to(link_text, link_to_path, options = {}) ⇒ Object
active_li_link_to ============================== options :module The controller or module that defines what this <li> is active for.
-
#breadcrumbs(*trail) ⇒ Object
Breadcrumb Helper Generates HTML for displaying breadcrumbs.
-
#button_link_to(link_text, link_to_path, type = nil, options = {}) ⇒ Object
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.
Instance Method Details
#active_li_link_to(link_text, link_to_path, options = {}) ⇒ Object
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, ={}) = .fetch(:li_options, {}) = .fetch(:link_to_options, {}) icon_class = .fetch(:icon_class, nil) module_pattern = .fetch(:module, nil) action_pattern = .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 .key?(:class) css_classes = [:class].split(/\s/) css_classes << "active" [:class] = css_classes.join(' ') else [:class] = "active" end end end link_text = (icon_class.blank?) ? link_text : "<i class=\"icon #{icon_class}\"></i> #{link_text}" content_tag :li, do link_to link_to_path, do link_text.html_safe end end end |
#breadcrumbs(*trail) ⇒ Object
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 (*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(link_text, link_to_path, type = nil, options = {}) ⇒ Object
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 (link_text, link_to_path, type=nil, ={}) = .fetch(:link_to_options, {}) icon_class = .fetch(:icon_class, nil) css_classes = ([: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? [:class] = css_classes.join(" ") link_to link_to_path, do link_text.html_safe end end |