Module: Motr::Helpers::Elements
- Defined in:
- lib/motr/helpers/elements.rb
Overview
Generates misc html elements that aren’t included in Rails core, or are custom.
Instance Method Summary collapse
-
#button_link(txt, path, attrs = {}, incl_span = false) ⇒ Object
Generates a “button” link tag.
-
#flash_messages(attrs = {}) ⇒ Object
Convenience method for outputting all current flash messages.
Instance Method Details
#button_link(txt, path, attrs = {}, incl_span = false) ⇒ Object
Generates a “button” link tag. Simply a convenience method to skip adding ‘class=“button”’ and also adds an icon
option
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/motr/helpers/elements.rb', line 22 def (txt, path, attrs = {}, incl_span = false) image = attrs.delete(:icon) klasses = (attrs.delete(:class) || "").split(" ") klasses << 'button' klasses = klasses.uniq.compact content = "" content << image_tag(image) unless image.nil? content << (incl_span ? "<span>#{txt}</span>" : txt) link_to content.html_safe, path, attrs.merge(:class => klasses.join(" ")) end |
#flash_messages(attrs = {}) ⇒ Object
Convenience method for outputting all current flash messages. This allows you to avoid using things like “if flash” and so on, which is far from DRY
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/motr/helpers/elements.rb', line 52 def (attrs = {}) return if flash.nil? or flash.empty? wrapper = attrs.delete(:wrapper) || :div closer = attrs.delete(:closer) unless closer === false closer ||= "<span>X</span>" end klasses = (attrs.delete(:class) || "").split(" ") klasses << "flash_message" content = "" flash.each do |key, value| klasses << "flash_message_#{key.to_s.underscore}" msg_attrs = attrs.merge(:class => [key.to_s, klasses].flatten.join(' ')) content.concat content_tag(wrapper, "#{value} #{closer}".html_safe, msg_attrs).html_safe end content.html_safe end |