Skip to content

Instantly share code, notes, and snippets.

@yamaaki
Last active October 2, 2015 01:40
Show Gist options
  • Save yamaaki/ea7aeca4b3f8b0d4097e to your computer and use it in GitHub Desktop.
Save yamaaki/ea7aeca4b3f8b0d4097e to your computer and use it in GitHub Desktop.
class MaterializeRenderer < SimpleNavigation::Renderer::Base
def render(item_container)
data = hash_render(item_container)
list = []
data.each do |item|
unless item[:items]
options = { class: "waves-effect waves-teal #{item[:class].present? ? item[:class] : ''}" }
options[:method] = item[:method] if item[:method]
a = link_to item[:name], item[:url], options
li = content_tag :li, a, class: (item[:selected] ? 'active' : '')
list << li
else
lis = []
item[:items].each do |item2|
options = { class: 'waves-effect waves-teal' }
options[:method] = item2[:method] if item2[:method]
a = link_to item2[:name], item2[:url], options
li = content_tag :li, a, class: (item2[:selected] ? 'active' : '')
lis << li
end
ul = content_tag :ul, lis.join
div = content_tag :div, ul, class: 'collapsible-body'
options = { class: "collapsible-header waves-effect waves-teal #{item[:selected] ? 'active' : ''}" }
options[:method] = item[:method] if item[:method]
a = link_to item[:name], '#', options
li = content_tag :li, [a, div].join, class: (item[:selected] ? 'active' : '')
list << li
end
end
list.join.html_safe
end
def hash_render(item_container)
return nil unless item_container
item_container.items.map do |item|
{
items: hash_render(item.sub_navigation),
name: item.name,
selected: item.selected?,
url: item.url,
method: item.method,
class: item.html_options[:class],
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment