Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch over to GitHub Actions and fix various issues with the test suite #368

Merged
merged 11 commits into from
Jul 22, 2022
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Test suite"

on: [push]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
# We test on all stable versions of Ruby
- "2.7"
- "3.0"
- "3.1"
- "jruby"
# … but only the primary templates
bundle_without: ["secondary:development"]
title: ["primary templates"]

# In addition we test for the secondary templates on the latest version of Ruby
include:
- ruby: "3.1"
bundle_without: "primary:development"
title: "secondary templates"

env:
BUNDLE_WITHOUT: ${{ matrix.bundle_without }}
name: Ruby ${{ matrix.ruby }} (${{ matrix.title }})
steps:
- uses: actions/checkout@v2

- name: Install dependencies
# WikiCloth needs IDN
# Pandoc needs Pandoc
run: sudo apt-get install -y libidn11-dev pandoc

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run test suite
run: bundle exec rake
35 changes: 19 additions & 16 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ group :development do
gem 'ronn', '~> 0.7.3'
end

can_execjs = (RUBY_VERSION >= '1.9.3')

group :primary do
gem 'builder'
gem 'haml', '>= 4' if RUBY_VERSION >= '2.0.0'
gem 'haml', '>= 4'
gem 'erubis'
gem 'markaby'

Expand All @@ -27,17 +25,15 @@ group :primary do
gem 'sass-embedded'
end

if can_execjs
gem 'less'
gem 'coffee-script'
gem 'livescript'
gem 'babel-transpiler'
gem 'typescript-node'
end
gem 'less'
gem 'coffee-script'
gem 'livescript'
gem 'babel-transpiler'
gem 'typescript-node'
end

platform :mri do
gem 'duktape', '~> 1.3.0.6' if can_execjs
gem 'duktape', '~> 1.3.0.6'
end

group :secondary do
Expand All @@ -55,19 +51,26 @@ group :secondary do
gem 'pdf-reader', '~> 1.3.3'
end

gem 'nokogiri' if RUBY_VERSION > '1.9.2'
gem 'nokogiri'

# Both rdiscount and bluecloth embeds Discount and loading
# both at the same time causes strange issues.
discount_gem = ENV["DISCOUNT_GEM"] || "rdiscount"
raise "DISCOUNT_GEM must be set to 'rdiscount' or 'bluecloth'" if !%w[rdiscount bluecloth].include?(discount_gem)

platform :ruby do
gem 'wikicloth'
gem 'rinku' # dependency for wikicloth for handling links

gem 'yajl-ruby'
gem 'redcarpet' if RUBY_VERSION > '1.8.7'
gem 'rdiscount', '>= 2.1.6' if RUBY_VERSION != '1.9.2'
gem 'redcarpet'
gem 'rdiscount', '>= 2.1.6' if discount_gem == "rdiscount"
gem 'RedCloth'
gem 'commonmarker' if RUBY_VERSION > '1.9.3'
gem 'commonmarker'
end

platform :mri do
gem 'bluecloth'
gem 'bluecloth' if discount_gem == "bluecloth"
end
end

38 changes: 23 additions & 15 deletions lib/tilt/pandoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,38 @@ module Tilt
class PandocTemplate < Template
self.default_mime_type = 'text/html'

def tilt_to_pandoc_mapping
{ :smartypants => :smart,
:escape_html => { :f => 'markdown-raw_html' },
:commonmark => { :f => 'commonmark' },
:markdown_strict => { :f => 'markdown_strict' }
}
end

# turn options hash into an array
# Map tilt options to pandoc options
# Replace hash keys with value true with symbol for key
# Remove hash keys with value false
# Leave other hash keys untouched
def pandoc_options
options.reduce([]) do |sum, (k,v)|
case v
when true
sum << (tilt_to_pandoc_mapping[k] || k)
when false
sum
result = []
from = "markdown"
smart_extension = "-smart"
options.each do |k,v|
case k
when :smartypants
smart_extension = "+smart" if v
when :escape_html
from = "markdown-raw_html" if v
when :commonmark
from = "commonmark" if v
when :markdown_strict
from = "markdown_strict" if v
else
sum << { k => v }
case v
when true
result << k
when false
# do nothing
else
result << { k => v }
end
end
end
result << { :f => from + smart_extension }
result
end

def prepare
Expand Down
19 changes: 12 additions & 7 deletions lib/tilt/rst-pandoc.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
require 'tilt/template'
require 'tilt/pandoc'
require 'pandoc'

module Tilt
# Pandoc reStructuredText implementation. See:
# http://pandoc.org/
# Use PandocTemplate and specify input format
class RstPandocTemplate < PandocTemplate
def tilt_to_pandoc_mapping
{ :smartypants => :smart }
self.default_mime_type = 'text/html'

def prepare
@engine = PandocRuby.new(data, :f => "rst")
@output = nil
end

def evaluate(scope, locals, &block)
@output ||= @engine.to_html.strip
end

def pandoc_options
options.merge!(f: 'rst')
super
def allows_script?
false
end
end
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class << self
alias_method :describe, :context
end

# Returns true if line numbers are reported incorrectly in heredocs.
def heredoc_line_number_bug?
# https://github.com/jruby/jruby/issues/7272
RUBY_PLATFORM == "java"
end

private

def self.context_name(name)
Expand Down
6 changes: 0 additions & 6 deletions test/tilt_asciidoctor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class AsciidoctorTemplateTest < Minitest::Test
HTML5_OUTPUT = "<div class=\"sect1\"><h2 id=\"_hello_world\">Hello World!</h2><div class=\"sectionbody\"></div></div>"
DOCBOOK45_OUTPUT = "<section id=\"_hello_world\"><title>Hello World!</title></section>"
DOCBOOK5_OUTPUT = "<section xml:id=\"_hello_world\"><title>Hello World!</title></section>"

def strip_space(str)
Expand All @@ -30,11 +29,6 @@ def strip_space(str)
assert_equal HTML5_OUTPUT, strip_space(template.render)
end

test "preparing and evaluating docbook 4.5 templates on #render" do
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'docbook45'}) { |t| "== Hello World!" }
assert_equal DOCBOOK45_OUTPUT, strip_space(template.render)
end

test "preparing and evaluating docbook 5 templates on #render" do
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'docbook5'}) { |t| "== Hello World!" }
assert_equal DOCBOOK5_OUTPUT, strip_space(template.render)
Expand Down
9 changes: 0 additions & 9 deletions test/tilt_commonmarkertemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ class CommonMarkerTemplateTest < Minitest::Test

assert_match(expected, template.render)
end

test "All CommonMarker parse options are available to users" do
assert_empty(CommonMarker::Config::Parse.keys - (Tilt::CommonMarkerTemplate::PARSE_OPTIONS + [:DEFAULT]))
end

test "All CommonMarker render options are available to users" do
assert_empty(CommonMarker::Config::Render.keys - (Tilt::CommonMarkerTemplate::RENDER_OPTIONS + [:DEFAULT]))
end

end
rescue LoadError
warn "Tilt::CommonMarkerTemplate (disabled)"
Expand Down
4 changes: 4 additions & 0 deletions test/tilt_etannitemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class EtanniTemplateTest < Minitest::Test
line = boom.backtrace.grep(/^test\.etn:/).first
assert line, "Backtrace didn't contain test.etn"
_file, line, _meth = line.split(":")
skip if heredoc_line_number_bug?
assert_equal '13', line
end
end
Expand All @@ -72,6 +73,7 @@ class EtanniTemplateTest < Minitest::Test
line = boom.backtrace.first
file, line, _meth = line.split(":")
assert_equal 'test.etn', file
skip if heredoc_line_number_bug?
assert_equal '6', line
end
end
Expand Down Expand Up @@ -142,6 +144,7 @@ class Scope
line = boom.backtrace.grep(/^test\.etn:/).first
assert line, "Backtrace didn't contain test.etn"
_file, line, _meth = line.split(":")
skip if heredoc_line_number_bug?
assert_equal '13', line
end
end
Expand All @@ -158,6 +161,7 @@ class Scope
line = boom.backtrace.first
file, line, _meth = line.split(":")
assert_equal 'test.etn', file
skip if heredoc_line_number_bug?
assert_equal '6', line
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/tilt_pandoctemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class PandocTemplateTest < Minitest::Test
describe "passing in Pandoc options" do
test "generates footnotes" do
template = Tilt::PandocTemplate.new { |t| "Here is an inline note.^[Inlines notes are cool!]" }
assert_equal "<p>Here is an inline note.<a href=\"#fn1\" class=\"footnoteRef\" id=\"fnref1\"><sup>1</sup></a></p>\n<div class=\"footnotes\">\n<hr />\n<ol>\n<li id=\"fn1\"><p>Inlines notes are cool!<a href=\"#fnref1\">↩</a></p></li>\n</ol>\n</div>", template.render
result = template.render
assert_match "Here is an inline note", result
assert_match "Inlines notes are cool!", result
end

test "doesn't generate footnotes with markdown_strict option" do
Expand Down
4 changes: 4 additions & 0 deletions test/tilt_stringtemplate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class StringTemplateTest < Minitest::Test
line = boom.backtrace.grep(/^test\.str:/).first
assert line, "Backtrace didn't contain test.str"
_file, line, _meth = line.split(":")
skip if heredoc_line_number_bug?
assert_equal '13', line
end
end
Expand All @@ -68,6 +69,7 @@ class StringTemplateTest < Minitest::Test
line = boom.backtrace.first
file, line, _meth = line.split(":")
assert_equal 'test.str', file
skip if heredoc_line_number_bug?
assert_equal '6', line
end
end
Expand Down Expand Up @@ -139,6 +141,7 @@ class Scope
line = boom.backtrace.grep(/^test\.str:/).first
assert line, "Backtrace didn't contain test.str"
_file, line, _meth = line.split(":")
skip if heredoc_line_number_bug?
assert_equal '13', line
end
end
Expand All @@ -155,6 +158,7 @@ class Scope
line = boom.backtrace.first
file, line, _meth = line.split(":")
assert_equal 'test.str', file
skip if heredoc_line_number_bug?
assert_equal '6', line
end
end
Expand Down