Class: SimpleNavigation::Renderer::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple_navigation/rendering/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, Links, List, Text

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(options)

:nodoc:



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

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

Instance Attribute Details

- (Object) adapter (readonly)

Returns the value of attribute adapter



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

def adapter
  @adapter
end

- (Object) options (readonly)

Returns the value of attribute options



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

def options
  @options
end

Instance Method Details

- (Boolean) expand_all?

Returns:

  • (Boolean)


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

def expand_all?
  !!options[:expand_all]
end

- (Boolean) include_sub_navigation?(item)

Returns:

  • (Boolean)


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

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

- (Object) level



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

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

- (Object) render(item_container)

Renders the specified ItemContainer to HTML.

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



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

def render(item_container)
  raise 'subclass responsibility'
end

- (Object) render_sub_navigation_for(item)



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

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

- (Boolean) skip_if_empty?

Returns:

  • (Boolean)


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

def skip_if_empty?
  !!options[:skip_if_empty]
end