Class: LcpRuby::Display::Renderers::Truncate

Inherits:
BaseRenderer show all
Defined in:
lib/lcp_ruby/display/renderers/truncate.rb

Instance Method Summary collapse

Methods inherited from BaseRenderer

#link_producing?

Instance Method Details

#render(value, options = {}, record: nil, view_context: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/lcp_ruby/display/renderers/truncate.rb', line 5

def render(value, options = {}, record: nil, view_context: nil)
  max = (options["max"] || 50).to_i
  text = value.to_s
  if text.length > max
    view_context.(:span, view_context.truncate(text, length: max), title: text)
  else
    text
  end
end