From d391cf1c0d67c30b0430f16e010f74bec4a5f843 Mon Sep 17 00:00:00 2001 From: Vasiliy Yakliushin Date: Sun, 28 Apr 2019 20:09:32 +0200 Subject: [PATCH] Add pandoc support Here I try to fix an another warning from tests. ``` cannot load such file -- pandoc-ruby: skipping markdown tests with Tilt::PandocTemplate ``` `pandoc-ruby` is not defined in Gemfile, so I add it there. This gem has a prerequisite dependency `pandoc` application that can be installed via homebrew. That's why I update travis.yml to make it available during a test run. The final step to make it work is to exclude `outvar` from the option's list provided to the template. When `pandoc` application is called with unsupported parameters it stops the execution and returns an error. --- .travis.yml | 4 +++- Gemfile | 1 + README.md | 2 ++ lib/sinatra/base.rb | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3e749f776..2620251661 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,9 @@ addons: - ubuntu-toolchain-r-test packages: - g++-4.8 - + homebrew: + packages: + - pandoc rvm: - 2.2.10 - 2.3.8 diff --git a/Gemfile b/Gemfile index 13bee90de0..af675416d6 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ if RUBY_ENGINE == "ruby" gem 'sass' gem 'reel-rack' gem 'celluloid', '~> 0.16.0' + gem 'pandoc-ruby', '~> 2.0.2' gem 'simplecov', require: false end diff --git a/README.md b/README.md index 336ac2b994..effb719297 100644 --- a/README.md +++ b/README.md @@ -750,6 +750,8 @@ template, you almost always want to pass locals to it. BlueCloth, kramdown, maruku + commonmarker + pandoc diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index d9c3164a1e..312764ada5 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -722,6 +722,7 @@ def liquid(template, options = {}, locals = {}, &block) end def markdown(template, options = {}, locals = {}) + options[:default_outvar] = false render :markdown, template, options, locals end @@ -825,10 +826,11 @@ def render(engine, data, options = {}, locals = {}, &block) content_type = options.delete(:content_type) || content_type layout_engine = options.delete(:layout_engine) || engine scope = options.delete(:scope) || self + default_outvar = options.delete(:default_outvar) != false options.delete(:layout) # set some defaults - options[:outvar] ||= '@_out_buf' + options[:outvar] ||= '@_out_buf' if default_outvar options[:default_encoding] ||= settings.default_encoding # compile and render template