2021-10-18 12:40:01 -04:00
|
|
|
require File.expand_path('helper', __dir__)
|
2010-09-11 08:34:41 -04:00
|
|
|
|
2011-04-15 05:00:07 -04:00
|
|
|
MarkdownTest = proc do
|
2010-09-11 08:34:41 -04:00
|
|
|
def markdown_app(&block)
|
|
|
|
mock_app do
|
2020-03-13 17:20:04 -04:00
|
|
|
set :views, __dir__ + '/views'
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
|
2011-04-15 05:00:07 -04:00
|
|
|
def setup
|
|
|
|
Tilt.prefer engine, 'markdown', 'mkd', 'md'
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the correct engine' do
|
|
|
|
assert_equal engine, Tilt[:md]
|
|
|
|
assert_equal engine, Tilt[:mkd]
|
|
|
|
assert_equal engine, Tilt[:markdown]
|
|
|
|
end
|
|
|
|
|
2010-09-11 08:34:41 -04:00
|
|
|
it 'renders inline markdown strings' do
|
|
|
|
markdown_app { markdown '# Hiya' }
|
|
|
|
assert ok?
|
2011-04-15 05:00:07 -04:00
|
|
|
assert_like "<h1>Hiya</h1>\n", body
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders .markdown files in views path' do
|
|
|
|
markdown_app { markdown :hello }
|
|
|
|
assert ok?
|
2011-04-15 05:00:07 -04:00
|
|
|
assert_like "<h1>Hello From Markdown</h1>", body
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error if template not found" do
|
|
|
|
mock_app { get('/') { markdown :no_such_template } }
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|
2011-04-15 05:14:23 -04:00
|
|
|
|
|
|
|
it "renders with inline layouts" do
|
|
|
|
mock_app do
|
|
|
|
layout { 'THIS. IS. #{yield.upcase}!' }
|
|
|
|
get('/') { markdown 'Sparta', :layout_engine => :str }
|
|
|
|
end
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_like 'THIS. IS. <P>SPARTA</P>!', body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders with file layouts" do
|
2012-05-21 17:21:59 -04:00
|
|
|
markdown_app {
|
|
|
|
markdown 'Hello World', :layout => :layout2, :layout_engine => :erb
|
|
|
|
}
|
2011-04-15 05:14:23 -04:00
|
|
|
assert ok?
|
|
|
|
assert_body "ERB Layout!\n<p>Hello World</p>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can be used in a nested fashion for partials and whatnot" do
|
|
|
|
mock_app do
|
|
|
|
template(:inner) { "hi" }
|
|
|
|
template(:outer) { "<outer><%= markdown :inner %></outer>" }
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { erb :outer }
|
2011-04-15 05:14:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_like '<outer><p>hi</p></outer>', body
|
|
|
|
end
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|
2011-01-25 03:27:15 -05:00
|
|
|
|
2022-02-27 05:18:25 -05:00
|
|
|
[
|
|
|
|
"Tilt::PandocTemplate",
|
|
|
|
"Tilt::CommonMarkerTemplate",
|
|
|
|
"Tilt::KramdownTemplate",
|
|
|
|
"Tilt::RedcarpetTemplate",
|
|
|
|
"Tilt::RDiscountTemplate",
|
|
|
|
"Tilt::MarukuTemplate"
|
|
|
|
].each do |template_name|
|
2011-04-15 05:00:07 -04:00
|
|
|
begin
|
2019-04-28 12:02:09 -04:00
|
|
|
template = Object.const_get(template_name)
|
|
|
|
|
|
|
|
klass = Class.new(Minitest::Test) { define_method(:engine) { template } }
|
2011-04-15 05:00:07 -04:00
|
|
|
klass.class_eval(&MarkdownTest)
|
2019-04-28 12:02:09 -04:00
|
|
|
|
|
|
|
name = template_name.split('::').last.sub(/Template$/, 'Test')
|
2012-12-12 06:42:16 -05:00
|
|
|
Object.const_set name, klass
|
2013-01-26 04:12:16 -05:00
|
|
|
rescue LoadError, NameError
|
2019-04-28 12:02:09 -04:00
|
|
|
warn "#{$!}: skipping markdown tests with #{template_name}"
|
2011-04-15 05:00:07 -04:00
|
|
|
end
|
2010-09-11 08:34:41 -04:00
|
|
|
end
|