Socket
Book a DemoInstallSign in
Socket

mjml

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mjml

0.0.8
bundlerRubygems
Version published
Maintainers
1
Created
Source

Mjml

Allow use https://mjml.io/ in rails

Installation

Add this line to your application's Gemfile:

gem 'mjml'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mjml

Usage

Configuration

Mjml.configure do |config|
  config.exec_path = `which mjml`
end

You have to install mjml compiler via npm install mjml to use this gem

In case of you don't set exec_path, The exec_path will be set default as node_modules/mjml/bin/mjml. If you use heroku you can config multiple buildpacks to make it support nodejs

Mjmj#render

Mjml.render(template_path, template_variable, binding): this render method accept three parameters

  • template_path: the location of your template
  • template_variable: these variables which be passed to template so that you can use something like this <div><%= name %></div>
  • binding: you can get something like mailer binding to support rails path helper

Mailer

You can use in mailer

body = Mjml.render("#{Dir.pwd}/app/views/template.mjml", { name: 'Mjml parser' })
mail(to: xxx, subject: xxx, body: body, content_type: 'text/html')

and template.mjml

<mjml>
  <mj-body>
    <mj-container>
      <mj-section>
        <mj-column>
          <mj-image width="100" src="https://mjml.io/assets/img/logo-small.png"></mj-image>
          <mj-divider border-color="#F45E43"></mj-divider>
          <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello <%= name %></mj-text>
        </mj-column>
      </mj-section>
    </mj-container>
  </mj-body>
</mjml>

To support render partial inside template, you have to add this into your mime types

Mime::Type.register_alias "text/plain", :mjml

and you can use in template.mjml

<%= render partial: 'xxxx', formats: [:mjml] %>

Development

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/MQuy/mjml. 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.

FAQs

Package last updated on 10 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.