{"id":31696719,"url":"https://github.com/andypearson/happy-titles","last_synced_at":"2025-10-08T17:15:45.521Z","repository":{"id":667076,"uuid":"124244","full_name":"andypearson/happy-titles","owner":"andypearson","description":"A simple (and cheerful) way to handle page titles in your layouts.","archived":false,"fork":false,"pushed_at":"2022-12-14T02:10:58.000Z","size":64,"stargazers_count":11,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-07T23:35:42.193Z","etag":null,"topics":["gem","happy-titles","rails","ruby","titles"],"latest_commit_sha":null,"homepage":"","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/andypearson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-02-08T08:40:13.000Z","updated_at":"2019-08-13T13:59:22.000Z","dependencies_parsed_at":"2023-01-13T10:35:12.321Z","dependency_job_id":null,"html_url":"https://github.com/andypearson/happy-titles","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/andypearson/happy-titles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andypearson%2Fhappy-titles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andypearson%2Fhappy-titles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andypearson%2Fhappy-titles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andypearson%2Fhappy-titles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andypearson","download_url":"https://codeload.github.com/andypearson/happy-titles/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andypearson%2Fhappy-titles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278838435,"owners_count":26054720,"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-07T02:00:06.786Z","response_time":59,"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":["gem","happy-titles","rails","ruby","titles"],"created_at":"2025-10-08T17:15:41.614Z","updated_at":"2025-10-08T17:15:45.516Z","avatar_url":"https://github.com/andypearson.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# happy-titles\n\nA simple (and cheerful) way to handle page titles in your layouts.\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'happy-titles'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install happy-titles\n\n\n## Usage\n\n### Setting up default values\n\nCreate a new file in `config/initializers` called `happy_titles.rb` or something else which makes sense!\n\nIn this new file, add the following lines to set the default site and tagline.\n\n```ruby\nHappyTitles.configure do |config|\n  config.site = \"Your Site\"\n  config.tagline = \"Your witty but informative tagline\"\nend\n```\n\n\n### Update your layout\n\nIn the layout where you want to display your title add the following call to the Happy Titles helper method.\n\n```\n\u003c%= page_title %\u003e\n```\n\nThe header element of your layout might end up looking something like:\n\n```html\n\u003chead\u003e\n  \u003cmeta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" /\u003e\n  \u003c%= page_title %\u003e\n\u003c/head\u003e\n```\n\nNotice you don't need to wrap the helper in a `\u003ctitle\u003e` element, this is done for you.\n\n\n### Set the title in your views\n\nIn each of your views call the `title` method to set the title for that page.\n\n```\n\u003c% title 'Your very first Happy Title!' %\u003e\n```\n\n### See your titles!\n\nGiven the above settings, let's have a look at the output you will receive when you call the `page_title` method in your layouts.\n\nOn pages where the title has not been set you will see...\n\n```html\n\u003ctitle\u003eYour Site | Your witty but informative tagline\u003c/title\u003e\n```\n\n...and on pages where the title _has_ been set you will see...\n\n```html\n\u003ctitle\u003eYour very first Happy Title! | Your Site\u003c/title\u003e\n```\n\nThat really is all there is to setting up and using Happy Titles!\n\n\n## Customising the Title Templates\n\n### Intro\n\nYou have already seen how to set up and use Happy Titles, now let's take a look at how to customise the individual title templates.\n\nIn all of the following examples I am going to assume the same defaults that are set up in the Set the Defaults section of this README.\n\nBefore we have a look at that, let's have a look at the **placeholders** you can use. These placeholders will be replaced with the real content when the title is rendered.\n\n| Placeholder | Example                                                                                   |\n|:------------|:------------------------------------------------------------------------------------------|\n| :site       | \"Your Site\"                                                                               |\n| :tagline    | \"Your witty but informative tagline\"                                                      |\n| :title      | Will become \"Your very first Happy Title!\" or `:tagline` if a page title has not been set |\n\nNow let's have a look at the default templates.\n\n| Template            | Description                                                                               |\n|:--------------------|:------------------------------------------------------------------------------------------|\n| :site \u0026#124; :title | Is used when there is no title set: \"Your Site \u0026#124; Your witty but informative tagline\" |\n| :title \u0026#124; :site | Is used when there *is* a title set: \"Your very first Happy Title! \u0026#124; Your Site\"      |\n\nYou can change the default templates by using the following setting in `config/initializers/happy_titles.rb`\n\n```ruby\nHappyTitles.configure do |config|\n  config.templates do\n    # The second param is the template to use when there is no title set\n    # The third param is the template to use when there is a title set\n    default \"[:site]\", \"[:site] :title\"\n  end\nend\n```\n\nThen when you render your titles you will see the following\n\n```html\n\u003ctitle\u003e[Your Site]\u003c/title\u003e \u003c!-- when there is no title --\u003e\n\u003ctitle\u003e[Your Site] Your very first Happy Title!\u003c/title\u003e \u003c!-- when the title is set --\u003e\n```\n\n\n### Adding Additional Templates\n\nAs well as changing the default template, you can also add new templates and then use those when you need a different title format in a different layout.\n\nIn `config/initializers/happy_titles.rb`:\n\n```ruby\nHappyTitles.configure do |config|\n  config.templates do\n    extra \"++ :site ++\", \"++ :site ++ :title ++\"\n  end\nend\n```\n\nThen in your layout, you can use the following to call the extra template.\n\n```\n\u003c%= page_title :extra %\u003e\n```\n\nAnd you will get the following output, as you probably would've guessed by now!\n\n```html\n\u003ctitle\u003e++ Your Site ++\u003c/title\u003e \u003c!-- when there is no title --\u003e\n\u003ctitle\u003e++ Your Site ++ Your very first Happy Title! ++\u003c/title\u003e \u003c!-- when the title is set --\u003e\n```\n\nYou can add as many additional title templates as you need!\n\nOne final thing to mention, you can create templates that just have one format. So...\n\nIn `config/initializers/happy_titles.rb`:\n\n```ruby\nHappyTitles.configure do |config|\n  config.templates do\n    single \":site (:title)\"\n  end\nend\n```\n\nIn your layout:\n\n```\n\u003c%= page_title :single %\u003e\n```\n\nThe output:\n\n```html\n\u003ctitle\u003eYour Site (Your witty but informative tagline)\u003c/title\u003e \u003c!-- when there is no title --\u003e\n\u003ctitle\u003eYour Site (Your very first Happy Title!)\u003c/title\u003e \u003c!-- when the title is set --\u003e\n```\n\n\n## Contributing\n\n1. Fork it ( https://github.com/andypearson/happy-titles/fork )\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 a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandypearson%2Fhappy-titles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandypearson%2Fhappy-titles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandypearson%2Fhappy-titles/lists"}