Skip to content
Browse files

Merge branch 'tilt-1.3'

Conflicts:
	README.de.rdoc
  • Loading branch information...
2 parents 56bcd4c + 6ad90f5 commit 92516551b31f22a4fca132383300a471f1a07bbc @rkh rkh committed Apr 27, 2011
View
3 CHANGES
@@ -2,6 +2,9 @@
* Added support for HTTP PATCH requests. (Konstantin Haase)
+ * Support for Creole templates, Creole is a standardized wiki markup,
+ supported by many wiki implementations. (Konstanin Haase)
+
* Set up `Rack::Logger` or `Rack::NullLogger` depending on whether logging
was enabled or not. Also, expose that logger with the `logger` helper
method. (Konstantin Haase)
View
4 Gemfile
@@ -34,9 +34,13 @@ gem 'slim', :group => 'slim'
gem 'RedCloth', :group => 'redcloth'
gem 'coffee-script', '>= 2.0', :group => 'coffee-script'
gem 'rdoc', :group => 'rdoc'
+gem 'kramdown', :group => 'kramdown'
+gem 'maruku', :group => 'maruku'
+gem 'creole', :group => 'creole'
platforms :ruby do
gem 'rdiscount', :group => 'rdiscount'
+ gem 'bluecloth', :group => 'bluecloth'
end
platforms :ruby_18, :jruby do
View
13 README.de.rdoc
@@ -592,6 +592,19 @@ Das +slim+-Gem wird benötigt, um Slim-Templates rendern zu können:
Dieser Code rendert <tt>./views/index.slim</tt>.
+=== Creole-Templates
+
+Das +creole+-Gem wird benötigt, um Creole-Templates rendern zu können:
+
+ # creole muss eingebunden werden
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+Dieser Code rendert <tt>./views/index.creole</tt>.
+
=== CoffeeScript-Templates
Das <tt>coffee-script</tt>-Gem und mindestens eine der folgenden Optionen
View
13 README.es.rdoc
@@ -597,6 +597,19 @@ La gem/librería <tt>slim</tt> es necesaria para renderizar plantillas Slim:
Renderiza <tt>./views/index.slim</tt>.
+=== Plantillas Creole
+
+La gem/librería <tt>creole</tt> es necesaria para renderizar plantillas Creole:
+
+ # Vas a necesitar requerir creole en tu app
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+Renderiza <tt>./views/index.creole</tt>.
+
=== Plantillas CoffeeScript
La gem/librería <tt>coffee-script</tt> y al menos <b>una</b> de las siguientes
View
14 README.fr.rdoc
@@ -618,6 +618,20 @@ Le gem slim est nécessaire pour utiliser la fonction de rendu Slim:
Utilisera <tt>./views/index.slim</tt>.
+=== Templates Creole
+
+Le gem <tt>creole</tt> est nécessaire pour utiliser la fonction de rendu
+Creole:
+
+ # Chargez la bibliothèque creole dans votre application
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+Utilisera <tt>./views/index.creole</tt>.
+
=== Templates CoffeeScript
Le gem <tt>coffee-script</tt> est nécessaire ainsi que l'<b>une</b> des
View
13 README.jp.rdoc
@@ -432,6 +432,19 @@ Slimテンプレートを使うにはslimライブラリが必要です:
<tt>./views/index.slim</tt>を表示します。
+=== Creole テンプレート
+
+Creoleテンプレートを使うにはcreoleライブラリが必要です:
+
+ # creoleを読み込みます
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+<tt>./views/index.creole</tt>を表示します。
+
=== CoffeeScript テンプレート
CoffeeScriptテンプレートを表示するにはcoffee-scriptライブラリと`coffee`バイナリが必要です:
View
37 README.rdoc
@@ -256,30 +256,6 @@ and overridden on an individual basis.
Renders <tt>./views/index.erb</tt>.
-=== Erubis Templates
-
-The <tt>erubis</tt> gem/library is required to render Erubis templates:
-
- # You'll need to require erubis in your app
- require 'erubis'
-
- get '/' do
- erubis :index
- end
-
-Renders <tt>./views/index.erubis</tt>.
-
-It is also possible to replace Erb with Erubis:
-
- require 'erubis'
- Tilt.register :erb, Tilt[:erubis]
-
- get '/' do
- erb :index
- end
-
-Renders <tt>./views/index.erb</tt> with Erubis.
-
=== Builder Templates
The <tt>builder</tt> gem/library is required to render builder templates:
@@ -586,6 +562,19 @@ The <tt>slim</tt> gem/library is required to render Slim templates:
Renders <tt>./views/index.slim</tt>.
+=== Creole Templates
+
+The <tt>creole</tt> gem/library is required to render Creole templates:
+
+ # You'll need to require creole in your app
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+Renders <tt>./views/index.creole</tt>.
+
=== CoffeeScript Templates
The <tt>coffee-script</tt> gem/library and at least <b>one</b> of the
View
13 README.ru.rdoc
@@ -584,6 +584,19 @@ Thin - это более производительный и функциона
Отобразит <tt>./views/index.slim</tt>.
+=== Creole шаблоны
+
+<tt>creole</tt> gem/библиотека необходима для рендеринга creole шаблонов:
+
+ # Вам нужно будет подключить creole в приложении
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+Отобразит <tt>./views/index.creole</tt>.
+
=== CoffeeScript шаблоны
Вам понадобится <tt>coffee-script</tt> gem/библиотека и что-то <b>одно</b> из следующего списка,
View
13 README.zh.rdoc
@@ -582,6 +582,19 @@ Rack body对象或者HTTP状态码:
渲染 <tt>./views/index.slim</tt>。
+=== Creole 模板
+
+需要引入 <tt>creole</tt> gem/library 来渲染 Creole 模板:
+
+ # 需要在你的应用中引入 creole
+ require 'creole'
+
+ get '/' do
+ creole :index
+ end
+
+渲染 <tt>./views/index.creole</tt>。
+
=== CoffeeScript 模板
需要引入 <tt>coffee-script</tt> gem/library 并至少满足下面条件一项
View
8 lib/sinatra/base.rb
@@ -451,6 +451,8 @@ def erb(template, options={}, locals={})
end
def erubis(template, options={}, locals={})
+ warn "Sinatra::Templates#erubis is deprecated and will be removed, use #erb instead.\n" \
+ "If you have Erubis installed, it will be used automatically.\n\tfrom #{caller.first}"
render :erubis, template, options, locals
end
@@ -516,12 +518,16 @@ def slim(template, options={}, locals={})
render :slim, template, options, locals
end
+ def creole(template, options={}, locals={})
+ render :creole, template, options, locals
+ end
+
# Calls the given block for every possible template file in views,
# named name.ext, where ext is registered on engine.
def find_template(views, name, engine)
yield ::File.join(views, "#{name}.#{@preferred_extension}")
Tilt.mappings.each do |ext, engines|
- next unless ext != @preferred_extension and Array(engines).include? engine
+ next unless ext != @preferred_extension and engines.include? engine
yield ::File.join(views, "#{name}.#{ext}")
end
end
View
6 sinatra.gemspec
@@ -44,7 +44,6 @@ Gem::Specification.new do |s|
test/delegator_test.rb
test/encoding_test.rb
test/erb_test.rb
- test/erubis_test.rb
test/extensions_test.rb
test/filter_test.rb
test/haml_test.rb
@@ -80,15 +79,13 @@ Gem::Specification.new do |s|
test/views/calc.html.erb
test/views/error.builder
test/views/error.erb
- test/views/error.erubis
test/views/error.haml
test/views/error.sass
test/views/explicitly_nested.str
test/views/foo/hello.test
test/views/hello.builder
test/views/hello.coffee
test/views/hello.erb
- test/views/hello.erubis
test/views/hello.haml
test/views/hello.less
test/views/hello.liquid
@@ -105,7 +102,6 @@ Gem::Specification.new do |s|
test/views/hello.textile
test/views/layout2.builder
test/views/layout2.erb
- test/views/layout2.erubis
test/views/layout2.haml
test/views/layout2.liquid
test/views/layout2.mab
@@ -123,7 +119,7 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = %w[README.rdoc README.de.rdoc README.jp.rdoc README.fr.rdoc README.es.rdoc README.hu.rdoc README.zh.rdoc LICENSE]
s.add_dependency 'rack', '~> 1.2'
- s.add_dependency 'tilt', '~> 1.2', '>= 1.2.2'
+ s.add_dependency 'tilt', '~> 1.3'
s.add_development_dependency 'shotgun', '~> 0.6'
s.homepage = "http://sinatra.rubyforge.org"
View
65 test/creole_test.rb
@@ -0,0 +1,65 @@
+require File.dirname(__FILE__) + '/helper'
+
+begin
+require 'creole'
+
+class CreoleTest < Test::Unit::TestCase
+ def creole_app(&block)
+ mock_app do
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ end
+ get '/'
+ end
+
+ it 'renders inline creole strings' do
+ creole_app { creole '= Hiya' }
+ assert ok?
+ assert_body "<h1>Hiya</h1>"
+ end
+
+ it 'renders .creole files in views path' do
+ creole_app { creole :hello }
+ assert ok?
+ assert_body "<h1>Hello From Creole</h1>"
+ end
+
+ it "raises error if template not found" do
+ mock_app { get('/') { creole :no_such_template } }
+ assert_raise(Errno::ENOENT) { get('/') }
+ end
+
+ it "renders with inline layouts" do
+ mock_app do
+ layout { 'THIS. IS. #{yield.upcase}!' }
+ get('/') { creole 'Sparta', :layout_engine => :str }
+ end
+ get '/'
+ assert ok?
+ assert_like 'THIS. IS. <P>SPARTA</P>!', body
+ end
+
+ it "renders with file layouts" do
+ creole_app { creole 'Hello World', :layout => :layout2, :layout_engine => :erb }
+ assert ok?
+ assert_body "ERB Layout!\n<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= creole :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
+end
+
+rescue LoadError
+ warn "#{$!.to_s}: skipping creole tests"
+end
View
25 test/erb_test.rb
@@ -1,6 +1,15 @@
require File.dirname(__FILE__) + '/helper'
class ERBTest < Test::Unit::TestCase
+ def engine
+ Tilt::ERBTemplate
+ end
+
+ def setup
+ Tilt.prefer engine, :erb
+ super
+ end
+
def erb_app(&block)
mock_app {
set :views, File.dirname(__FILE__) + '/views'
@@ -9,6 +18,10 @@ def erb_app(&block)
get '/'
end
+ it 'uses the correct engine' do
+ assert_equal engine, Tilt[:erb]
+ end
+
it 'renders inline ERB strings' do
erb_app { erb '<%= 1 + 1 %>' }
assert ok?
@@ -45,7 +58,7 @@ def erb_app(&block)
erb 'Hello World', :layout => :layout2
}
assert ok?
- assert_equal "ERB Layout!\nHello World\n", body
+ assert_body "ERB Layout!\nHello World"
end
it "renders erb with blocks" do
@@ -79,3 +92,13 @@ def is; "IS." end
assert_equal '<outer><inner>hi</inner></outer>', body
end
end
+
+
+begin
+ require 'erubis'
+ class ErubisTest < ERBTest
+ def engine; Tilt::ErubisTemplate end
+ end
+rescue LoadError
+ warn "#{$!.to_s}: skipping erubis tests"
+end
View
88 test/erubis_test.rb
@@ -1,88 +0,0 @@
-require File.dirname(__FILE__) + '/helper'
-
-begin
-require 'erubis'
-
-class ERubisTest < Test::Unit::TestCase
- def erubis_app(&block)
- mock_app {
- set :views, File.dirname(__FILE__) + '/views'
- get '/', &block
- }
- get '/'
- end
-
- it 'renders inline ERubis strings' do
- erubis_app { erubis '<%= 1 + 1 %>' }
- assert ok?
- assert_equal '2', body
- end
-
- it 'renders .erubis files in views path' do
- erubis_app { erubis :hello }
- assert ok?
- assert_equal "Hello World\n", body
- end
-
- it 'takes a :locals option' do
- erubis_app {
- locals = {:foo => 'Bar'}
- erubis '<%= foo %>', :locals => locals
- }
- assert ok?
- assert_equal 'Bar', body
- end
-
- it "renders with inline layouts" do
- mock_app {
- layout { 'THIS. IS. <%= yield.upcase %>!' }
- get('/') { erubis 'Sparta' }
- }
- get '/'
- assert ok?
- assert_equal 'THIS. IS. SPARTA!', body
- end
-
- it "renders with file layouts" do
- erubis_app {
- erubis 'Hello World', :layout => :layout2
- }
- assert ok?
- assert_equal "ERubis Layout!\nHello World\n", body
- end
-
- it "renders erubis with blocks" do
- mock_app {
- def container
- @_out_buf << "THIS."
- yield
- @_out_buf << "SPARTA!"
- end
- def is; "IS." end
- get '/' do
- erubis '<% container do %> <%= is %> <% end %>'
- end
- }
- get '/'
- assert ok?
- assert_equal 'THIS. IS. SPARTA!', body
- end
-
- it "can be used in a nested fashion for partials and whatnot" do
- mock_app {
- template(:inner) { "<inner><%= 'hi' %></inner>" }
- template(:outer) { "<outer><%= erubis :inner %></outer>" }
- get '/' do
- erubis :outer
- end
- }
-
- get '/'
- assert ok?
- assert_equal '<outer><inner>hi</inner></outer>', body
- end
-end
-
-rescue LoadError
- warn "#{$!.to_s}: skipping erubis tests"
-end
View
7 test/helper.rb
@@ -65,6 +65,11 @@ def assert_body(value)
assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
end
+ def assert_like(a,b)
+ pattern = /\s*\n\s*| id=['"][^"']*["']/
+ assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "")
+ end
+
def assert_include(str, substr)
assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
end
@@ -76,6 +81,8 @@ def method_missing(name, *args, &block)
else
super
end
+ rescue Rack::Test::Error
+ super
end
# Also check response since we delegate there.
View
4 test/helpers_test.rb
@@ -323,8 +323,8 @@ def test_default
end
end
- get '/'
- assert_body 'ok'
+ get '/'
+ assert_body 'ok'
end
it 'accepts an options hash' do
View
63 test/markdown_test.rb
@@ -1,10 +1,6 @@
require File.dirname(__FILE__) + '/helper'
-begin
-fail LoadError, "rdiscount not available" if defined? JRuby
-require 'rdiscount'
-
-class MarkdownTest < Test::Unit::TestCase
+MarkdownTest = proc do
def markdown_app(&block)
mock_app do
set :views, File.dirname(__FILE__) + '/views'
@@ -13,24 +9,73 @@ def markdown_app(&block)
get '/'
end
+ def setup
+ Tilt.prefer engine, 'markdown', 'mkd', 'md'
+ super
+ end
+
+ it 'uses the correct engine' do
+ assert_equal engine, Tilt[:md]
+ assert_equal engine, Tilt[:mkd]
+ assert_equal engine, Tilt[:markdown]
+ end
+
it 'renders inline markdown strings' do
markdown_app { markdown '# Hiya' }
assert ok?
- assert_equal "<h1>Hiya</h1>\n", body
+ assert_like "<h1>Hiya</h1>\n", body
end
it 'renders .markdown files in views path' do
markdown_app { markdown :hello }
assert ok?
- assert_equal "<h1>Hello From Markdown</h1>\n", body
+ assert_like "<h1>Hello From Markdown</h1>", body
end
it "raises error if template not found" do
mock_app { get('/') { markdown :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
+
+ it "renders with inline layouts" do
+ mock_app do
+ layout { 'THIS. IS. #{yield.upcase}!' }
+ get('/') { markdown 'Sparta', :layout_engine => :str }
+ end
+ get '/'
+ assert ok?
+ assert_like 'THIS. IS. <P>SPARTA</P>!', body
+ end
+
+ it "renders with file layouts" do
+ markdown_app { markdown 'Hello World', :layout => :layout2, :layout_engine => :erb }
+ assert ok?
+ assert_body "ERB Layout!\n<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= markdown :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
-rescue LoadError
- warn "#{$!.to_s}: skipping markdown tests"
+# Will generate RDiscountTest, KramdownTest, etc.
+Tilt.mappings['md'].each do |t|
+ begin
+ t.new { "" }
+ klass = Class.new(Test::Unit::TestCase) { define_method(:engine) { t }}
+ klass.class_eval(&MarkdownTest)
+ Object.const_set t.name[/[^:]+(?=Template$)/] << "Test", klass
+ rescue LoadError
+ warn "#{$!}: skipping markdown tests with #{t}"
+ end
end
View
1 test/radius_test.rb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/helper'
begin
-fail LoadError, 'Radius broken on 1.9.' if RUBY_VERSION >= '1.9.1'
require 'radius'
class RadiusTest < Test::Unit::TestCase
View
30 test/rdoc_test.rb
@@ -28,6 +28,36 @@ def rdoc_app(&block)
mock_app { get('/') { rdoc :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
+
+ it "renders with inline layouts" do
+ mock_app do
+ layout { 'THIS. IS. #{yield.upcase}!' }
+ get('/') { rdoc 'Sparta', :layout_engine => :str }
+ end
+ get '/'
+ assert ok?
+ assert_like 'THIS. IS.<P>SPARTA</P>!', body
+ end
+
+ it "renders with file layouts" do
+ rdoc_app { rdoc 'Hello World', :layout => :layout2, :layout_engine => :erb }
+ assert ok?
+ assert_body "ERB Layout!\n<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= rdoc :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
rescue LoadError
View
30 test/textile_test.rb
@@ -28,6 +28,36 @@ def textile_app(&block)
mock_app { get('/') { textile :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
+
+ it "renders with inline layouts" do
+ mock_app do
+ layout { 'THIS. IS. #{yield.upcase}!' }
+ get('/') { textile 'Sparta', :layout_engine => :str }
+ end
+ get '/'
+ assert ok?
+ assert_like 'THIS. IS. <P>SPARTA</P>!', body
+ end
+
+ it "renders with file layouts" do
+ textile_app { textile 'Hello World', :layout => :layout2, :layout_engine => :erb }
+ assert ok?
+ assert_body "ERB Layout!\n<p>Hello World</p>"
+ end
+
+ it "can be used in a nested fashion for partials and whatnot" do
+ mock_app do
+ template(:inner) { "hi" }
+ template(:outer) { "<outer><%= textile :inner %></outer>" }
+ get '/' do
+ erb :outer
+ end
+ end
+
+ get '/'
+ assert ok?
+ assert_like '<outer><p>hi</p></outer>', body
+ end
end
rescue LoadError
View
3 test/views/error.erubis
@@ -1,3 +0,0 @@
-Hello <%= 'World' %>
-<% raise 'Goodbye' unless defined?(french) && french %>
-<% raise 'Au revoir' if defined?(french) && french %>
View
1 test/views/hello.creole
@@ -0,0 +1 @@
+= Hello From Creole
View
1 test/views/hello.erubis
@@ -1 +0,0 @@
-Hello <%= 'World' %>
View
2 test/views/layout2.erubis
@@ -1,2 +0,0 @@
-ERubis Layout!
-<%= yield %>

0 comments on commit 9251655

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