Class: Kin::Nav::Formatters::Basic
- Inherits:
-
Object
- Object
- Kin::Nav::Formatters::Basic
- Includes:
- Merb::Helpers::Tag
- Defined in:
- lib/kin/nav/formatters.rb
Overview
Receives a nav instance and transforms it into HTML.
Instance Method Summary collapse
-
#initialize(nav, controller, options) ⇒ Basic
constructor
Creates a new BasicFormatter instance.
-
#to_html ⇒ String
Transforms the menu given to
initializeinto a string containing HTML.
Constructor Details
#initialize(nav, controller, options) ⇒ Basic
Creates a new BasicFormatter instance.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kin/nav/formatters.rb', line 25 def initialize(nav, controller, ) @nav = nav @current = nav.active_item(controller) @resource = [:resource] @inject = .fetch(:inject, {}) @guards = .fetch(:guard, {}) # Escape injected content. @inject.each do |item_id, contents| contents = Array(contents) contents.map! { |v| Merb::Parse.escape_xml(v) } @inject[item_id] = contents end end |
Instance Method Details
#to_html ⇒ String
Transforms the menu given to initialize into a string containing HTML.
51 52 53 54 55 |
# File 'lib/kin/nav/formatters.rb', line 51 def to_html '<ul>%s</ul>' % @nav.items.map do |item| trasform_item_to_html(item) if item.display?(@guards) end.join("\n") end |