{"id":31774099,"url":"https://github.com/jbox-web/page_title_helper","last_synced_at":"2025-10-10T04:48:23.935Z","repository":{"id":316283805,"uuid":"1062462025","full_name":"jbox-web/page_title_helper","owner":"jbox-web","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-23T17:38:02.000Z","size":243,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-23T19:14:50.058Z","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/jbox-web.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-23T09:36:08.000Z","updated_at":"2025-09-23T17:38:07.000Z","dependencies_parsed_at":"2025-09-25T21:30:43.391Z","dependency_job_id":null,"html_url":"https://github.com/jbox-web/page_title_helper","commit_stats":null,"previous_names":["jbox-web/page_title_helper"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jbox-web/page_title_helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fpage_title_helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fpage_title_helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fpage_title_helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fpage_title_helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/page_title_helper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fpage_title_helper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002657,"owners_count":26083442,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-10T04:48:04.635Z","updated_at":"2025-10-10T04:48:23.929Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Page title helper\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/page_title_helper.svg)](https://github.com/jbox-web/page_title_helper/blob/master/LICENSE)\n[![CI](https://github.com/jbox-web/page_title_helper/workflows/CI/badge.svg)](https://github.com/jbox-web/page_title_helper/actions)\n[![Maintainability](https://qlty.sh/badges/f914656c-1900-4579-8b62-babd4c364c11/maintainability.svg)](https://qlty.sh/gh/jbox-web/projects/page_title_helper)\n[![Code Coverage](https://qlty.sh/badges/f914656c-1900-4579-8b62-babd4c364c11/coverage.svg)](https://qlty.sh/gh/jbox-web/projects/page_title_helper)\n\nThis project adheres to [Semantic Versioning](https://semver.org/).\n\n## What does this gem do?\n\nEver wondered if there was an easier and DRY-way to set your page titles\n(and/or headings), introducing _page title helper_, a small view helper for\nRails to inflect titles from controllers and actions.\n\nIn your layout, add this to your `\u003chead\u003e`-section:\n\n```html\n\u003ctitle\u003e\u003c%= page_title %\u003e\u003c/title\u003e\n```\n\nThat's it. Now just add translations, in e.g. `config/locales/en.yml`:\n\n```yaml\nen:\n  contacts:\n    index:\n      title: \"Contacts\"\n```\n\nWhen `/contacts/` is requested, the key `:en, :contacts, :index, :title`\nis looked up and printed, together with the applications basename, like:\n`Contacts - My cool App`.\nThe format etc. is of course configurable, just head down to the options.\n\n## Installation\n\nPut this in your `Gemfile` :\n\n```ruby\ngit_source(:github){ |repo_name| \"https://github.com/#{repo_name}.git\" }\n\ngem 'page_title_helper', github: 'jbox-web/page_title_helper'\n```\n\nthen run `bundle install`.\n\n## Translated titles\n\nAll translated titles are inflected from the current controller and action,\nso to easily explain all lookups, here an example with the corresponding\nlookups:\n\n```\nAdmin::AccountController#index =\u003e :'admin.account.index.title'\n                                  :'admin.account.title'\n                                  options[:default]\n```\n\nFor `create` and `update` a further fallback to `new.title` and `edit.title`\nhave been added, because they certainly are duplicates.\n\n## Customize titles\n\nNeed a custom title, or need to fill in some placeholders? Just use the _bang_\nmethod (`page_title!`), in e.g. `contacts/show.html.erb` the requirement is to\ndisplay the contacts name in the `\u003ctitle\u003e-tag`as well as in the heading?\n\n```html\n\u003ch1\u003e\u003c%= page_title!(@contact.name) %\u003e\u003c/h1\u003e\n```\n\nA call to `page_title` will now return the contacts name, neat :) if for\nexample the `\u003ch1\u003e` does not match the `\u003ctitle\u003e`, then well, just do something\nlike:\n\n```html\n\u003c% page_title!(@contact.name + \" (\" + @contact.company.name + \")\") %\u003e\n\u003ch1\u003e\u003c%= @contact.name %\u003e\u003c/h1\u003e\n```\n\nGuess, that's it. Of course it's also possible to use `translate` within\n`page_title!`, to translate custom titles, like:\n\nIn `config/locales/en.yml`:\n\n```yaml\nen:\n  dashboard:\n    index:\n      title: \"Welcome back, {{name}}\"\n```\n\nIn `app/views/dashboard/index.html.erb`:\n\n```html\n\u003ch1\u003e\u003c%= page_title!(t('.title', name: @user.first_name)) %\u003e\u003c/h1\u003e\n```\n\n## More fun with \u003ccode\u003e:format\u003c/code\u003e\n\nThe `:format` option is used to specify how a title is formatted, i.e. if the\napp name is prepended or appended or if it contains the account name etc.\nIt uses a similar approach as paperclip's path interpolations:\n\n```ruby\npage_title format: ':title / :app' # =\u003e \"Contacts / My cool app\"\n```\n\nAdding custom interpolations is as easy as defining a block, for example to\naccess the current controller:\n\n```ruby\nPageTitleHelper.interpolates :controller do |env|\n  env[:view].controller.controller_name.humanize\nend\n\npage_title format: ':title / :controller / :app' # =\u003e \"Welcome back / Dashboard / My cool app\"\n```\n\nTo access just the title, without any magic app stuff interpolated or appended,\nuse:\n\n```ruby\npage_title! \"untitled\"\npage_title format: false # =\u003e \"untitled\"\n```\n\nNeed a custom format for a single title? Just return an array:\n\nIn the view:\n\n```html\n\u003ch1\u003e\u003c%= page_title!(@contact.name, \":title from :company - :app\") %\u003e\u003c/h1\u003e # =\u003e \u003ch1\u003eFranz Meyer\u003c/h1\u003e\n```\n\nIn the `\u003chead\u003e`:\n\n```html\n\u003ctitle\u003e\u003c%= page_title %\u003e\u003c/title\u003e # =\u003e this time it will use custom title like \"Franz Meyer from ABC Corp. - My cool app\"\n```\n\nTo streamline that feature a bit and simplify reuse of often used formats,\nit's possible to define format aliases like:\n\nIn an initializer, e.g., `config/initializers/page_title_helper.rb`:\n\n```ruby\nPageTitleHelper.formats[:with_company] = \":title from :company - :app\"\n# show app first for promo pages :)\nPageTitleHelper.formats[:promo] = \":app - :title\" \n```\n\nThen in the view to display a contact:\n\n```ruby\npage_title! @contact.name, :with_company\n```\n\nOr for the promo page via `config/locales/en.yml` (!):\n\n```yaml\nen:\n  pages:\n    features:\n      title:\n        - \"Features comparison\"\n        - !ruby/sym promo\n```\n\nPretty, cool, ain't it? The special `format: :app` works also via the `formats`\nhash. Then there is also a `:default` format, which can be used to override the\ndefault format.\n\n## All options - explained\n\n| Option   | Description | Default | Values |\n|----------|-------------|---------|--------|\n|`:app`    | Specify the applications name, however it's recommended to define it via translation key `:'app.name'`. | Inflected from `Rails.root`| string |\n|`:default`| String which is displayed when no translation exists and no custom title has been specified. Can also be set to a symbol or array to take advantage of `I18n.translate`'s `:default` option. | `'app.tagline'` | string, symbol or array of those |\n|`:format` | Defines the output format, accepts a string containing multiple interpolations, or a symbol to a format alias, see _More fun with `:format`_. If set to `false`, just the current title is returned. | `:default`| string, symbol |\n\nOptions can be set globally via `PageTitleHelper.options`. Note, currently it\nonly makes sense to set `:default` globally.\n\nTo add or change formats use:\n\n```ruby\n# change the default format used (if no format is specified):\nPageTitleHelper.formats[:default] = \":title // :app\"\n\n# add a custom format alias (which can be used with page_title(format: :promo))\nPageTitleHelper.formats[:promo] = \":app // :title\"\n```\n\n_Note:_ It's recommended to add this kind of stuff to an initializer, like e.g.\n`config/initializers/page_title_helper.rb`.\n\n## A (maybe useful) interpolation\n\nThe internationalized controller name, with fallback to just display the\nhumanized name:\n\n```ruby\nPageTitleHelper.interpolates :controller do |env|\n  c = env[:view].controller\n  I18n.t(c.controller_path.tr('/', '.') + '.controller', default: c.controller_name.humanize)\nend\n```\n\n_Note:_ Put this kind of stuff into an initializer, like\n`config/initializers/page_title_helper.rb` or something like that.\n\n## Licence and copyright\n\nCopyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fpage_title_helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Fpage_title_helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fpage_title_helper/lists"}