diff --git a/README.md b/README.md index d296a3a..9f8a66e 100644 --- a/README.md +++ b/README.md @@ -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 + + + + + + <%= yield %> + + + ``` -$ bundle install + +```erb + + +Hello, <%= @user.name %> +``` + +```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 + + + + + + Hello, world! + + + +``` + +```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, world! + + + +``` + +```ruby +require 'mail' +require 'mjml-ruby' + +template = File.open('hello.mjml', 'rb') { |f| MJML::Parser.new.call(f) } + +Mail.deliver do + from 'example@mail.com' + to 'example@mail.com' + 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 diff --git a/lib/mjml.rb b/lib/mjml.rb index 0cd83c0..875b612 100644 --- a/lib/mjml.rb +++ b/lib/mjml.rb @@ -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 diff --git a/mjml-ruby.gemspec b/mjml-ruby.gemspec index d9d7e48..da44157 100644 --- a/mjml-ruby.gemspec +++ b/mjml-ruby.gemspec @@ -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