mjml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mjml/config.rb +7 -0
- data/lib/mjml/render.rb +57 -0
- data/lib/mjml/version.rb +3 -0
- data/lib/mjml.rb +16 -0
- data/mjml.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f57a6a317180b7aa3e60a648f98935a7ba835196
|
4
|
+
data.tar.gz: 277cce08fd8ef9c48865dc3818f154e220d60751
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 509e3f3f7850261c0ac30833324c9e0ffd8f670246277632d02f26c5817e38949757adcf8768b43840982df807f9eea84e3de1431a2d369149243133fb763d11
|
7
|
+
data.tar.gz: e02b504e6bec98782f292db5588e8d474685dbeaf4c9f1a916b1a99608780c4e6241aa3c403740a5d9a479b3f36809ca3060502157e3aba01bb2b2bd96b3508a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at sugiacupit@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Mjml
|
2
|
+
|
3
|
+
Allow use https://mjml.io/ in rails
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mjml'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mjml
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
#### Configuration
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Mjml.configure do |config|
|
27
|
+
config.exec_path = `which mjml`
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
#### Mailer
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
body = Mjml.render("#{Dir.pwd}/app/views/template") # => template.mjml
|
35
|
+
mail(to: xxx, subject: xxx, body: body, content_type: 'text/html')
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
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](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
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](http://contributor-covenant.org) code of conduct.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mjml"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mjml/config.rb
ADDED
data/lib/mjml/render.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Mjml
|
2
|
+
class Render
|
3
|
+
attr_accessor :path, :args, :content, :instance
|
4
|
+
|
5
|
+
def initialize(path, args, instance)
|
6
|
+
@path = path
|
7
|
+
@args = args
|
8
|
+
@instance = instance || binding
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
generate_mjml_file
|
13
|
+
generate_html_file
|
14
|
+
read_html_file
|
15
|
+
clear_tmp_files
|
16
|
+
content
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def generate_mjml_file
|
22
|
+
File.write(mjml_path, template_mjml)
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_html_file
|
26
|
+
`#{Config.exec_path} #{mjml_path} -o #{html_path}`
|
27
|
+
end
|
28
|
+
|
29
|
+
def read_html_file
|
30
|
+
@content ||= File.open(html_path).read
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_tmp_files
|
34
|
+
File.delete(mjml_path)
|
35
|
+
File.delete(html_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def mjml_path
|
39
|
+
@mjml_path ||= "#{Dir.pwd}/tmp/template-#{SecureRandom.uuid}.mjml"
|
40
|
+
end
|
41
|
+
|
42
|
+
def html_path
|
43
|
+
@html_path ||= "#{Dir.pwd}/tmp/template-#{SecureRandom.uuid}.html"
|
44
|
+
end
|
45
|
+
|
46
|
+
def template_variables
|
47
|
+
@template_variables ||= args.inject(instance) { |b, item| b.local_variable_set(item[0], item[1]) and b }
|
48
|
+
end
|
49
|
+
|
50
|
+
def template_mjml
|
51
|
+
@template_mjml ||= lambda do
|
52
|
+
template_erb = File.open(path).read
|
53
|
+
ERB.new(template_erb).result(template_variables)
|
54
|
+
end.call
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/mjml/version.rb
ADDED
data/lib/mjml.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
require "mjml/version"
|
5
|
+
require "mjml/render"
|
6
|
+
require "mjml/config"
|
7
|
+
|
8
|
+
module Mjml
|
9
|
+
def self.render(path, args, instance = nil)
|
10
|
+
Render.new(path, args, instance).execute
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield Config
|
15
|
+
end
|
16
|
+
end
|
data/mjml.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mjml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mjml"
|
8
|
+
spec.version = Mjml::VERSION
|
9
|
+
spec.authors = ["MQuy"]
|
10
|
+
spec.email = ["sugiacupit@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Template engine for mjml.}
|
13
|
+
spec.description = %q{Template engine for mjml. It help user reduce when writing email template.}
|
14
|
+
spec.homepage = "https://MQuy.github.io"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mjml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MQuy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Template engine for mjml. It help user reduce when writing email template.
|
56
|
+
email:
|
57
|
+
- sugiacupit@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/mjml.rb
|
72
|
+
- lib/mjml/config.rb
|
73
|
+
- lib/mjml/render.rb
|
74
|
+
- lib/mjml/version.rb
|
75
|
+
- mjml.gemspec
|
76
|
+
homepage: https://MQuy.github.io
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.5.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Template engine for mjml.
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|