Created
February 6, 2013 16:08
-
-
Save tlux/4723612 to your computer and use it in GitHub Desktop.
This file contains 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
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