Skip to content

Commit

Permalink
Publish v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykola Basov committed Sep 2, 2016
1 parent f636a9b commit d69a284
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 14 deletions.
108 changes: 99 additions & 9 deletions README.md
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
2 changes: 1 addition & 1 deletion lib/mjml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.setup!
def self.find_executable
local_path = File.expand_path('node_modules/.bin/mjml', Dir.pwd)
return local_path if File.file?(local_path)
`which mjml`.strip
`/usr/bin/which mjml`.strip
end
end

Expand Down
7 changes: 3 additions & 4 deletions mjml-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.require_paths = ['lib']

s.add_runtime_dependency 'dry-configurable', '~> 0.1.0'
s.add_runtime_dependency 'dry-configurable', '~> 0.1.7'

s.add_development_dependency 'rake'
s.add_development_dependency 'minitest', '~> 5.8.0', '>= 5.0.0'
s.add_development_dependency 'minitest', '~> 5.9.0', '>= 5.0.0'
s.add_development_dependency 'tilt', '~> 2.0.0', '>= 2.0.0'
s.add_development_dependency 'sprockets', '~> 3.0.0', '>= 3.0.0'
s.add_development_dependency 'actionpack', '>= 4.0.0'
s.add_development_dependency 'sprockets', '~> 3.7.0', '>= 3.0.0'
s.add_development_dependency 'byebug', '~> 9.0.0', '>= 9.0.0'
end

0 comments on commit d69a284

Please sign in to comment.