Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'rabl' of https://github.com/jc00ke/sinatra into jc00ke-…

…rabl

Conflicts:
	Gemfile
  • Loading branch information...
commit 9e8677a6c3e5e3f262141bb5713fd3f0a81c94e5 2 parents 31e7834 + 15998be
@rkh rkh authored
View
1  Gemfile
@@ -43,6 +43,7 @@ gem 'creole'
gem 'markaby'
gem 'radius'
gem 'wlang', '>= 2.0.1'
+gem 'rabl' unless RUBY_ENGINE == 'jruby'
if RUBY_ENGINE == 'jruby'
gem 'nokogiri', '!= 1.5.0'
View
6 README.de.rdoc
@@ -508,6 +508,12 @@ Nimmt ebenso einen Block für Inline-Templates entgegen (siehe Beispiel).
=== Slim Templates
+Abhängigkeit:: {rabl}[https://github.com/nesquena/rabl]
+Dateierweiterungs:: <tt>.rabl</tt>
+Beispiel:: <tt>rabl :index</tt>
+
+=== Slim Templates
+
Abhängigkeit:: {slim}[http://slim-lang.com/]
Dateierweiterungs:: <tt>.slim</tt>
Beispiel:: <tt>slim :index</tt>
View
6 README.es.rdoc
@@ -496,6 +496,12 @@ Ejemplos:: <tt>markaby { h1 "Bienvenido!" }</tt>
Además, acepta un bloque con la definición de la plantilla (ver el ejemplo).
+=== Plantillas RABL
+
+Dependencias:: {rabl}[https://github.com/nesquena/rabl]
+Extensiones de Archivo:: <tt>.rabl</tt>
+Ejemplo:: <tt>rabl :index</tt>
+
=== Plantillas Slim
Dependencias:: {slim}[http://slim-lang.com/]
View
6 README.fr.rdoc
@@ -508,6 +508,12 @@ Exemple:: <tt>markaby { h1 "Bienvenue !" }</tt>
Ce moteur accepte également un bloc pour des templates en ligne (voir exemple).
+=== Templates RABL
+
+Dépendances:: {rabl}[https://github.com/nesquena/rabl]
+Extensions de fichier:: <tt>.rabl</tt>
+Exemple:: <tt>rabl :index</tt>
+
=== Templates Slim
Dépendances:: {slim}[http://slim-lang.com/]
View
13 README.jp.rdoc
@@ -426,6 +426,19 @@ Markabyテンプレートを使うにはmarkabyライブラリが必要です:
<tt>./views/index.mab</tt>を表示します。
+=== RABL テンプレート
+
+RABLテンプレートを使うにはrablライブラリが必要です:
+
+ # rablを読み込みます
+ require 'rabl'
+
+ get '/' do
+ rabl :index
+ end
+
+<tt>./views/index.rabl</tt>を表示します。
+
=== Slim テンプレート
Slimテンプレートを使うにはslimライブラリが必要です:
View
6 README.ko.rdoc
@@ -454,6 +454,12 @@ Radius 템플릿에서는 루비 메서드를 호출할 수 없기 때문에,
인라인 템플릿으로 블록을 받을 수도 있음(예제 참조).
+=== RABL 템플릿
+
+의존:: {rabl}[https://github.com/nesquena/rabl]
+파일 확장자:: <tt>.rabl</tt>
+예제:: <tt>rabl :index</tt>
+
=== Slim 템플릿
의존:: {slim}[http://slim-lang.com/]
View
6 README.rdoc
@@ -481,6 +481,12 @@ Example:: <tt>markaby { h1 "Welcome!" }</tt>
It also takes a block for inline templates (see example).
+=== RABL Templates
+
+Dependency:: {rabl}[https://github.com/nesquena/rabl]
+File Extensions:: <tt>.rabl</tt>
+Example:: <tt>rabl :index</tt>
+
=== Slim Templates
Dependency:: {slim}[http://slim-lang.com/]
View
6 README.ru.rdoc
@@ -488,6 +488,12 @@ Thin — это более производительный и функцион
Блок также используется и для встроенных шаблонов (см. пример).
+=== RABL шаблоны
+
+Зависимости:: {rabl}[https://github.com/nesquena/rabl]
+Расширения файлов:: <tt>.rabl</tt>
+Пример:: <tt>rabl :index</tt>
+
=== Slim шаблоны
Зависимости:: {slim}[http://slim-lang.com/]
View
5 lib/sinatra/base.rb
@@ -654,6 +654,11 @@ def yajl(template, options={}, locals={})
render :yajl, template, options, locals
end
+ def rabl(template, options={}, locals={})
+ Rabl.register!
+ render :rabl, 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
89 test/rabl_test.rb
@@ -0,0 +1,89 @@
+require File.expand_path('../helper', __FILE__)
+
+begin
+require 'rabl'
+require 'ostruct'
+require 'json'
+require 'active_support/core_ext/hash/conversions'
+
+class RablTest < Test::Unit::TestCase
+ def rabl_app(&block)
+ mock_app {
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ }
+ get '/'
+ end
+
+ it 'renders inline rabl strings' do
+ rabl_app do
+ @foo = OpenStruct.new(:baz => 'w00t')
+ rabl %q{
+ object @foo
+ attributes :baz
+ }
+ end
+ assert ok?
+ assert_equal '{"openstruct":{"baz":"w00t"}}', body
+ end
+ it 'renders .rabl files in views path' do
+ rabl_app do
+ @foo = OpenStruct.new(:bar => 'baz')
+ rabl :hello
+ end
+ assert ok?
+ assert_equal '{"openstruct":{"bar":"baz"}}', body
+ end
+
+ it "renders with file layouts" do
+ rabl_app {
+ @foo = OpenStruct.new(:bar => 'baz')
+ rabl :hello, :layout => :layout2
+ }
+ assert ok?
+ assert_equal '{"qux":{"openstruct":{"bar":"baz"}}}', body
+ end
+
+ it "raises error if template not found" do
+ mock_app {
+ get('/') { rabl :no_such_template }
+ }
+ assert_raise(Errno::ENOENT) { get('/') }
+ end
+
+ it "passes rabl options to the rabl engine" do
+ mock_app do
+ get('/') do
+ @foo = OpenStruct.new(:bar => 'baz')
+ rabl %q{
+ object @foo
+ attributes :bar
+ }, :format => 'xml'
+ end
+ end
+ get '/'
+ assert ok?
+ assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
+ end
+
+ it "passes default rabl options to the rabl engine" do
+ mock_app do
+ set :rabl, :format => 'xml'
+ get('/') do
+ @foo = OpenStruct.new(:bar => 'baz')
+ rabl %q{
+ object @foo
+ attributes :bar
+ }
+ end
+ end
+ get '/'
+ assert ok?
+ assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
+ end
+
+end
+
+rescue LoadError
+ warn "#{$!.to_s}: skipping rabl tests"
+end
View
2  test/views/hello.rabl
@@ -0,0 +1,2 @@
+object @foo
+attributes :bar
View
3  test/views/layout2.rabl
@@ -0,0 +1,3 @@
+node(:qux) do
+ ::JSON.parse(yield)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.