{"id":16820311,"url":"https://github.com/dvandersluis/waiter","last_synced_at":"2025-04-09T18:08:52.363Z","repository":{"id":5612107,"uuid":"6819535","full_name":"dvandersluis/waiter","owner":"dvandersluis","description":"DSL for constructing menus for Rails applications","archived":false,"fork":false,"pushed_at":"2017-02-10T18:48:52.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T20:11:11.379Z","etag":null,"topics":[],"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/dvandersluis.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}},"created_at":"2012-11-22T22:07:41.000Z","updated_at":"2019-11-18T22:11:49.000Z","dependencies_parsed_at":"2022-08-20T17:40:34.980Z","dependency_job_id":null,"html_url":"https://github.com/dvandersluis/waiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fwaiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fwaiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fwaiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvandersluis%2Fwaiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvandersluis","download_url":"https://codeload.github.com/dvandersluis/waiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085157,"owners_count":21045135,"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":[],"created_at":"2024-10-13T10:56:14.065Z","updated_at":"2025-04-09T18:08:52.341Z","avatar_url":"https://github.com/dvandersluis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Waiter\n\nWaiter serves up menus for your application:\n* Provides a quick DSL for building menus, without having to specify any HTML.\n* Makes assumptions based on what's provided in the DSL so that the specification does not need to be unnecessarily verbose.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'waiter'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install waiter\n\n## Usage\n\n### Building a menu\n\nTo create a new menu:\n\n    Waiter::Menu.serve(:my_menu) do\n      file\n      edit\n      view\n      # ...\n    end\n\nThe above defines a menu with three items. By default, each item name (ie. \"file\", \"edit\", etc.) corresponds both to the\nI18n string to use (so `file` will call `I18n.t(:file, scope: [:menu, :my_menu])`) as well as to the controller to use\n(`file` will correspond to `FileController`, and the menu item will link to `FileController#index` by default).\n\nOf course, there will be situations where the path may need to be explicitly specified. In this case, you can use a path finder:\n\n    Waiter::Menu::serve do\n      menu.file documents_path\n    end\n \nAlternately, the `:controller` and `:action` options can be specified:\n\n    Waiter::Menu.serve do\n      menu.file :controller =\u003e :documents, :action =\u003e :index\n    end\n    \nIn both of the above examples, the File menu will correspond to `DocumentsController#index`, and will be shown as selected\nfor any action within that controller.\n\nThere may also be times where you need multiple controllers to light up the same menu item. This can be achieved by\npassing an array to the `:controllers` option:\n\n    Waiter::Menu.serve do\n      file :controllers =\u003e ['files', 'print', ... ]\n    end\n\nThis will create a menu that links to `DocumentsController#index`, which will be lit up the user hits any action within\nthe `FilesController`, `PrintController`, as well as the `DocumentsController`.\n\n\n### Submenus\n\nMenus can also have submenus (currently only one level of nesting is supported when drawing a menu, but infinite\nlevels are supported when building a menu). A submenu is defined with the same syntax as a root menu item, and is\npassed as a block to the root menu item.\n\nSubmenus automatically assume the controller to use is the controller specified by its root menu item, so a\ncontroller does not need to be specified unless it differs. As well, the menu item name is assumed to be used\nfor the controller for that item, so it does not need to be specified unless it differs from the name.\nAn id can also be specified if necessary (with the `:id` option).\n\n    Waiter::Menu.serve do\n      file do\n        new                            # Corresponds to FileController#new\n        print print_file_path          # Corresponds to PrintController#print\n        list :action =\u003e :all           # Corresponds to ListController#all\n      end\n    end\n\nIf a path hash is given without an `action` key, the index action will be inferred.\n\n\n### Menu Options\n\nThere are two options that you can use when building your menu. Options can be passed into build when defining\na menu or specified once the menu is defined by accessing the menu.options hash.\n\n`selected`: Allows the selected menu item to be overridden, so a specified menu item can be lit up regardless of\nwhat the current controller/action is. This can be useful if there is an action that falls under different menu\nitems depending on application context, or if there is a controller that may correspond to multiple menu items.\nA good way to achieve this would be to add a before_filter to set an instance variable which is then passed into\nthe selected option.\n\n    before_filter :set_current_menu\n\n    def set_current_menu\n      case params[:action]\n        when 'foo' then @current_menu = \"menu1\"\n        when 'bar' then @current_menu = \"menu2\"\n      end\n    end\n\n    Waiter::Menu.serve(:selected =\u003e @current_menu) do |menu|\n    end\n\nNote that the value passed to `:selected` should match the name of the menu item.\n\n\n### Drawing (outputting) a menu\n\nTo draw a created menu, use the `Waiter::Menu::Drawer` class. The class requires the current context to be\npassed in so that `ActionController` methods can be used. In general (ie. if the menu is being drawn from a helper)\nthe context is self.\n\n    menu = Waiter::Menu.serve do |menu|\n      # ...\n    end\n\n    Waiter::Menu::Drawer.new(menu, context).draw\n\nIf a different `Drawer` is desired, `Waiter::Menu::Drawer` can be subclassed and the method `draw` overridden to provide an alternate format.\n\nAlternately, `Waiter::Menu` responds to `draw` directly:\n\n    menu.draw(context)\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fwaiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvandersluis%2Fwaiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvandersluis%2Fwaiter/lists"}