Class: Neuron::Navigation::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/neuron/navigation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, options = {}) ⇒ Title

Returns a new instance of Title.



17
18
19
20
21
22
23
# File 'lib/neuron/navigation.rb', line 17

def initialize(view, options = {})
  @view = view
  @navigation_title = nil
  @page_title = nil
  @head_title = nil
  @default_options = {title_separator: ''}.merge(options)
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



8
9
10
# File 'lib/neuron/navigation.rb', line 8

def default_options
  @default_options
end

#viewObject (readonly)

Returns the value of attribute view.



9
10
11
# File 'lib/neuron/navigation.rb', line 9

def view
  @view
end

Class Method Details



12
13
14
# File 'lib/neuron/navigation.rb', line 12

def navigation_title(controller, action = :index, options = {})
  I18n.t("navigation.#{controller}.#{action}", options)
end

Instance Method Details

#head_title(title = nil, options = {}) ⇒ Object



36
37
38
39
# File 'lib/neuron/navigation.rb', line 36

def head_title(title = nil, options = {})
  options = default_options.merge(options)
  @head_title ||= title.try(:to_s) || view.strip_tags([navigation_title, application.title].compact.join(options[:title_separator]))
end


31
32
33
34
# File 'lib/neuron/navigation.rb', line 31

def navigation_title(title = nil, options = {})
  options = {default: @page_title || view.view_name.humanize}.merge(default_options).merge(options)
  @navigation_title ||= title.try(:to_s) || self.class.navigation_title(view.controller_i18n_scope, view.view_name, options)
end

#page_title(title = nil, options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/neuron/navigation.rb', line 25

def page_title(title = nil, options = {})
  options = default_options.merge(options)
  options = options.merge(default: navigation_title(title, options))
  @page_title ||= title.try(:to_s) || view.t('.title', options)
end