{"id":13747310,"url":"https://github.com/heartcombo/show_for","last_synced_at":"2025-05-09T08:32:17.767Z","repository":{"id":43656847,"uuid":"437753","full_name":"heartcombo/show_for","owner":"heartcombo","description":"Wrap your objects with a helper to easily show them","archived":false,"fork":false,"pushed_at":"2024-04-09T19:59:26.000Z","size":270,"stargazers_count":463,"open_issues_count":0,"forks_count":54,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-05-21T01:05:23.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://blog.plataformatec.com.br/tag/show_for","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/heartcombo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","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":"2009-12-15T11:24:16.000Z","updated_at":"2024-06-18T15:18:34.272Z","dependencies_parsed_at":"2023-10-12T04:47:50.723Z","dependency_job_id":"c5f76353-290a-4509-a0cf-744d7aa1c763","html_url":"https://github.com/heartcombo/show_for","commit_stats":null,"previous_names":["plataformatec/show_for"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heartcombo%2Fshow_for","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heartcombo%2Fshow_for/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heartcombo%2Fshow_for/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heartcombo%2Fshow_for/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heartcombo","download_url":"https://codeload.github.com/heartcombo/show_for/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224208106,"owners_count":17273674,"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-08-03T06:01:24.666Z","updated_at":"2024-11-15T20:31:28.455Z","avatar_url":"https://github.com/heartcombo.png","language":"Ruby","readme":"# ShowFor\n\n[![Gem Version](https://fury-badge.herokuapp.com/rb/show_for.png)](http://badge.fury.io/rb/show_for)\n\nShowFor allows you to quickly show a model information with I18n features.\n\n```erb\n\u003c%= show_for @user do |u| %\u003e\n  \u003c%= u.attribute :name %\u003e\n  \u003c%= u.attribute :nickname, in: :profile %\u003e\n  \u003c%= u.attribute :confirmed? %\u003e\n  \u003c%= u.attribute :created_at, format: :short %\u003e\n  \u003c%= u.attribute :last_sign_in_at, if_blank: \"User did not access yet\",\n                  wrapper_html: { id: \"sign_in_timestamp\" } %\u003e\n\n  \u003c%= u.attribute :photo do %\u003e\n    \u003c%= image_tag(@user.photo_url) %\u003e\n  \u003c% end %\u003e\n\n  \u003c%= u.association :company %\u003e\n  \u003c%= u.association :tags, to_sentence: true %\u003e\n\u003c% end %\u003e\n```\n\n## Installation\n\nInstall the gem:\n\n    gem install show_for\n\nOr add ShowFor to your Gemfile and bundle it up:\n\n    gem 'show_for'\n\nRun the generator:\n\n    rails generate show_for:install\n\nAnd you are ready to go.\n\nNote: This branch aims Rails 5 and 6 support, so if you want to use it with\nolder versions of Rails, check out the available branches.\n\n## Usage\n\nShowFor allows you to quickly show a model information with I18n features.\n\n```erb\n\u003c%= show_for @admin do |a| %\u003e\n  \u003c%= a.attribute :name %\u003e\n  \u003c%= a.attribute :login, value: :upcase %\u003e\n  \u003c%= a.attribute :confirmed? %\u003e\n  \u003c%= a.attribute :created_at, format: :short %\u003e\n  \u003c%= a.attribute :last_sign_in_at, if_blank: \"Administrator did not access yet\"\n                  wrapper_html: { id: \"sign_in_timestamp\" } %\u003e\n\n  \u003c%= a.attribute :photo do %\u003e\n    \u003c%= image_tag(@admin.photo_url) %\u003e\n  \u003c% end %\u003e\n\n  \u003c% a.value :biography %\u003e\n\u003c% end %\u003e\n```\n\nWill generate something like:\n\n```html\n\u003cdiv id=\"admin_1\" class=\"show_for admin\"\u003e\n  \u003cdiv class=\"wrapper admin_name\"\u003e\n    \u003cstrong class=\"label\"\u003eName\u003c/strong\u003e\u003cbr /\u003e\n    José Valim\n  \u003c/div\u003e\n  \u003cdiv class=\"wrapper admin_login\"\u003e\n    \u003cstrong class=\"label\"\u003eLogin\u003c/strong\u003e\u003cbr /\u003e\n    JVALIM\n  \u003c/div\u003e\n  \u003cdiv class=\"wrapper admin_confirmed\"\u003e\n    \u003cstrong class=\"label\"\u003eConfirmed?\u003c/strong\u003e\u003cbr /\u003e\n    Yes\n  \u003c/div\u003e\n  \u003cdiv class=\"wrapper admin_created_at\"\u003e\n    \u003cstrong class=\"label\"\u003eCreated at\u003c/strong\u003e\u003cbr /\u003e\n    13/12/2009 - 19h17\n  \u003c/div\u003e\n  \u003cdiv id=\"sign_in_timestamp\" class=\"wrapper admin_last_sign_in_at\"\u003e\n    \u003cstrong class=\"label\"\u003eLast sign in at\u003c/strong\u003e\u003cbr /\u003e\n    Administrator did not access yet\n  \u003c/div\u003e\n  \u003cdiv class=\"wrapper admin_photo\"\u003e\n    \u003cstrong class=\"label\"\u003ePhoto\u003c/strong\u003e\u003cbr /\u003e\n    \u003cimg src=\"path/to/photo\" /\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"wrapper admin_biography\"\u003e\n    Etiam porttitor eros ut diam vestibulum et blandit lectus tempor. Donec\n    venenatis fermentum nunc ac dignissim. Pellentesque volutpat eros quis enim\n    mollis bibendum. Ut cursus sem ac sem accumsan nec porttitor felis luctus.\n    Sed purus nunc, auctor vitae consectetur pharetra, tristique non nisi.\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\nYou can also show a list of attributes, useful if you don't need to change any configuration:\n\n```erb\n\u003c%= show_for @admin do |a| %\u003e\n  \u003c%= a.attributes :name, :confirmed?, :created_at %\u003e\n\u003c% end %\u003e\n```\n\n## Value lookup\n\nShowFor uses the following sequence to get the attribute value:\n\n* use the output of a block argument if given\n* use the output of the `:value` argument if given\n* check if a `:\"human_#{attribute}\"` method is defined\n* retrieve the attribute directly.\n\n## Options\n\nShowFor handles a series of options. Those are:\n\n* __:format__ - Sent to `I18n.localize` when the attribute is a date/time object.\n\n* __:value__ - Can be used instead of block. If a `Symbol` is called as instance method.\n\n* __:if_blank__ - An object to be used if the value is blank. Not escaped as well.\n\n* __:separator__ - The piece of html that separates label and content, overriding the global configuration.\n\nIn addition, all containers (`:label`, `:content` and `:wrapper`) can have their html\noptions configured through the `:label_html`, `:content_html` and `:wrapper_html`\noptions. Containers can have their tags configured on demand as well through\n`:label_tag,` `:content_tag` and `:wrapper_tag` options.\n\n## Label\n\nShowFor also exposes the label method. In case you want to use the default\n`human_attribute_name` lookup and the default wrapping:\n\n```ruby\na.label :name                  #=\u003e \u003cstrong class=\"label\"\u003eName\u003c/strong\u003e\na.label \"Name\", id: \"my_name\"  #=\u003e \u003cstrong class=\"label\" id=\"my_name\"\u003eName\u003c/strong\u003e\n```\n\nOptionally, if you want to wrap the inner part of the label with some text\n(e.g. adding a semicolon), you can do so by specifying a proc for `ShowFor.label_proc`\nthat will be called with any label text. E.g.:\n\n```ruby\n  ShowFor.label_proc = lambda { |l| l + \":\" }\n```\n\nWhen taking this route, you can also skip on a per label basis by passing the\n`:wrap_label` option with a value of false.\n\n## Associations\n\nShowFor also supports associations.\n\n```erb\n\u003c%= show_for @artwork do |a| %\u003e\n  \u003c%= a.association :artist %\u003e\n  \u003c%= a.association :artist, using: :name_with_title %\u003e\n  \u003c%= a.attribute :name_with_title, in: :artist %\u003e\n\n  \u003c%= a.association :tags %\u003e\n  \u003c%= a.association :tags, to_sentence: true %\u003e\n  \u003c%= a.association :tags do\n    @artwork.tags.map(\u0026:name).to_sentence\n  end %\u003e\n\n  \u003c%= a.association :fans, collection_tag: :ol do |fan| %\u003e\n    \u003cli\u003e\u003c%= link_to fan.name, fan %\u003e\u003c/li\u003e\n  \u003c% end %\u003e\n\u003c% end %\u003e\n```\n\nThe first is a `has_one` or `belongs_to` association, which works like an attribute\nto ShowFor, except it will retrieve the artist association and try to find a\nproper method from `ShowFor.association_methods` to be used. You can pass\nthe option :using to tell (and not guess) which method from the association\nto use.\n\n:tags is a `has_and_belongs_to_many` association which will return a collection.\nShowFor can handle collections by default by wrapping them in list (`\u003cul\u003e` with\neach item wrapped by an `\u003cli\u003e`). However, it also allows you to give `:to_sentence`\nor `:join` it you want to render them inline.\n\nYou can also pass a block which expects an argument to association. In such cases,\na wrapper for the collection is still created and the block just iterates over the\ncollection objects.\n\nHere are some other examples of the many possibilites to custom the output content:\n\n```erb\n\u003c%= u.association :relationships, label: 'test' do  %\u003e\n  \u003c% @user.relationships.each do |relation| %\u003e\n    \u003c%= relation.related_user.name if relation.related_user_role == 'supervisor' %\u003e\n  \u003c% end %\u003e\n\u003c% end %\u003e\n\n\u003c%= u.attribute :gender do  %\u003e\n  \u003c%= content_tag :span, t(\"helpers.enum_select.user.gender.#{@user.gender}\") %\u003e\n\u003c% end %\u003e\n```\n\n## Maintainers\n\n* José Valim (http://github.com/josevalim)\n* Carlos Antonio da Silva (https://github.com/carlosantoniodasilva)\n\n## Contributors\n\n* Jonas Grimfelt (http://github.com/grimen)\n\n## Supported Ruby / Rails versions\n\nWe intend to maintain support for all Ruby / Rails versions that haven't reached end-of-life.\n\nFor more information about specific versions please check [Ruby](https://www.ruby-lang.org/en/downloads/branches/)\nand [Rails](https://guides.rubyonrails.org/maintenance_policy.html) maintenance policies, and our test matrix.\n\n## Bugs and Feedback\n\nIf you discover any bugs or want to drop a line, feel free to create an issue on GitHub.\n\nhttp://github.com/heartcombo/show_for/issues\n\n## License\n\nMIT License. Copyright 2020-2024 Rafael França, Carlos Antônio da Silva. Copyright 2012-2019 Plataformatec.\n","funding_links":[],"categories":["Ruby","Decorators"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheartcombo%2Fshow_for","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheartcombo%2Fshow_for","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheartcombo%2Fshow_for/lists"}