Module: Fluffery::Helpers::Elements
- Defined in:
- lib/fluffery/helpers/elements.rb
Instance Method Summary collapse
-
#button_link(txt, path, attrs = {}) ⇒ Object
Creates a common format for CSS buttons Example: button_link(‘Blog’, ‘/blog’) yields <a href=“/blog” class=“button”><span>Blog</span></a>.
-
#flash_messages(attrs = {}) ⇒ Object
Outputs all flash messages.
-
#form_for(record_or_name_or_array, *args, &block) ⇒ Object
Simply overriding the default form_for to add additional html options/attributes.
Instance Method Details
#button_link(txt, path, attrs = {}) ⇒ Object
Creates a common format for CSS buttons Example: button_link(‘Blog’, ‘/blog’) yields <a href=“/blog” class=“button”><span>Blog</span></a>
25 26 27 28 |
# File 'lib/fluffery/helpers/elements.rb', line 25 def (txt, path, attrs = {}) inline_classes = attrs.has_key?(:class) ? "#{attrs[:class]} " : "" link_to "<span>#{txt}</span>".html_safe, path, attrs.merge({ :class => "#{inline_classes}button" }) end |
#flash_messages(attrs = {}) ⇒ Object
Outputs all flash messages. This allows you to call <%= flash_messages %> once in your application’s layout file. The output is a div with the class flash_message, and the type used. It also renders a “close” tag, which can be overridden or set to “”. By default this is a span containing ‘X’
<div class=“flash_message error”>
Your error message from flash[:error]
<span>X</span>
</div>
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluffery/helpers/elements.rb', line 40 def (attrs = {}) wrapper = attrs.delete(:wrapper) || :div closer = attrs.delete(:close) || "<span>X</span>" classes = (attrs.key?(:class)) ? attrs[:class].split(' ') : [] classes << "flash_message" content = "" flash.each_key do |k| classes << "flash_message_#{k.to_s.underscore}" msg_attrs = attrs.merge(:class => [k.to_s, classes].flatten.join(' ')) content.concat content_tag(wrapper, "#{flash[k]} #{closer}".html_safe, msg_attrs).html_safe end content.html_safe end |
#form_for(record_or_name_or_array, *args, &block) ⇒ Object
Simply overriding the default form_for to add additional html options/attributes.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fluffery/helpers/elements.rb', line 7 def form_for(record_or_name_or_array, *args, &block) = args.last.is_a?(Hash) ? args.pop : {} [:html] ||= {} # Add support for the 'ajax' uploader. [:html].merge!('data-remote-uploadable' => true) if .delete(:remote_upload) # Add support for javascript validation. [:html].merge!('data-js-validatable' => true) if .delete(:validate) args = (args << ) super(record_or_name_or_array, *args, &block) end |