Module: Loaf::CrumbFormatter

Included in:
ViewExtensions
Defined in:
lib/loaf/crumb_formatter.rb

Overview

A mixin for formatting crumb name

Instance Method Summary collapse

Instance Method Details

#format_name(name, options = {}) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/loaf/crumb_formatter.rb', line 10

def format_name(name, options = {})
  return name if name.nil? || name.empty?

  formatted = name.to_s.dup
  formatted = Loaf::Translation.find_title(formatted)
  formatted = formatted.capitalize if options[:capitalize]
  if options[:crumb_length]
    formatted = truncate(formatted, length: options[:crumb_length])
  end
  formatted
end