Skip to content

Commit

Permalink
Add pandoc support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
304 committed Apr 28, 2019
1 parent 5e2e41f commit d391cf1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -17,7 +17,9 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

homebrew:
packages:
- pandoc
rvm:
- 2.2.10
- 2.3.8
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -750,6 +750,8 @@ template, you almost always want to pass locals to it.
<a href="https://github.com/ged/bluecloth" title="BlueCloth">BlueCloth</a>,
<a href="https://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
<a href="https://github.com/bhollis/maruku" title="maruku">maruku</a>
<a href="https://github.com/gjtorikian/commonmarker" title="commonmarker">commonmarker</a>
<a href="https://github.com/alphabetum/pandoc-ruby" title="pandoc">pandoc</a>
</td>
</tr>
<tr>
Expand Down
4 changes: 3 additions & 1 deletion lib/sinatra/base.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d391cf1

Please sign in to comment.