Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gnandretta
Member
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= Hello From RDoc |
There's a typy here, it should be 'rdoc' instead of 'rdiscount'