From 017a02ed0992d88f7247414521833f8e79cbd750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nyl=C3=A9n?= Date: Fri, 4 Nov 2022 07:42:51 +0800 Subject: [PATCH] feat: update mrml and set up github action matrix (#44) * feat: update mrml and set up github action matrix * feat: add rust matrix * fix * fixes --- .github/workflows/ruby.yml | 72 ++++++----- .gitignore | 1 + .tool-versions | 4 +- Gemfile.lock | 120 ------------------ LICENSE.txt => LICENSE | 2 +- README.md | 4 +- lib/mrml/rails/handler.rb | 3 +- mrml-rails.gemspec | 2 +- spec/support/templates/layouts/mailer.mjml | 32 ++++- .../mrml_test_mailer/normal_email.mjml | 6 +- 10 files changed, 84 insertions(+), 162 deletions(-) delete mode 100644 Gemfile.lock rename LICENSE.txt => LICENSE (95%) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 4656de7..aa3d39e 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,38 +9,42 @@ on: jobs: build: name: ruby - runs-on: ubuntu-latest - + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + ruby: ["2.7", "3.0", "3.1"] + rust: ["1.51.0", "1.54.0", "1.60.0", "1.62.1", "1.65.0"] + runs-on: ${{ matrix.os }} + steps: - - uses: actions/checkout@v2 - with: - persist-credentials: false - - name: Read .tool-versions - uses: marocchino/tool-versions-action@v1 - id: versions - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - - name: Set up Rust - uses: hecrj/setup-rust-action@v1 - with: - rust-version: ${{ steps.versions.outputs.rust}} - - name: Cache gems - uses: actions/cache@v1 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('.tool-versions') }}-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems-${{ hashFiles('.tool-versions') }}-${{ hashFiles('**/Gemfile.lock') }} - - name: Run yarn - run: yarn - - name: Install dependencies - run: | - gem install bundler - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 - env: - RAILS_ENV: test - - name: Run tests - run: bundle exec rake spec - env: - RAILS_ENV: test + - uses: actions/checkout@v2 + with: + persist-credentials: false + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Set up Rust + uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + - name: Cache gems + uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('.tool-versions') }}-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems-${{ hashFiles('.tool-versions') }}-${{ hashFiles('**/Gemfile.lock') }} + - name: Run yarn + run: yarn + - name: Install dependencies + run: | + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + env: + RAILS_ENV: test + - name: Run tests + run: bundle exec rake spec + env: + RAILS_ENV: test diff --git a/.gitignore b/.gitignore index 783440f..faf44d4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ # rspec failure tracking .rspec_status *.gem +Gemfile.lock diff --git a/.tool-versions b/.tool-versions index c6818c4..88918ef 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -ruby 2.7.5 -rust 1.59.0 +ruby 3.1.2 +rust 1.65.0 diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index b6e424d..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,120 +0,0 @@ -PATH - remote: . - specs: - mrml-rails (0.2.0) - actionmailer (>= 3.1) - mrml (>= 0.2, < 0.9) - railties (>= 3.1) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) - globalid (>= 0.3.6) - activesupport (5.2.8.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - builder (3.2.4) - concurrent-ruby (1.1.10) - crass (1.0.6) - diff-lcs (1.5.0) - erubi (1.10.0) - ffi (1.15.5) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.11.0) - concurrent-ruby (~> 1.0) - loofah (2.18.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.4.0) - minitar (0.9) - minitest (5.15.0) - mrml (0.8.0) - ffi - thermite - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) - rack (2.2.4) - rack-test (2.0.2) - rack (>= 1.3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rake (13.0.6) - rspec (3.11.0) - rspec-core (~> 3.11.0) - rspec-expectations (~> 3.11.0) - rspec-mocks (~> 3.11.0) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-rails (5.1.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.11.0) - thermite (0.13.0) - minitar (~> 0.5) - rake (>= 10) - tomlrb (~> 1.2) - thor (1.2.1) - thread_safe (0.3.6) - tomlrb (1.3.0) - tzinfo (1.2.9) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - mrml-rails! - rake (~> 13.0) - rspec (~> 3.11) - rspec-rails (~> 5.0, >= 4.0.2) - -BUNDLED WITH - 2.1.4 diff --git a/LICENSE.txt b/LICENSE similarity index 95% rename from LICENSE.txt rename to LICENSE index ce51e2e..5fcc36f 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Joakim Nylén +Copyright (c) 2021-2022 Joakim Nylén, Odd Camp AB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bd5ade1..bdd28ec 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ `mrml-rails` is a ActionMailer templating engine that uses the Rust-based MRML compiler in order to compile MJML files into pure HTML. +**Minimum Rust version supported is `1.51.0`** + ## Installation Add this line to your application's Gemfile: @@ -36,7 +38,7 @@ I.e.: `sign_up.mjml`, `notification.mjml` 2. Add a RustConfig with: ``` -VERSION=1.57.0 +VERSION=1.65.0 RUST_SKIP_BUILD=1 ``` diff --git a/lib/mrml/rails/handler.rb b/lib/mrml/rails/handler.rb index aff3b9d..a07bf5f 100644 --- a/lib/mrml/rails/handler.rb +++ b/lib/mrml/rails/handler.rb @@ -21,7 +21,8 @@ def call(template, source = nil) end if compiled_source =~ //i - "MRML.to_html(begin;#{compiled_source};end).html_safe" + # "MRML.to_html(begin;#{compiled_source};end).html_safe" + "MRML::Template.new(begin;#{compiled_source};end).to_html" else compiled_source end diff --git a/mrml-rails.gemspec b/mrml-rails.gemspec index 9b63dbb..ed857d1 100644 --- a/mrml-rails.gemspec +++ b/mrml-rails.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| spec.metadata['changelog_uri'] = 'https://github.com/oddcamp/mrml-rails/releases' spec.add_runtime_dependency 'actionmailer', '>= 3.1' - spec.add_runtime_dependency 'mrml', '>= 0.2', '< 0.9' + spec.add_runtime_dependency 'mrml', '~> 1.0' spec.add_runtime_dependency 'railties', '>= 3.1' spec.add_development_dependency 'rspec', '~> 3.10' spec.add_development_dependency 'rspec-rails', '>= 4.0.2', '~> 5.0' diff --git a/spec/support/templates/layouts/mailer.mjml b/spec/support/templates/layouts/mailer.mjml index df8eeb6..6a55375 100644 --- a/spec/support/templates/layouts/mailer.mjml +++ b/spec/support/templates/layouts/mailer.mjml @@ -1,5 +1,35 @@ +<% + @font_family = 'Helvetica Neue' +%> + - + + + + + + + + + + + + + ul { + list-style: none; + margin: 0; + padding: 0; + } + + @media (max-width:640px) { + .hidden { + display: none !important; + } + } + + + + <%= yield %> diff --git a/spec/support/templates/mrml_test_mailer/normal_email.mjml b/spec/support/templates/mrml_test_mailer/normal_email.mjml index 2e71344..bcb1f70 100644 --- a/spec/support/templates/mrml_test_mailer/normal_email.mjml +++ b/spec/support/templates/mrml_test_mailer/normal_email.mjml @@ -1,3 +1,7 @@ +<% + text = 'something' +%> + @@ -7,7 +11,7 @@ -

We inform you about something

+

We inform you about <%= text %>

Please visit this link