-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mykola Basov
committed
Sep 2, 2016
1 parent
f636a9b
commit d69a284
Showing
3 changed files
with
103 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,127 @@ | ||
# MJML Ruby | ||
|
||
[![Build Status](https://travis-ci.org/kolybasov/mjml-ruby.svg?branch=master)](https://travis-ci.org/kolybasov/mjml-ruby) | ||
[![Gem](https://img.shields.io/gem/v/mjml-ruby.svg?maxAge=2592000)]() | ||
[![Travis](https://img.shields.io/travis/kolybasov/mjml-ruby.svg?maxAge=2592000)]() | ||
[![Gemnasium](https://img.shields.io/gemnasium/kolybasov/mjml-ruby.svg?maxAge=2592000)]() | ||
[![Code Climate](https://codeclimate.com/github/kolybasov/mjml-ruby/badges/gpa.svg)](https://codeclimate.com/github/kolybasov/mjml-ruby) | ||
|
||
#### [!] REQUIRE NODEJS | ||
|
||
[MJML](https://mjml.io) parser and template engine for Ruby. | ||
Allows to create email temapltes without mess. | ||
|
||
## Installation | ||
## Install | ||
|
||
Add this line to your Gemfile: | ||
Add to Gemfile: | ||
|
||
```ruby | ||
gem 'mjml-ruby', git: 'https://github.com/kolybasov/mjml-ruby.git', require: 'mjml' | ||
gem 'mjml-ruby', '~> 0.1.0', require: 'mjml' | ||
``` | ||
|
||
Install [NodeJS](https://nodejs.org/en/) and [MJML](https://mjml.io) (both installations will works local and global). | ||
|
||
``` | ||
$ npm install [-g] mjml@^2.0 | ||
$ npm install -g mjml@^2.3.3 | ||
$ bundle install | ||
``` | ||
|
||
Run bundle install: | ||
## Usage | ||
|
||
#### With Rails | ||
|
||
```erb | ||
<!-- app/views/layouts/mailer.html.mjml --> | ||
<mjml> | ||
<mj-body> | ||
<mj-container> | ||
<%= yield %> | ||
</mj-container> | ||
<mj-body> | ||
</mjml> | ||
``` | ||
$ bundle install | ||
|
||
```erb | ||
<!-- app/views/welcome_mailer/welcome.html.mjml --> | ||
<mj-text>Hello, <%= @user.name %></mj-text> | ||
``` | ||
|
||
```ruby | ||
class WelcomeMailer < ApplicationMailer | ||
def welcome(user) | ||
@user = user | ||
mail(to: @user.email, subject: 'Welcome') | ||
end | ||
end | ||
``` | ||
|
||
#### With [Tilt](https://github.com/rtomayko/tilt) | ||
|
||
```erb | ||
<!-- templates/hello.mjml --> | ||
<mjml> | ||
<mj-body> | ||
<mj-container> | ||
<mj-text>Hello, world!</mj-text> | ||
</mj-container> | ||
<mj-body> | ||
</mjml> | ||
``` | ||
|
||
```ruby | ||
require 'tilt' | ||
require 'ruby-mjml' | ||
|
||
template = Tilt.new('templates/hello.mjml') | ||
template.render # returns compiled HTML | ||
``` | ||
|
||
#### With [mail](https://github.com/mikel/mail) gem | ||
|
||
```erb | ||
<!-- hello.mjml --> | ||
<mjml> | ||
<mj-body> | ||
<mj-container> | ||
<mj-text>Hello, world!</mj-text> | ||
</mj-container> | ||
<mj-body> | ||
</mjml> | ||
``` | ||
|
||
```ruby | ||
require 'mail' | ||
require 'mjml-ruby' | ||
|
||
template = File.open('hello.mjml', 'rb') { |f| MJML::Parser.new.call(f) } | ||
|
||
Mail.deliver do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Hello' | ||
body template | ||
end | ||
``` | ||
|
||
## Configuration | ||
|
||
```ruby | ||
MJML.configure do |config| | ||
config.bin_path = '/bin/mjml' | ||
end | ||
``` | ||
|
||
### TODO | ||
## TODO | ||
- [x] Create parser | ||
- [x] Make it configurable | ||
- [x] Create Tilt interface | ||
- [x] Create Sprockets interface | ||
- [x] Create Railtie | ||
- [x] Setup Travis | ||
- [ ] Add usage guide | ||
- [x] Add usage guide | ||
- [ ] Fix tests on CI | ||
- [ ] Add more tests | ||
- [ ] Improove docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters