Permalink
Browse files

Add textile helper method. Tilt supports textile for quite some time …

…now, but 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 970169b commit b464e024a8f90df169fbe46bd7b5877aedc5b17c @rkh rkh committed Sep 11, 2010
Showing with 87 additions and 0 deletions.
  1. +25 −0 README.de.rdoc
  2. +22 −0 README.rdoc
  3. +4 −0 lib/sinatra/base.rb
  4. +1 −0 sinatra.gemspec
  5. +34 −0 test/textile_test.rb
  6. +1 −0 test/views/hello.textile
View
@@ -343,6 +343,31 @@ aufzurufen:
%h1 Hallo von Haml!
%p= markdown(:greetings)
+=== Textile-Templates
+
+Das RedCloth gem wird benötigt um Textile-Templates rendern zu können:
+
+ ## redcloth muss eingebunden werden
+ require "redcloth"
+
+ get '/' do
+ textile :index
+ end
+
+Dieser Code rendert <tt>./views/index.textile</tt>.
+
+Da es weder möglich ist Methoden aufzurufen, noch +locals+ zu übergeben, ist
+es am sinnvollsten Textile in Kombination mit einer anderen Template-Engine
+zu nutzen:
+
+ erb :overview, :locals => { :text => textile(:introduction) }
+
+Es ist auch möglich die +textile+ Methode aus anderen Templates heraus
+aufzurufen:
+
+ %h1 Hallo von Haml!
+ %p= textile(:greetings)
+
=== Inline-Templates
get '/' do
View
@@ -337,6 +337,28 @@ Note that you may also call the markdown method from within other templates:
%h1 Hello From Haml!
%p= markdown(:greetings)
+=== Textile Templates
+
+The RedCloth gem/library is required to render Textile templates:
+
+ ## You'll need to require rdiscount in your app
+ require "redcloth"
+
+ get '/' do
+ textile :index
+ end
+
+Renders <tt>./views/index.textile</tt>.
+
+It is not possible to call methods from textile, nor to pass locals to it. You therefore will usually use it in combination with another rendering engine:
+
+ erb :overview, :locals => { :text => textile(:introduction) }
+
+Note that you may also call the textile method from within other templates:
+
+ %h1 Hello From Haml!
+ %p= textile(:greetings)
+
=== Inline Templates
get '/' do
View
@@ -343,6 +343,10 @@ def markdown(template, options={}, locals={})
render :markdown, template, options, locals
end
+ def textile(template, options={}, locals={})
+ render :textile, template, options, locals
+ end
+
private
def render(engine, data, options={}, locals={}, &block)
# merge app-level options
View
@@ -88,6 +88,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'less'
s.add_development_dependency 'liquid'
s.add_development_dependency 'rdiscount'
+ s.add_development_dependency 'RedCloth'
s.has_rdoc = true
s.homepage = "http://sinatra.rubyforge.org"
View
@@ -0,0 +1,34 @@
+require File.dirname(__FILE__) + '/helper'
+
+begin
+require 'redcloth'
+
+class TextileTest < Test::Unit::TestCase
+ def textile_app(&block)
+ mock_app do
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ end
+ get '/'
+ end
+
+ it 'renders inline textile strings' do
+ textile_app { textile 'h1. Hiya' }
+ assert ok?
+ assert_equal "<h1>Hiya</h1>", body
+ end
+
+ it 'renders .textile files in views path' do
+ textile_app { textile :hello }
+ assert ok?
+ assert_equal "<h1>Hello From Textile</h1>", body
+ end
+
+ it "raises error if template not found" do
+ mock_app { get('/') { textile :no_such_template } }
+ assert_raise(Errno::ENOENT) { get('/') }
+ end
+end
+rescue
+ warn "#{$!.to_s}: skipping textile tests"
+end
View
@@ -0,0 +1 @@
+h1. Hello From Textile

0 comments on commit b464e02

Please sign in to comment.