{"id":17823087,"url":"https://github.com/artofcode-/structured_menus","last_synced_at":"2026-02-24T19:34:50.491Z","repository":{"id":32805787,"uuid":"142786185","full_name":"ArtOfCode-/structured_menus","owner":"ArtOfCode-","description":"An easy way to create flexible menus for Rails apps.","archived":false,"fork":false,"pushed_at":"2023-03-08T19:51:27.000Z","size":55,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T19:45:56.318Z","etag":null,"topics":["dropdown","menus","rails","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtOfCode-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-29T18:35:38.000Z","updated_at":"2022-09-17T06:28:35.000Z","dependencies_parsed_at":"2024-10-27T18:20:16.927Z","dependency_job_id":"959db5e7-1b85-468b-9c63-99d4550bd602","html_url":"https://github.com/ArtOfCode-/structured_menus","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.21052631578947367","last_synced_commit":"0be51156fed2d74099bf84643a19d54c4ec330c1"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstructured_menus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstructured_menus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstructured_menus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstructured_menus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtOfCode-","download_url":"https://codeload.github.com/ArtOfCode-/structured_menus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247699769,"owners_count":20981609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dropdown","menus","rails","ruby"],"created_at":"2024-10-27T17:50:57.479Z","updated_at":"2025-10-24T21:12:03.564Z","avatar_url":"https://github.com/ArtOfCode-.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `structured_menus`\nAn easy way to create flexible menus for Rails apps.\n\n## Installation\nAdd this line to your Gemfile and run `bundle install`:\n\n    gem 'structured_menus'\n    \nNext, create a configuration file in `config/initializers`, probably called `structured_menus.rb` because convention, and add the following to it:\n\n```ruby\nStructuredMenus::Configurator.configure do |config|\n  # You don't have to add anything here, if you like the defaults, but you still need to call `configure`.\nend\n```\n\n## Quick Start\nOnce you've done the above, create `app/menus/menu.yml`, and add the following to it:\n\n```yaml\n- name: FAQ\n  icon: question\n  link: /faq\n```\n\nIn the view in which you want to display the menu, add this code:\n\n```erb\n\u003c%= Rails.menus.show :menu, :dashboard, current_user %\u003e\n``` \n\nYou can substitute `:dashboard` for `:dropdown` if you want a Bootstrap dropdown menu instead; if you don't have a `current_user` method, use `nil`.\n\nContinue reading for more detailed usage options.\n    \n## Usage\nStructuredMenus enables you to create menus for your app by writing YAML files in (by default) `app/menus`. Each file is a menu; each item in the file\nbecomes an item on your menu, displayed according to the adapter (more on that later) and options you specify. Such a file might look like this:\n\n```yaml\n- name: Admin\n  icon: cogs\n  link: /admin\n  if: 'lambda { |u| u\u0026.has_role?(:admin) }'\n\n- name: CRM\n  icon: users\n  link: /crm\n\n- name: Orders\n  icon: money-bill-alt\n  link: /orders\n```\n\nSave that as `mymenu.yml`, and you'll be able to call `Rails.menus.show :mymenu, :dashboard, current_user` to pop it up anywhere in your app.\n\n### Adapters\nAdapters are the bits that control how the menu is actually displayed. There are two included by default: `:dashboard` and `:dropdown`. Both are \ndesigned to work with Bootstrap and FontAwesome (yes, I'm opinionated). Each adapter supports different options - see the definitions in \n`lib/structured_menus/adapters` for details on what they are.\n\n - **Dashboard** is designed to be a full-screen main menu type thing, probably for apps with lots of navigation. The example menu YAML shown above\n   looks like this when shown (some custom CSS - the topbar is not part of the menu):\n   \n   [![](https://i.stack.imgur.com/n0sbQ.png)](https://i.stack.imgur.com/n0sbQ.png)\n   \n   Use `:dashboard` in your call to `Rails.menus.show` to get this adapter.\n   \n - **Dropdown** is, well, a Bootstrap dropdown menu. It doesn't include icons by default, but you can make it do so if you want them. The same YAML\n   looks like this with the dropdown adapter:\n   \n   [![](https://i.stack.imgur.com/rc1Ww.png)](https://i.stack.imgur.com/rc1Ww.png)\n   \n   Use `:dropdown` in your call to `Rails.menus.show` to get this adapter.\n   \n#### Custom adapters\nIf those two don't suit your needs, you can write your own custom adapter. Essentially, this needs to emulate one of the two stock adapters, in that:\n\n - It must respond to `#show`\n - Calls to `#show` must respond with the string of raw HTML that you want to render.\n \nFor reference, here's what the dashboard adapter looks like:\n\n```ruby\nmodule StructuredMenus::Adapters\n  class DashboardAdapter\n    include ActionView::Helpers::UrlHelper\n    include ActionView::Helpers::OutputSafetyHelper\n    \n    def self.show(menu, user, **options)\n      inst = new\n      width = options[:width] || 4\n      cards = menu.map do |i|\n        next unless !i['if'] || instance_eval(i['if']).call(user)\n\n        cls = options[:class] || 'dashboard-menu-card'\n        inst.raw(\"\u003cdiv class=\\\"#{cls}\\\"\u003e#{inst.link_to inst.raw(\"\u003ci class=\\\"fas fa-#{i['icon']}\\\"\u003e\u003c/i\u003e #{i['name']}\"), i['link']}\u003c/div\u003e\")\n      end.compact\n\n      inst.raw(cards.in_groups_of(12 / width).map(\u0026:compact).map do |g|\n        '\u003cdiv class=\"row\"\u003e' + g.map { |c| \"\u003cdiv class=\\\"col-md-#{12 / width}\\\"\u003e#{c}\u003c/div\u003e\" }.join(\"\\n\") + '\u003c/div\u003e'\n      end.join(\"\\n\"))\n    end\n  end\nend\n```\n\nThe parameters that will be passed to `#show` are as follows:\n\n - `menu` - a parsed YAML file, in the form of an array. Each element is a hash representing a single menu item as specified in the file.\n - `user` is the value passed to `Rails.menus.show`, which should be a reference to the current user. This can be `nil`.\n - `**options` is a hash of additional options - it's up to you what you want to support. Look at the adapter files in `lib/structured_menus/adapters`\n   to see the options that the stock adapters support.\n   \nOnce you've written your adapter, tell structured_menus about it by adding it to the configuration file:\n\n```ruby\nStructuredMenus::Configurator.configure do |config|\n  config.adapters \u003c\u003c YourCustomAdapterClass\nend\n```\n\n## Contributions\nWelcome. Ping me a PR. For large changes you should probably open an issue first to discuss.\n\n## License\nAvailable under the terms of the MIT license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartofcode-%2Fstructured_menus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartofcode-%2Fstructured_menus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartofcode-%2Fstructured_menus/lists"}