1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Merge branch 'asciidoctor-support' of https://github.com/somu/sinatra

Conflicts:
	Gemfile
This commit is contained in:
Konstantin Haase 2014-02-21 10:34:32 +01:00
commit 0cb66792c8
6 changed files with 119 additions and 0 deletions

View file

@ -55,6 +55,7 @@ if RUBY_ENGINE == "ruby" and RUBY_VERSION > '1.9.2'
gem 'wikicloth'
gem 'markaby'
gem 'radius'
gem 'asciidoctor'
gem 'liquid'
gem 'stylus'
gem 'rabl'

View file

@ -52,6 +52,7 @@ pick up if available.
* [Markdown Templates](#markdown-templates)
* [Textile Templates](#textile-templates)
* [RDoc Templates](#rdoc-templates)
* [AsciiDoc Templates](#asciidoc-templates)
* [Radius Templates](#radius-templates)
* [Markaby Templates](#markaby-templates)
* [RABL Templates](#rabl-templates)
@ -790,6 +791,26 @@ Since you cannot call Ruby from RDoc, you cannot use layouts written in
RDoc. However, it is possible to use another rendering engine for the
template than for the layout by passing the `:layout_engine` option.
#### AsciiDoc Templates
<table>
<tr>
<td>Dependency</td>
<td><a href="http://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
</tr>
<tr>
<td>File Extension</td>
<td><tt>.asciidoc</tt>, <tt>.adoc</tt> and <tt>.ad</tt></td>
</tr>
<tr>
<td>Example</td>
<td><tt>asciidoc :README, :layout_engine => :erb</tt></td>
</tr>
</table>
Since you cannot call Ruby methods directly from an AsciiDoc template, you almost
always want to pass locals to it.
#### Radius Templates
<table>

View file

@ -710,6 +710,26 @@ erb :overview, :locals => { :text => rdoc(:introduction) }
для отображения шаблона, а другой для лэйаута с помощью опции
`:layout_engine`.
#### AsciiDoc шаблоны
<table>
<tr>
<td>Зависимости</td>
<td><a href="http://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
</tr>
<tr>
<td>Расширения файлов</td>
<td><tt>.asciidoc</tt>, <tt>.adoc</tt> и <tt>.ad</tt></td>
</tr>
<tr>
<td>Пример</td>
<td><tt>asciidoc :README, :layout_engine => :erb</tt></td>
</tr>
</table>
Так как в AsciiDoc шаблонах невозможно вызывать методы из Ruby напрямую, то вы
почти всегда будете передавать в шаблон локальные переменные.
#### Radius шаблоны
<table>

View file

@ -715,6 +715,10 @@ module Sinatra
render :rdoc, template, options, locals
end
def asciidoc(template, options = {}, locals = {})
render :asciidoc, template, options, locals
end
def radius(template, options = {}, locals = {})
render :radius, template, options, locals
end

72
test/asciidoctor_test.rb Normal file
View file

@ -0,0 +1,72 @@
require File.expand_path('../helper', __FILE__)
begin
require 'asciidoctor'
class AsciidoctorTest < Test::Unit::TestCase
def asciidoc_app(&block)
mock_app do
set :views, File.dirname(__FILE__) + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline AsciiDoc strings' do
asciidoc_app { asciidoc '== Hiya' }
assert ok?
assert_match %r{<h2.*?>Hiya</h2>}, body
end
it 'uses the correct engine' do
engine = Tilt::AsciidoctorTemplate
assert_equal engine, Tilt[:ad]
assert_equal engine, Tilt[:adoc]
assert_equal engine, Tilt[:asciidoc]
end
it 'renders .asciidoc files in views path' do
asciidoc_app { asciidoc :hello }
assert ok?
assert_match %r{<h2.*?>Hello from AsciiDoc</h2>}, body
end
it 'raises error if template not found' do
mock_app { get('/') { asciidoc :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
it 'renders with inline layouts' do
mock_app do
layout { 'THIS. IS. #{yield.upcase}!' }
get('/') { asciidoc 'Sparta', :layout_engine => :str }
end
get '/'
assert ok?
assert_include body, 'THIS. IS.'
assert_include body, '<P>SPARTA</P>'
end
it 'renders with file layouts' do
asciidoc_app do
asciidoc 'Hello World', :layout => :layout2, :layout_engine => :erb
end
assert ok?
assert_include body, 'ERB Layout!'
assert_include body, '<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><%= asciidoc :inner %></outer>' }
get('/') { erb :outer }
end
get '/'
assert ok?
assert_match %r{<outer>.*<p.*?>hi</p>.*</outer>}m, body
end
end
rescue LoadError
warn "#{$!.to_s}: skipping asciidoc tests"
end

View file

@ -0,0 +1 @@
== Hello from AsciiDoc