From ee6e68b0293a524883f69fd0734f667a0112d5d8 Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Wed, 2 Oct 2019 16:44:21 -0500 Subject: [PATCH] Rails 6 support (again) (#50) * Rails 6 support * Added Separate appraisal for Rails 6 RC1 * Remove debugging * Add rails-6 builds to Travis * Polish Rails 6 support * Changelog for v3.1.0 * whitespace * Update Gemfiles --- .gitignore | 1 + .travis.yml | 6 +- Appraisals | 5 + CHANGELOG.md | 4 + Gemfile | 1 - Gemfile.lock | 94 ------------------ README.md | 15 +++ gemfiles/rails_5.gemfile.lock | 4 +- gemfiles/rails_51.gemfile.lock | 4 +- gemfiles/rails_52.gemfile.lock | 4 +- gemfiles/rails_6.gemfile | 9 ++ gemfiles/rails_6.gemfile.lock | 153 ++++++++++++++++++++++++++++++ gemfiles/rails_head.gemfile.lock | 4 +- lib/maildown.rb | 10 +- lib/maildown/ext/action_mailer.rb | 20 +++- lib/maildown/handlers/markdown.rb | 18 ++-- lib/maildown/version.rb | 2 +- 17 files changed, 233 insertions(+), 121 deletions(-) delete mode 100644 Gemfile.lock create mode 100644 gemfiles/rails_6.gemfile create mode 100644 gemfiles/rails_6.gemfile.lock diff --git a/.gitignore b/.gitignore index 6137c2e..172b635 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ test/dummy/.sass-cache *.gem .ruby-version .DS_Store +Gemfile.lock diff --git a/.travis.yml b/.travis.yml index 78ae12e..d66726f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ before_install: - gem install bundler --no-document rvm: - - 2.3.8 - 2.4.6 - 2.5.5 - 2.6.3 @@ -17,10 +16,15 @@ gemfile: - gemfiles/rails_5.gemfile - gemfiles/rails_51.gemfile - gemfiles/rails_52.gemfile + - gemfiles/rails_6.gemfile - gemfiles/rails_head.gemfile matrix: exclude: + - rvm: 2.3.8 + gemfile: gemfiles/rails_6.gemfile + - rvm: 2.4.6 + gemfile: gemfiles/rails_6.gemfile - rvm: 2.3.8 gemfile: gemfiles/rails_head.gemfile - rvm: 2.4.6 diff --git a/Appraisals b/Appraisals index cce208f..76a289a 100644 --- a/Appraisals +++ b/Appraisals @@ -13,6 +13,11 @@ appraise "rails-52" do gem "sqlite3", "~> 1.3.6" end +appraise "rails-6" do + gem "rails", "6.0.0" + gem "sqlite3", "~> 1.4" +end + appraise "rails-head" do gem "rails", git: "https://github.com/rails/rails.git" gem "sqlite3", "~> 1.4" diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ceb5a2..8593afc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.0 + +- Support for Rails 6 (https://github.com/schneems/maildown/pull/50) + ## 3.0.3 - Remove an Action View deprecation in Rails 6 (https://github.com/schneems/maildown/pull/45) diff --git a/Gemfile b/Gemfile index edcf09e..552d791 100644 --- a/Gemfile +++ b/Gemfile @@ -12,5 +12,4 @@ gemspec # To use debugger # gem 'debugger' - gem "appraisal" diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 1d1492b..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,94 +0,0 @@ -PATH - remote: . - specs: - maildown (3.0.3) - actionmailer (>= 4.0.0) - kramdown - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (5.1.5) - actionpack (= 5.1.5) - actionview (= 5.1.5) - activejob (= 5.1.5) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.1.5) - actionview (= 5.1.5) - activesupport (= 5.1.5) - rack (~> 2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.5) - activesupport (= 5.1.5) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.5) - activesupport (= 5.1.5) - globalid (>= 0.3.6) - activesupport (5.1.5) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - builder (3.2.3) - concurrent-ruby (1.0.5) - crass (1.0.3) - erubi (1.7.1) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - kramdown (2.1.0) - loofah (2.2.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (0.9.0) - mini_mime (1.0.1) - mini_portile2 (2.3.0) - minitest (5.11.3) - nokogiri (1.8.2) - mini_portile2 (~> 2.3.0) - rack (2.0.4) - rack-test (0.8.3) - rack (>= 1.0, < 3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.1.5) - actionpack (= 5.1.5) - activesupport (= 5.1.5) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.0) - sqlite3 (1.3.13) - thor (0.20.0) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal - maildown! - railties - rake - sqlite3 - -BUNDLED WITH - 2.0.2 diff --git a/README.md b/README.md index d3922c5..d95eee1 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,21 @@ Features we have that they don't: - Their gem is unmaintained, but honestly it's pretty simple and will keep working for some time. - We have way more monkeypatches than they do 🙀. + +## Test + +We use the appraisal gem to generate Gemfiles. Install all dependencies with this: + +``` +$ appraisal install +``` + +Run a specific suite like this: + +``` +$ BUNDLE_GEMFILE=gemfiles/rails_6.gemfile bundle exec rake test +``` + ## License MIT diff --git a/gemfiles/rails_5.gemfile.lock b/gemfiles/rails_5.gemfile.lock index 5845ac3..d923ae0 100644 --- a/gemfiles/rails_5.gemfile.lock +++ b/gemfiles/rails_5.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - maildown (3.0.2) + maildown (3.1.0) actionmailer (>= 4.0.0) kramdown @@ -126,4 +126,4 @@ DEPENDENCIES sqlite3 (~> 1.3.6) BUNDLED WITH - 1.16.1 + 2.0.2 diff --git a/gemfiles/rails_51.gemfile.lock b/gemfiles/rails_51.gemfile.lock index ffb0b2c..20a4950 100644 --- a/gemfiles/rails_51.gemfile.lock +++ b/gemfiles/rails_51.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - maildown (3.0.2) + maildown (3.1.0) actionmailer (>= 4.0.0) kramdown @@ -126,4 +126,4 @@ DEPENDENCIES sqlite3 (~> 1.3.6) BUNDLED WITH - 1.16.1 + 2.0.2 diff --git a/gemfiles/rails_52.gemfile.lock b/gemfiles/rails_52.gemfile.lock index 58af3c6..faa7fe2 100644 --- a/gemfiles/rails_52.gemfile.lock +++ b/gemfiles/rails_52.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - maildown (3.0.2) + maildown (3.1.0) actionmailer (>= 4.0.0) kramdown @@ -134,4 +134,4 @@ DEPENDENCIES sqlite3 (~> 1.3.6) BUNDLED WITH - 1.16.1 + 2.0.2 diff --git a/gemfiles/rails_6.gemfile b/gemfiles/rails_6.gemfile new file mode 100644 index 0000000..3de0970 --- /dev/null +++ b/gemfiles/rails_6.gemfile @@ -0,0 +1,9 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "rails", "6.0.0" +gem "sqlite3", "~> 1.4" + +gemspec path: "../" diff --git a/gemfiles/rails_6.gemfile.lock b/gemfiles/rails_6.gemfile.lock new file mode 100644 index 0000000..5d29586 --- /dev/null +++ b/gemfiles/rails_6.gemfile.lock @@ -0,0 +1,153 @@ +PATH + remote: .. + specs: + maildown (3.1.0) + actionmailer (>= 4.0.0) + kramdown + +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.0.0) + actionpack (= 6.0.0) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) + mail (>= 2.7.1) + actionmailer (6.0.0) + actionpack (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.0.0) + actionview (= 6.0.0) + activesupport (= 6.0.0) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.0) + actionpack (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) + nokogiri (>= 1.8.5) + actionview (6.0.0) + activesupport (= 6.0.0) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.0) + activesupport (= 6.0.0) + globalid (>= 0.3.6) + activemodel (6.0.0) + activesupport (= 6.0.0) + activerecord (6.0.0) + activemodel (= 6.0.0) + activesupport (= 6.0.0) + activestorage (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) + marcel (~> 0.3.1) + activesupport (6.0.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + zeitwerk (~> 2.1, >= 2.1.8) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + builder (3.2.3) + concurrent-ruby (1.1.5) + crass (1.0.4) + erubi (1.9.0) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (1.6.0) + concurrent-ruby (~> 1.0) + kramdown (2.1.0) + loofah (2.3.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.2) + mimemagic (0.3.3) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.12.2) + nio4r (2.5.2) + nokogiri (1.10.4) + mini_portile2 (~> 2.4.0) + rack (2.0.7) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (6.0.0) + actioncable (= 6.0.0) + actionmailbox (= 6.0.0) + actionmailer (= 6.0.0) + actionpack (= 6.0.0) + actiontext (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) + activemodel (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) + bundler (>= 1.3.0) + railties (= 6.0.0) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.2.0) + loofah (~> 2.2, >= 2.2.2) + railties (6.0.0) + actionpack (= 6.0.0) + activesupport (= 6.0.0) + method_source + rake (>= 0.8.7) + thor (>= 0.20.3, < 2.0) + rake (13.0.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.4.1) + thor (0.20.3) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + websocket-driver (0.7.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.4) + zeitwerk (2.1.10) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + maildown! + rails (= 6.0.0) + railties + rake + sqlite3 (~> 1.4) + +BUNDLED WITH + 2.0.2 diff --git a/gemfiles/rails_head.gemfile.lock b/gemfiles/rails_head.gemfile.lock index 2e1a7c7..37b5a8c 100644 --- a/gemfiles/rails_head.gemfile.lock +++ b/gemfiles/rails_head.gemfile.lock @@ -82,7 +82,7 @@ GIT PATH remote: .. specs: - maildown (3.0.2) + maildown (3.1.0) actionmailer (>= 4.0.0) kramdown @@ -155,4 +155,4 @@ DEPENDENCIES sqlite3 (~> 1.4) BUNDLED WITH - 1.16.1 + 2.0.2 diff --git a/lib/maildown.rb b/lib/maildown.rb index 013f546..f566461 100644 --- a/lib/maildown.rb +++ b/lib/maildown.rb @@ -11,14 +11,8 @@ def self.allow_indentation=(allow_indentations) @allow_indentations = allow_indentations end - def self.enable_layouts - puts "Maildown.enable_layouts is deprecated, setting this does nothing" - @enable_layouts - end - - def self.enable_layouts=(enable_layouts) - puts "Maildown.enable_layouts= is deprecated, setting this does nothing" - @enable_layouts = enable_layouts + def self.rails_6? + @rails_6 ||= Rails.version > "6" end end diff --git a/lib/maildown/ext/action_mailer.rb b/lib/maildown/ext/action_mailer.rb index 4ea55c6..5a73cd1 100644 --- a/lib/maildown/ext/action_mailer.rb +++ b/lib/maildown/ext/action_mailer.rb @@ -45,16 +45,32 @@ def each_template(paths, name, &block) return templates if templates.first.handler != Maildown::Handlers::Markdown html_template = templates.first + + # Cached template is already defined if html_template.instance_variable_defined?(:"@maildown_text_template") - text_template = html_template.instance_variable_get(:"@maildown_text_template") + text_template = html_template.instance_variable_get(:"@maildown_text_template") + return [html_template, text_template] + end + + if Maildown.rails_6? + text_template = html_template + .class + .new( + html_template.source, + html_template.identifier, + html_template.handler, + format: :text, + locals: html_template.locals + ) else text_template = html_template.dup formats = html_template.formats.dup.tap { |f| f.delete(:html) } text_template.formats = formats - html_template.instance_variable_set(:"@maildown_text_template", text_template) end + html_template.instance_variable_set(:"@maildown_text_template", text_template) + return [html_template, text_template] end end diff --git a/lib/maildown/handlers/markdown.rb b/lib/maildown/handlers/markdown.rb index ab04d8a..bd5a755 100644 --- a/lib/maildown/handlers/markdown.rb +++ b/lib/maildown/handlers/markdown.rb @@ -30,15 +30,22 @@ def self.call(template, source = nil) # with Rails 5.0+. source ||= template.source - # Match beginning whitespace but not newline http://rubular.com/r/uCXQ58OOC8 + # Match beginning whitespace but not newline + # http://rubular.com/r/uCXQ58OOC8 source.gsub!(/^[^\S\n]+/, ''.freeze) if Maildown.allow_indentation - compiled_source = erb_handler.call(template) + if Maildown.rails_6? + compiled_source = erb_handler.call(template, source) + is_html = (template.format != :text) + else + compiled_source = erb_handler.call(template) + is_html = template.formats.include?(:html) + end - if template.formats.include?(:html) - return "Maildown::MarkdownEngine.to_html(begin;#{compiled_source}; end)" + if is_html + "Maildown::MarkdownEngine.to_html(begin;#{compiled_source}; end)" else - return "Maildown::MarkdownEngine.to_text(begin;#{compiled_source}; end)" + "Maildown::MarkdownEngine.to_text(begin;#{compiled_source}; end)" end end end @@ -61,4 +68,3 @@ def self.call(template, source = nil) # to allow rails to even attempt to process the file, it needs this # handler with ".md.erb" to be registered. ActionView::Template.register_template_handler :"md.erb", Maildown::Handlers::Markdown - diff --git a/lib/maildown/version.rb b/lib/maildown/version.rb index 628f47e..e1bc907 100644 --- a/lib/maildown/version.rb +++ b/lib/maildown/version.rb @@ -1,3 +1,3 @@ module Maildown - VERSION = "3.0.3" + VERSION = "3.1.0" end