Module: RailsStuff::Helpers::Text

Included in:
All
Defined in:
lib/rails_stuff/helpers/text.rb

Instance Method Summary collapse

Instance Method Details

#blank_placeholderObject

Default placeholder value.



21
22
23
24
25
# File 'lib/rails_stuff/helpers/text.rb', line 21

def blank_placeholder
  @_blank_placeholder ||=  :small,
    "(#{I18n.t(:'helpers.placeholder.blank', default: '-')})",
    class: :'text-muted'
end

#replace_blank(value, &block) ⇒ Object

Replaces blank values with cached placeholder from translations. When called with block, it’ll check value for blankness, but returns block’s result if value is present.

replace_blank(description)
replace_blank(tags) { tags.join(', ') }
replace_blank(order.paid_at) { |x| l x, format: :long }


12
13
14
15
16
17
18
# File 'lib/rails_stuff/helpers/text.rb', line 12

def replace_blank(value, &block)
  if value.blank?
    blank_placeholder
  else
    block_given? ? capture(value, &block) : value
  end
end