{"id":15527241,"url":"https://github.com/sztheory/meta_presenter","last_synced_at":"2025-10-07T21:14:29.104Z","repository":{"id":54232619,"uuid":"158758144","full_name":"szTheory/meta_presenter","owner":"szTheory","description":"Focused Rails presenter classes","archived":false,"fork":false,"pushed_at":"2024-01-21T15:57:17.000Z","size":125,"stargazers_count":10,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T12:16:37.938Z","etag":null,"topics":["delegation","mit-license","presenter","presenter-behaviour","presenters","rails","ruby","rubygem"],"latest_commit_sha":null,"homepage":"https://metapresenter.com","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/szTheory.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2018-11-22T23:14:19.000Z","updated_at":"2023-10-19T23:46:42.000Z","dependencies_parsed_at":"2024-01-21T16:57:46.686Z","dependency_job_id":null,"html_url":"https://github.com/szTheory/meta_presenter","commit_stats":{"total_commits":119,"total_committers":2,"mean_commits":59.5,"dds":0.008403361344537785,"last_synced_commit":"961d12c9e5d45f1f2ae23d6d827f2ff1f526cdc3"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fmeta_presenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fmeta_presenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fmeta_presenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szTheory%2Fmeta_presenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szTheory","download_url":"https://codeload.github.com/szTheory/meta_presenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430600,"owners_count":21429324,"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":["delegation","mit-license","presenter","presenter-behaviour","presenters","rails","ruby","rubygem"],"created_at":"2024-10-02T11:05:09.739Z","updated_at":"2025-10-07T21:14:24.055Z","avatar_url":"https://github.com/szTheory.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/meta_presenter.svg)](https://badge.fury.io/rb/meta_presenter) [![Build Status](https://travis-ci.org/szTheory/meta_presenter.svg?branch=master)](https://travis-ci.org/szTheory/meta_presenter) [![Coverage Status](https://coveralls.io/repos/github/szTheory/meta_presenter/badge.svg?branch=master)](https://coveralls.io/github/szTheory/meta_presenter?branch=master) [![Inline docs](https://inch-ci.org/github/szTheory/meta_presenter.svg?branch=master)](https://inch-ci.org/github/szTheory/meta_presenter) [![Maintainability](https://api.codeclimate.com/v1/badges/8698d68a87ec1a9bfacd/maintainability)](https://codeclimate.com/github/szTheory/meta_presenter/maintainability) [![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/szTheory/meta_presenter/blob/master/LICENSE.txt) [![Gem](https://img.shields.io/gem/dt/meta_presenter.svg)](https://rubygems.org/gems/meta_presenter) [![GitHub stars](https://img.shields.io/github/stars/szTheory/meta_presenter.svg?label=Stars\u0026style=social)](https://github.com/szTheory/meta_presenter)\n\n[![logo](https://user-images.githubusercontent.com/28652/50427588-2289cf80-087a-11e9-82e1-ae212adf0d07.png)](https://metapresenter.com)\n\nMetaPresenter is a Ruby gem for writing highly focused and testable Rails view presenter classes. For each controller/action pair you get a presenter class in `app/presenters` that you can use in your views with `presenter.method_name`. This helps you decompose your helper logic into tight, easily testable classes.\n\n![overlay-shape-clean-sm](https://user-images.githubusercontent.com/28652/50854229-828c7580-1352-11e9-824b-a78c9a2404fb.png)\n\n## Installation\n\n### 1. Add this line to your application's Gemfile\n\n```ruby\ngem 'meta_presenter'\n```\n\n### 2. Bundle from the command line\n\n```sh\nbundle install\n```\n\n### 3. Include MetaPresenter::Helpers in ApplicationController\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  include MetaPresenter::Helpers\nend\n```\n\n```ruby\n# mailers are supported too\nclass ApplicationMailer \u003c ActionMailer::Base\n  include MetaPresenter::Helpers\nend\n```\n\n## Setup\n\n### 1. Create an ApplicationPresenter\n\nApplicationPresenter methods can be used anywhere in the app. This example makes `presenter.page_title` and `presenter.last_login` accessible from all views.\n\n```ruby\n# app/presenters/application_presenter.rb\nclass ApplicationPresenter \u003c MetaPresenter::BasePresenter\n  def page_title\n    \"My App\"\n  end\n\n  def last_login\n    # controller methods are available to\n    # presenters in the same namespace\n    time = current_user.last_login_at\n    distance_of_time_in_words_to_now(time)\n  end\nend\n```\n\n#### 2. Create presenters for your controllers\n\nThis example makes `presenter.tooltip(text)` available for all actions on `PagesController`:\n\n```ruby\n# app/presenters/pages_presenter.rb\nclass PagesPresenter \u003c ApplicationPresenter\n  def tooltip(text)\n    content_tag(:p, text, class: \"font-body1\")\n  end\nend\n```\n\n```Erb\n\u003c!-- app/views/pages/about.html.erb --\u003e\n\u003ch1\u003eAbout\u003c/h1\u003e\n\u003cp data-tipsy-content=\"\u003c%= presenter.tooltip(\"Don't Be Evil\") %\u003e\"\u003eGloogle\u003c/p\u003e\n```\n\n#### 3. Create presenters for specific actions\n\nThis example makes `presenter.greeting` accessible from views. It also delegates undefined methods to `current_user`, so `presenter.email` would call `current_user.email`:\n\n```ruby\n# app/presenters/pages/home_presenter.rb\nclass Pages::HomePresenter \u003c PagesPresenter\n  # can also delegate specific methods. ex:\n  # delegate :email, :last, to: :current_user\n  delegate_all_to = :current_user\n\n  def greeting\n    \"Hello, #{name}\"\n  end\nend\n```\n\n```Erb\n\u003c!-- app/views/pages/home.html.erb --\u003e\n\u003ch1\u003eHome\u003c/h1\u003e\n\u003cp\u003e\u003c%= presenter.greeting %\u003e\u003c/p\u003e\n\u003cp\u003eLast login \u003c%= presenter.last_login %\u003e\u003c/p\u003e\n```\n\n## Example directory structure\n\nNote that presenters mirror the namespace of controllers.\n\n```diagram\napp/\n  controllers/\n    application_controller.rb\n    pages_controller.rb\n  presenters/\n    application_presenter.rb\n    pages_presenter.rb\n    pages/\n      home_presenter.rb\n      logs_presenter.rb\n  views\n    pages\n      home.html.erb\n      logs.html.erb\nspec/ (or test/)\n  presenters/\n    application_presenter_spec.rb\n    pages_presenter_spec.rb\n    pages/\n      home_presenter_spec.rb\n      logs_presenter_spec.rb\n```\n\n## Aliasing the presenter methods\n\nIf you want to customize the `presenter` method you can specify a shorthand by adding an alias_method to your controller or mailer:\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  including MetaPresenter\n\n  # So convenient!\n  alias_method :presenter, :pr\nend\n```\n\n## Requirements\n\nMetaPresenter supports Ruby \u003e= 3.0.0 and ActionPack/ActionMailer \u003e= 6, or \u003e= 7.0.1 for Rails 7 (7.0.0 has a bug)\n\n## Links\n\n- [Project website](https://metapresenter.com)\n- [RDocs for the master branch](https://www.rubydoc.info/github/szTheory/meta-presenter/master)\n\n## Specs\n\nTo run the specs for the currently running Ruby version, run `bundle install` and then `bundle exec rspec`. To run specs for every supported version of ActionPack, run `bundle exec appraisal install` and then `bundle exec appraisal rspec`.\n\n## Gem release\n\nMake sure the specs pass, bump the version number in meta_presenter.gemspec, build the gem with `gem build meta_presenter.gemspec`. Commit your changes and push to Github, then tag the commit with the current release number using Github's Releases interface (use the format vx.x.x, where x is the semantic version number). You can pull the latest tags to your local repo with `git pull --tags`. Finally, push the gem with `gem push meta_presenter-version-number-here.gem`.\n\n## TODO High-Priority\n\n- Add a `rake meta_presenter:install` that generates the scaffolding for you\n- Make sure directions are clear for manually creating presenters\n\n## TODO\n\n- create an example app and link to the repo for it in this README\n- add support for layout-level presenters\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b feature/my-new-feature`) or bugfix branch (`git checkout -b bugfix/my-helpful-bugfix`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin feature/my-new-feature`)\n5. Make sure specs are passing (`bundle exec rspec`)\n6. Create new Pull Request\n\n## Running the specs\n\nTo run specs against different versions of Rails:\n\n```bash\nbundle exec appraisal install #install dependencies for each ruby version\nbundle exec appraisal rails6 rspec #run rails 6 specs on current Ruby\nbundle exec appraisal rails7 rspec #run rails 7 specs on current Ruby\n```\n\n## License\n\nSee the [LICENSE](https://github.com/szTheory/meta_presenter/blob/master/LICENSE.txt) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsztheory%2Fmeta_presenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsztheory%2Fmeta_presenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsztheory%2Fmeta_presenter/lists"}