Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add support for creole templates

  • Loading branch information...
commit 9ce9e543e03e5e56e1b9d12a3adb98dc1f31a963 1 parent f65082d
@rkh rkh authored
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
1  Gemfile
@@ -36,6 +36,7 @@ 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'
View
13 README.de.rdoc
@@ -613,6 +613,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
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
13 README.rdoc
@@ -562,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
4 lib/sinatra/base.rb
@@ -518,6 +518,10 @@ 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)
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
1  test/views/hello.creole
@@ -0,0 +1 @@
+= Hello From Creole
Please sign in to comment.
Something went wrong with that request. Please try again.