Skip to content

Instantly share code, notes, and snippets.

@tlux
Created February 6, 2013 16:08
Show Gist options
  • Save tlux/4723612 to your computer and use it in GitHub Desktop.
Save tlux/4723612 to your computer and use it in GitHub Desktop.
def placehold_if(condition, options = {}, &block)
if condition
placeholder_class = options.fetch(:class, 'placeholder')
content_tag(:span, options[:with], class: placeholder_class) if options[:with]
else
capture(&block)
end
end
def placehold_unless(condition, options = {}, &block)
placehold_if(!condition, options, &block)
end
# Usage:
#
# <%= placehold_if @movie.blank?, with: '-' do %>
# <div id="container">
# Some custom content
# </div>
# <% end %>
#
# <%= placehold_unless @movie.present?, with: '-' do %>
# <div id="container">
# Some custom content
# </div>
# <% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment