Module: Spyro::ActionViewExtension::PageTitle

Included in:
ApplicationHelper
Defined in:
lib/spyro/helpers/action_view_extension.rb

Instance Method Summary collapse

Instance Method Details

#page_title(key, options) ⇒ Object



696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/spyro/helpers/action_view_extension.rb', line 696

def page_title key, options
  prefix = I18n.t('page_title.prefix', :raise => true) rescue []
  suffix = I18n.t('page_title.suffix', :raise => true) rescue []

  key = [*key]
  title = ""
  while key.any? and title.blank?
    title = I18n.t(['page_title', *key].join('.'), :raise => true) rescue nil
    key.pop if key.last == "default"
    key[-1] = "default" if key.any?
  end

  title = (title.blank? ? options[:default] : [prefix, title, suffix].flatten.compact.join(options[:separator] || ' - '))
  title.gsub(/\{\{([^\}]+)\}\}/) { $1.split('.').inject(self) { |base, method| base.send(method) } }
rescue
  options[:default].gsub(/\{\{([^\}]+)\}\}/) { $1.split('.').inject(self) { |base, method| base.send(method) } }
end