Permalink
Browse files

Add rdoc helper method. Tilt supports RDoc for quite some time now, b…

…ut it was not as easy to use as haml or erb, and not documented. Tests and documentation (English and German) included.
  • Loading branch information...
1 parent b464e02 commit c248dbac9db09f726f11d4877b49c80025961da0 @rkh committed Sep 12, 2010
Showing with 86 additions and 0 deletions.
  1. +25 −0 README.de.rdoc
  2. +22 −0 README.rdoc
  3. +4 −0 lib/sinatra/base.rb
  4. +34 −0 test/rdoc_test.rb
  5. +1 −0 test/views/hello.rdoc
View
@@ -368,6 +368,31 @@ aufzurufen:
%h1 Hallo von Haml!
%p= textile(:greetings)
+=== RDoc-Templates
+
+Das rdoc gem wird benötigt um RDoc-Templates rendern zu können:
+
+ ## redcloth muss eingebunden werden
+ require "rdoc"
+
+ get '/' do
+ rdoc :index
+ end
+
+Dieser Code rendert <tt>./views/index.rdoc</tt>.
+
+Da es weder möglich ist Methoden aufzurufen, noch +locals+ zu übergeben, ist
+es am sinnvollsten RDoc in Kombination mit einer anderen Template-Engine
+zu nutzen:
+
+ erb :overview, :locals => { :text => rdoc(:introduction) }
+
+Es ist auch möglich die +rdoc+ Methode aus anderen Templates heraus
+aufzurufen:
+
+ %h1 Hallo von Haml!
+ %p= rdoc(:greetings)
+
=== Inline-Templates
get '/' do
View
@@ -359,6 +359,28 @@ Note that you may also call the textile method from within other templates:
%h1 Hello From Haml!
%p= textile(:greetings)
+=== RDoc Templates
+
+The RDoc gem/library is required to render RDoc templates:
+
+ ## You'll need to require rdiscount in your app
+ require "rdoc"
+
+ get '/' do
+ rdoc :index
+ end
+
+Renders <tt>./views/index.rdoc</tt>.
+
+It is not possible to call methods from rdoc, nor to pass locals to it. You therefore will usually use it in combination with another rendering engine:
+
+ erb :overview, :locals => { :text => rdoc(:introduction) }
+
+Note that you may also call the rdoc method from within other templates:
+
+ %h1 Hello From Haml!
+ %p= rdoc(:greetings)
+
=== Inline Templates
get '/' do
View
@@ -347,6 +347,10 @@ def textile(template, options={}, locals={})
render :textile, template, options, locals
end
+ def rdoc(template, options={}, locals={})
+ render :rdoc, template, options, locals
+ end
+
private
def render(engine, data, options={}, locals={}, &block)
# merge app-level options
View
@@ -0,0 +1,34 @@
+require File.dirname(__FILE__) + '/helper'
+
+begin
+require 'rdoc'
+
+class RdocTest < Test::Unit::TestCase
+ def rdoc_app(&block)
+ mock_app do
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ end
+ get '/'
+ end
+
+ it 'renders inline rdoc strings' do
+ rdoc_app { rdoc '= Hiya' }
+ assert ok?
+ assert_equal "<h1>Hiya</h1>\n", body
+ end
+
+ it 'renders .rdoc files in views path' do
+ rdoc_app { rdoc :hello }
+ assert ok?
+ assert_equal "<h1>Hello From RDoc</h1>\n", body
+ end
+
+ it "raises error if template not found" do
+ mock_app { get('/') { rdoc :no_such_template } }
+ assert_raise(Errno::ENOENT) { get('/') }
+ end
+end
+rescue
+ warn "#{$!.to_s}: skipping rdoc tests"
+end
View
@@ -0,0 +1 @@
+= Hello From RDoc

0 comments on commit c248dba

Please sign in to comment.