Created
September 14, 2012 11:52
-
-
Save jmuheim/3721506 to your computer and use it in GitHub Desktop.
Rails signatures ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a Twitter Bootstrap nav item. | |
# | |
# @see http://twitter.github.com/bootstrap/components.html#navs | |
# | |
# @param [String optional] caption The caption of the item, optional if a block is passed | |
# @param [String optional] url The URL of the item | |
# @param [Hash] options | |
# @option options [Boolean] :brand (false) Set to true to define this item as the brand (this should be called directly on the `navbar` element itself as it also omits the surrounding `li` element) | |
# @option options [Boolean] :icon (nil) Pass the name of an icon (without the prefix `icon-`) to have an icon displayed to the left of the caption; see [available icons](http://twitter.github.com/bootstrap/base-css.html#icons) | |
# @return [String] HTML code | |
def item(*args, &block) | |
options = args.extract_options! | |
options.reverse_update({ | |
brand: false, | |
icon: false, | |
}) | |
caption, url = if block_given? | |
[capture(&block), args[0]] | |
else | |
[args[0], args[1]] | |
end | |
a_classes = [] | |
a_classes << 'brand' if options[:brand] | |
icon_content = (options[:icon] ? content_tag(:i, ' '.html_safe, class: "icon-#{options[:icon]}") : '').html_safe | |
content = link_to(url, class: a_classes.join(' ')) do | |
icon_content + caption | |
end | |
options[:brand] ? content : content_tag(:li, content) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought comments were editable... well, anyway, I meant: