Skip to content

Commit

Permalink
Add rdoc helper method. Tilt supports RDoc for quite some time now, b…
Browse files Browse the repository at this point in the history
…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
rkh committed Sep 12, 2010
1 parent b464e02 commit c248dba
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.de.rdoc
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions README.rdoc
Expand Up @@ -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

This comment has been minimized.

Copy link
@sylvaindesve

sylvaindesve Oct 6, 2010

Contributor

There's a typy here, it should be 'rdoc' instead of 'rdiscount'

This comment has been minimized.

Copy link
@gnandretta

gnandretta Oct 7, 2010

Member

Yes, you're right. And there's another typo where it says 'rdiscount' instead of 'redcloth'. I have already fixed both, but We'll have to wait until rkh comes back to merge the changes.

This comment has been minimized.

Copy link
@rkh

rkh Oct 9, 2010

Author Member

Merged. Thanks guys.

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
Expand Down
4 changes: 4 additions & 0 deletions lib/sinatra/base.rb
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/rdoc_test.rb
@@ -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
1 change: 1 addition & 0 deletions test/views/hello.rdoc
@@ -0,0 +1 @@
= Hello From RDoc

0 comments on commit c248dba

Please sign in to comment.