Sha256: 7338ff406af25644cde7f08243da5dc6bb63086745d60c5a765e9c16bffaf584
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
module MenuMaker class MenuRenderer attr_accessor :menu attr_reader :current_path, :helpers alias_method :h, :helpers def self.render(&block) define_method :render do build_html do instance_eval(&block) end end end def initialize(helpers, path = nil) @helpers = helpers @current_path = find_current_path(path) end def build_menu build_html do menu.items.inject('') do |out, item| out + yield(item, []) end end end def build_html output = yield '' if output.respond_to? :html_safe output.html_safe else output end end def call(menu) self.menu = menu render end private def find_current_path(current_path) @current_path = current_path || request_path || '' end def helpers_has_request? helpers.respond_to?(:request) && helpers.request.respond_to?(:path) end def request_path helpers.request.path if helpers_has_request? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
menu_maker-0.0.2 | lib/menu_maker/menu_renderer.rb |
menu_maker-0.0.1 | lib/menu_maker/menu_renderer.rb |