Skip to content

Commit

Permalink
Deprecate erubis, wikicloth, and maruku templates as they require mod…
Browse files Browse the repository at this point in the history
…ifying string literals

Ruby 3.4 will warn when modifying string literals, and a later
Ruby version will treat string literals as frozen, at which point
these will break.

Silence the verbose warnings when running tests.

I'm open to undeprecating these if the issues are fixed, but these
all seem unmaintained:

* Erubis: Last commit 13 years ago
* Wikicloth: Last commit 3 years ago
* Maruku: Last commit 7 years ago

Erubis is easily replaced by Erubi, and Maruku by another markdown
parser (Tilt supports many).  I'm not sure if there is a replacement
for Wikicloth.

While here, make checked_describe and check_require in test_helper
take multiple arguments.
  • Loading branch information
jeremyevans committed May 22, 2024
1 parent b803c18 commit b008ed8
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Support commonmarker 1.0+ API (unasuke) (#10)
* Make etanni template work with frozen string literals (jeremyevans)
* Deprecate erubis, wikicloth, and maruku templates as they require modifying frozen string literals (jeremyevans)

## 2.3.0 (2023-09-14)

Expand Down
2 changes: 2 additions & 0 deletions lib/tilt/erubis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require_relative 'erb'
require 'erubis'

warn 'tilt/erubis is deprecated, as erubis requires modifying string literals', uplevel: 1

module Tilt
# Erubis template implementation. See:
# http://www.kuwata-lab.com/erubis/
Expand Down
2 changes: 2 additions & 0 deletions lib/tilt/maruku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require_relative 'template'
require 'maruku'

warn 'tilt/maruku is deprecated, as maruku requires modifying string literals', uplevel: 1

# Maruku markdown implementation. See: https://github.com/bhollis/maruku
Tilt::MarukuTemplate = Tilt::StaticTemplate.subclass do
Maruku.new(@data, @options).to_html
Expand Down
2 changes: 2 additions & 0 deletions lib/tilt/wikicloth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require_relative 'template'
require 'wikicloth'

warn 'tilt/wikicloth is deprecated, as wikicloth requires modifying string literals', uplevel: 1

# WikiCloth implementation. See: https://github.com/nricciar/wikicloth
Tilt::WikiClothTemplate = Tilt::StaticTemplate.subclass do
parser = @options.delete(:parser) || WikiCloth::Parser
Expand Down
27 changes: 21 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,35 @@

FrozenError = RuntimeError unless defined?(FrozenError)

def self.checked_require(lib)
require lib
def self.checked_require(*libs)
verbose, $VERBOSE = $VERBOSE, nil
libs.each do |lib|
require lib
end
rescue LoadError => e
warn "skipping tests of #{lib}: #{e.class}: #{e.message}"
$VERBOSE = verbose
warn "skipping tests of #{libs.first}: #{e.class}: #{e.message}"
else
$VERBOSE = verbose
yield
end

def self.checked_describe(lib, &block)
checked_require lib do
describe(lib, &block)
def self.checked_describe(*libs, &block)
checked_require(*libs) do
describe(libs.first, &block)
end
end

module IgnoreVerboseWarnings
def setup
@_verbose = $VERBOSE
$VERBOSE = nil
end

def teardown
$VERBOSE = @_verbose
end
end

class Minitest::Spec
# Returns true if line numbers are reported incorrectly in heredocs.
Expand Down
2 changes: 2 additions & 0 deletions test/tilt_erubistemplate_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'test_helper'

checked_describe 'tilt/erubis' do
include IgnoreVerboseWarnings

data = (<<END).freeze
<html>
<body>
Expand Down
24 changes: 14 additions & 10 deletions test/tilt_markdown_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,20 @@ def nrender(text, options = {})
end
end

markdown_describe.call 'tilt/maruku', :MarukuTemplate do
skip_tests = [
':escape_html => true',
'smartypants by default',
'smartypants if :smartypants => false',
'smart quotes by default',
'smart quotes if :smartypants => false',
]
instance_methods.grep(/#{Regexp.union(skip_tests)}\z/).each do |method|
undef_method method
checked_require('tilt/maruku') do
markdown_describe.call 'tilt/maruku', :MarukuTemplate do
include IgnoreVerboseWarnings

skip_tests = [
':escape_html => true',
'smartypants by default',
'smartypants if :smartypants => false',
'smart quotes by default',
'smart quotes if :smartypants => false',
]
instance_methods.grep(/#{Regexp.union(skip_tests)}\z/).each do |method|
undef_method method
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/tilt_marukutemplate_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'test_helper'

checked_describe 'tilt/maruku' do
include IgnoreVerboseWarnings

it "registered below Kramdown" do
%w[md mkd markdown].each do |ext|
lazy = Tilt.lazy_map[ext]
Expand Down
2 changes: 2 additions & 0 deletions test/tilt_wikiclothtemplate_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'test_helper'

checked_describe 'tilt/wikicloth' do
include IgnoreVerboseWarnings

it "is registered for '.mediawiki' files" do
assert_equal Tilt::WikiClothTemplate, Tilt['test.mediawiki']
end
Expand Down

0 comments on commit b008ed8

Please sign in to comment.