Class: SimpleNavigation::Renderer::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple_navigation/renderer/base.rb

Overview

This is the base class for all renderers.

A renderer is responsible for rendering an ItemContainer and its containing items to HTML.

Direct Known Subclasses

Breadcrumbs, Json, Links, List, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

:nodoc:



16
17
18
19
# File 'lib/simple_navigation/renderer/base.rb', line 16

def initialize(options) #:nodoc:
  @options = options
  @adapter = SimpleNavigation.adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/simple_navigation/renderer/base.rb', line 12

def adapter
  @adapter
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/simple_navigation/renderer/base.rb', line 12

def options
  @options
end

Instance Method Details

#expand_all?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/simple_navigation/renderer/base.rb', line 21

def expand_all?
  !!options[:expand_all]
end

#include_sub_navigation?(item) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/simple_navigation/renderer/base.rb', line 33

def include_sub_navigation?(item)
  consider_sub_navigation?(item) && expand_sub_navigation?(item)
end

#levelObject



25
26
27
# File 'lib/simple_navigation/renderer/base.rb', line 25

def level
  options[:level] || :all
end

#render(item_container) ⇒ Object

Renders the specified ItemContainer to HTML.

When implementing a renderer, please consider to call include_sub_navigation? to determine whether an item’s sub_navigation should be rendered or not.



46
47
48
# File 'lib/simple_navigation/renderer/base.rb', line 46

def render(item_container)
  fail NotImplementedError, 'subclass responsibility'
end

#render_sub_navigation_for(item) ⇒ Object



37
38
39
# File 'lib/simple_navigation/renderer/base.rb', line 37

def render_sub_navigation_for(item)
  item.sub_navigation.render(options)
end

#skip_if_empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/simple_navigation/renderer/base.rb', line 29

def skip_if_empty?
  !!options[:skip_if_empty]
end