- Combines Liquid and extended Markdown (via Kramdown) for customer-safe templating of Rails pages and emails
- Integrates with Panoramic to add ActiveRecord database storage of templates for editing
- Generates both plain text and html parts of an email from a single template (replacing other markdown email gems)
- Supports html layouts for emails (unlike other markdown email gems)
Add this line to your application's Gemfile:
gem 'liquid_markdown', '~> 0.2.2'
# If you want to use database template
gem 'panoramic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install liquid_markdown
You can use liquid_markdown
in your mailer with .liqmd
file extension
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
def confirmation(user)
@user = user
mail(to: @user.email, subject: 'liquid markdown layout') do |format|
format.html
format.text
end
end
end
# app/views/user_mailer/confirmation.liqmd
# Hello {{user.email}},
You are now subscribed to our daily newsletter.
Thanks
------
ABC Org.
Please read full documentation in Panoramic
- Add following line to your
Gemfile
gem 'panoramic'
-
Your model should have the following fields:
body:text
,path:string
,locale:string
,handler:string
,partial:boolean
,format:string
-
Add below line to your Model
require 'liquid_markdown/resolver' # required
class TemplateStorage < ActiveRecord::Base
store_templates
# required
def self.resolver(options={})
LiquidMarkdown::Resolver.using self, options
end
end
Use liqmd
handler in your TemplateStorage
TemplateStorage.create(
body: "# Hello {{user.email}}, \n\n You have successfully subscribed to our
daily newsletter.",
path: 'user_mailer/confirmation',
handler: 'liqmd',
format: 'html'
)
- To use Panoramic resolver in your mailer
class UserMailer < ActionMailer::Base
prepend_view_path TemplateStorage.resolver
def confirmation(user)
@user = user
mail(
from: "someone@example.com",
to: @user.email,
subject: "Confirmation Link",
template_name: @user.template_name
)
end
end
We can compile Liquid templates into html and plain text version.
lm = LiquidMarkdown::Render.new("Hello {{user.profile.name}}!", {user: {profile: {name: 'Bob'}}})
lm.html # => "<p>Hello Bob!</p>"
lm.text # => "Hello Bob!"
lm = LiquidMarkdown::Render.new("# my first heading")
lm.html # => "<h1>my first heading</h1>"
lm.text # => "my first heading"
We can combine both Liquid and Markdown together, Liquid will get compiled first and then Markdown will get compiled
lm = LiquidMarkdown::Render.new("# Hello {{username | upcase}}", {username: 'Admin'})
lm.html # => "<h1>Hello ADMIN</h1>"
lm.text # => "Hello ADMIN"
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/buzzware/liquid_markdown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
- https://github.com/Shopify/liquid
- https://github.com/gettalong/kramdown
- https://github.com/andreapavoni/panoramic
- https://github.com/schneems/maildown
- https://github.com/fnando/actionmailer-markdown
The gem is available as open source under the terms of the MIT License.