1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

add support for creole templates

This commit is contained in:
Konstantin Haase 2011-04-15 11:51:35 +02:00
parent f65082df46
commit 9ce9e543e0
12 changed files with 166 additions and 0 deletions

View file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -518,6 +518,10 @@ module Sinatra
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)

65
test/creole_test.rb Normal file
View file

@ -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

1
test/views/hello.creole Normal file
View file

@ -0,0 +1 @@
= Hello From Creole