{"id":15405163,"url":"https://github.com/fnando/actionmailer-markdown","last_synced_at":"2025-07-16T19:32:18.926Z","repository":{"id":36215181,"uuid":"40519460","full_name":"fnando/actionmailer-markdown","owner":"fnando","description":"A different take on using ActionMailer, Markdown and I18n.","archived":false,"fork":false,"pushed_at":"2023-01-09T08:55:50.000Z","size":58,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-26T20:01:04.464Z","etag":null,"topics":[],"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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["fnando"],"custom":["https://www.paypal.me/nandovieira/🍕"]}},"created_at":"2015-08-11T03:32:29.000Z","updated_at":"2025-04-19T22:49:18.000Z","dependencies_parsed_at":"2023-01-16T23:29:13.907Z","dependency_job_id":null,"html_url":"https://github.com/fnando/actionmailer-markdown","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/fnando/actionmailer-markdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Factionmailer-markdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Factionmailer-markdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Factionmailer-markdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Factionmailer-markdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/actionmailer-markdown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Factionmailer-markdown/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265534578,"owners_count":23783858,"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-01T16:15:17.179Z","updated_at":"2025-07-16T19:32:18.909Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://www.paypal.me/nandovieira/🍕"],"categories":[],"sub_categories":[],"readme":"# ActionMailer::Markdown\n\n[![Gem](https://img.shields.io/gem/v/actionmailer-markdown.svg)](https://rubygems.org/gems/actionmailer-markdown)\n[![Gem](https://img.shields.io/gem/dt/actionmailer-markdown.svg)](https://rubygems.org/gems/actionmailer-markdown)\n\nA different take on using ActionMailer, Markdown and I18n.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'actionmailer-markdown'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install actionmailer-markdown\n\n## Usage\n\nImagine that you have a mail named `UserMailer#welcome`. Instead of manually\ndefining your subjects like the following, you can create the subject by\ndefining the `user_mailer.welcome.subject` translation.\n\n```ruby\n# app/mailers/user_mailer.rb\nclass UserMailer \u003c ApplicationMailer\n  def welcome(email)\n    mail to: email, subject: 'Welcome to Myapp'\n  end\nend\n```\n\n```yaml\n# config/locales/en.yml\nen:\n  user_mailer:\n    welcome:\n      subject: Welcome to my app\n```\n\nSince I really like defining everything I can in I18n files, I always extend\nthis behavior to the message's body, through the `user_mailer.welcome.body`\ntranslation.\n\n```yaml\n# config/locales/en.yml\nen:\n  user_mailer:\n    welcome:\n      subject: Welcome to my app\n      body: |\n        This is an e-mail body.\n\n        --\n        Myapp team\n```\n\nDid you notice that `|`? That allows YAML strings to be multiline. And on your\ne-mail class you can do something like this:\n\n```ruby\n# app/mailers/user_mailer.rb\nclass UserMailer \u003c ApplicationMailer\n  def welcome(email)\n    mail to: email, body: I18n.t('user_mailer.welcome.body')\n  end\nend\n```\n\nAnd if you want to render HTML and text-plain from this string, you may have to\ndo something like this (Markdown class not shown).\n\n```ruby\n# app/mailers/user_mailer.rb\nclass UserMailer \u003c ApplicationMailer\n  def welcome(email)\n    message = I18n.t('user_mailer.welcome.body')\n\n    mail to: email do |format|\n      format.text { render plain: message }\n      format.html { render html: Markdown.html(message).html_safe }\n    end\n  end\nend\n```\n\nThis idea is really nice, but you have too much things to deal with. Not\nanymore!\n\nWith ActionMailer::Markdown you can just define your mailer action like this:\n\n```ruby\n# app/mailers/user_mailer.rb\nclass UserMailer \u003c ApplicationMailer\n  def welcome(email)\n    mail to: email\n  end\nend\n```\n\nThat's right! This gem automatically uses `user_mailer.welcome.{subject,body}`\nfrom your translation files. And the best part: it evens supports Markdown.\n\n### Passing variables\n\nYou're likely to pass in variables to your messages. To do this, just define\ninstance variables. Imagine you want to parse the user's name on your subject\nand message. Let's suppose you have your translation file defined like this:\n\n```yaml\nen:\n  user_mailer:\n    welcome:\n      subject: \"Welcome to Myapp, %{name}\"\n      body: |\n        Hello, %{name}. And welcome to Myapp.\n```\n\nThis is what your mailer will look like:\n\n```ruby\nclass UserMailer \u003c ApplicationMailer\n  def welcome(user)\n    @name = user.name\n    mail to: user.email\n  end\nend\n```\n\nSame thing for URLs:\n\n```ruby\nclass UserMailer \u003c ApplicationMailer\n  def activation_email(user)\n    @name = user.name\n    @activation_url = account_activation_url(user.uuid)\n    mail to: user.email\n  end\nend\n```\n\nAnd your e-mail body can be something like this:\n\n```yaml\nen:\n  user_mailer:\n    activation_email:\n      subject: Activate your account\n      body: |\n        Hello, %{name}!\n\n        You have to [activate your account](%{activation_url}).\n\n        Thanks,\n\n        --\n        Myapp team\n```\n\nYou may be wondering what happens with the mail's text part. Don't worry!\nActionMailer::Markdown will take care of that. That message will be rendered as:\n\n```text\nHello, John!\n\nYou have to activate your account[1].\n\nThanks,\n--\nMyapp team\n\n[1]: http://example.com/activate/4d4b4396-dc26-47c4-b433-2cd9a1b45ce1\n```\n\nLists and other elements are also exported to a more friendly text version.\n\n**PROTIP:** Use [i18n-dot_lookup](https://github.com/fnando/i18n-dot_lookup) if\nyou want to access properties from an object, like `%{user.name}`\n\n### Replacing the Markdown engine\n\n[redcarpet](https://github.com/vmg/redcarpet) is the default Markdown parser.\nYou may want to specify different options or even switch out to a different\nMarkdown library. All you have to do is defining a processor that responds to\n`.call`. Let's say you want to use [kramdown](http://kramdown.gettalong.org/) as\nyour Markdown engine.\n\n```ruby\nActionMailer::Markdown.processor = -\u003e text { Kramdown::Document.new(text).to_html }\n```\n\n### Falling back to ActionMailer's default behavior\n\nYou can use templates if you want. Just don't define the `.body` part of your\ntranslation. Also, if you pass a block to the `mail()` method, it will skip this\nfunctionally completely.\n\n### Using markdown files\n\nIf you want to use Markdown files instead of I18n translations, this gem is not\nfor you. Consider using [maildown](https://github.com/schneems/maildown) or\n[markerb](https://github.com/plataformatec/markerb).\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/fnando/actionmailer-markdown. This project is intended to be\na safe, welcoming space for collaboration, and contributors are expected to\nadhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Factionmailer-markdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Factionmailer-markdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Factionmailer-markdown/lists"}