Skip to content
Browse files

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

Conflicts:
	Gemfile
  • Loading branch information...
2 parents baae681 + b09f70f commit 0cb66792c8dd057996b5bbda1b39892e33b80b94 @rkh rkh committed
Showing with 119 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +21 −0 README.md
  3. +20 −0 README.ru.md
  4. +4 −0 lib/sinatra/base.rb
  5. +72 −0 test/asciidoctor_test.rb
  6. +1 −0 test/views/hello.asciidoc
View
1 Gemfile
@@ -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
21 README.md
@@ -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
20 README.ru.md
@@ -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
4 lib/sinatra/base.rb
@@ -715,6 +715,10 @@ def rdoc(template, options = {}, locals = {})
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
View
72 test/asciidoctor_test.rb
@@ -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
1 test/views/hello.asciidoc
@@ -0,0 +1 @@
+== Hello from AsciiDoc

0 comments on commit 0cb6679

Please sign in to comment.
Something went wrong with that request. Please try again.