Skip to content
This repository
Browse code

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...
commit c248dbac9db09f726f11d4877b49c80025961da0 1 parent b464e02
Konstantin Haase authored September 12, 2010
25  README.de.rdoc
Source Rendered
@@ -368,6 +368,31 @@ aufzurufen:
368 368
   %h1 Hallo von Haml!
369 369
   %p= textile(:greetings)
370 370
 
  371
+=== RDoc-Templates
  372
+
  373
+Das rdoc gem wird benötigt um RDoc-Templates rendern zu können:
  374
+
  375
+  ## redcloth muss eingebunden werden
  376
+  require "rdoc"
  377
+
  378
+  get '/' do
  379
+    rdoc :index
  380
+  end
  381
+
  382
+Dieser Code rendert <tt>./views/index.rdoc</tt>.
  383
+
  384
+Da es weder möglich ist Methoden aufzurufen, noch +locals+ zu übergeben, ist
  385
+es am sinnvollsten RDoc in Kombination mit einer anderen Template-Engine
  386
+zu nutzen:
  387
+
  388
+  erb :overview, :locals => { :text => rdoc(:introduction) }
  389
+
  390
+Es ist auch möglich die +rdoc+ Methode aus anderen Templates heraus
  391
+aufzurufen:
  392
+
  393
+  %h1 Hallo von Haml!
  394
+  %p= rdoc(:greetings)
  395
+
371 396
 === Inline-Templates
372 397
 
373 398
   get '/' do
22  README.rdoc
Source Rendered
@@ -359,6 +359,28 @@ Note that you may also call the textile method from within other templates:
359 359
   %h1 Hello From Haml!
360 360
   %p= textile(:greetings)
361 361
 
  362
+=== RDoc Templates
  363
+
  364
+The RDoc gem/library is required to render RDoc templates:
  365
+
  366
+  ## You'll need to require rdiscount in your app
  367
+  require "rdoc"
  368
+
  369
+  get '/' do
  370
+    rdoc :index
  371
+  end
  372
+
  373
+Renders <tt>./views/index.rdoc</tt>.
  374
+
  375
+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:
  376
+
  377
+  erb :overview, :locals => { :text => rdoc(:introduction) }
  378
+
  379
+Note that you may also call the rdoc method from within other templates:
  380
+
  381
+  %h1 Hello From Haml!
  382
+  %p= rdoc(:greetings)
  383
+
362 384
 === Inline Templates
363 385
 
364 386
   get '/' do
4  lib/sinatra/base.rb
@@ -347,6 +347,10 @@ def textile(template, options={}, locals={})
347 347
       render :textile, template, options, locals
348 348
     end
349 349
 
  350
+    def rdoc(template, options={}, locals={})
  351
+      render :rdoc, template, options, locals
  352
+    end
  353
+
350 354
   private
351 355
     def render(engine, data, options={}, locals={}, &block)
352 356
       # merge app-level options
34  test/rdoc_test.rb
... ...
@@ -0,0 +1,34 @@
  1
+require File.dirname(__FILE__) + '/helper'
  2
+
  3
+begin
  4
+require 'rdoc'
  5
+
  6
+class RdocTest < Test::Unit::TestCase
  7
+  def rdoc_app(&block)
  8
+    mock_app do
  9
+      set :views, File.dirname(__FILE__) + '/views'
  10
+      get '/', &block
  11
+    end
  12
+    get '/'
  13
+  end
  14
+
  15
+  it 'renders inline rdoc strings' do
  16
+    rdoc_app { rdoc '= Hiya' }
  17
+    assert ok?
  18
+    assert_equal "<h1>Hiya</h1>\n", body
  19
+  end
  20
+
  21
+  it 'renders .rdoc files in views path' do
  22
+    rdoc_app { rdoc :hello }
  23
+    assert ok?
  24
+    assert_equal "<h1>Hello From RDoc</h1>\n", body
  25
+  end
  26
+
  27
+  it "raises error if template not found" do
  28
+    mock_app { get('/') { rdoc :no_such_template } }
  29
+    assert_raise(Errno::ENOENT) { get('/') }
  30
+  end
  31
+end
  32
+rescue
  33
+  warn "#{$!.to_s}: skipping rdoc tests"
  34
+end
1  test/views/hello.rdoc
Source Rendered
... ...
@@ -0,0 +1 @@
  1
+= Hello From RDoc

0 notes on commit c248dba

Sylvain Desvé

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

Gabriel Andretta

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.

Konstantin Haase

Merged. Thanks guys.

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