Sha256: 3fda35007e55d8d4a76731f34908c7f461b3ce9ed4f01b2d0c7c7f6f28d71678
Contents?: true
Size: 1.27 KB
Versions: 7
Compression:
Stored size: 1.27 KB
Contents
module MenuMaker module MenuTestHelper private def menu_definition Proc.new do |menu| menu.add 'Dashboard', '/cms/dashboard', icon: 'fa fa-dashboard' menu.add 'Suppliers', '#', icon: 'fa fa-user' do |submenu| submenu.add 'Add Supplier', '/cms/suppliers/new' submenu.add 'List Suppliers', '/cms/suppliers' end end end def example_menu(url) renderers = MenuRendererContainer.new do |c| c.add_for_next_depth(CustomMenuRenderer.new self, url) c.add_for_next_depth(CustomSubmenuRenderer.new self, url) end Menu.new(renderers, &menu_definition) end def menu_fixture(replacements = {}) replacements.each do |k, v| replacements[k] = v.blank? ? '' : %{ class="#{v}"} end replacement_keys = %i{ dashboard_li_class suppliers_li_class add_supplier_class list_supplier_class } output = raw_menu_html replacement_keys.each { |k| replacements[k] ||= '' } replacements.each { |k,v| output.sub!("{#{k}}", v) } output end def raw_menu_html path = File.expand_path('../fixtures/menu.html', __FILE__) html = File.read path html.split("\n").map(&:strip).join('') end end end
Version data entries
7 entries across 7 versions & 1 rubygems