mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Merge pull request #1494 from tkmru/support-erubi
Fix #1487 update test and docs to support erubi
This commit is contained in:
commit
4607e1ddf6
12 changed files with 36 additions and 9 deletions
1
Gemfile
1
Gemfile
|
@ -53,6 +53,7 @@ if RUBY_ENGINE == "ruby"
|
||||||
gem 'stylus'
|
gem 'stylus'
|
||||||
gem 'rabl'
|
gem 'rabl'
|
||||||
gem 'builder'
|
gem 'builder'
|
||||||
|
gem 'erubi'
|
||||||
gem 'erubis'
|
gem 'erubis'
|
||||||
gem 'haml', '>= 3.0'
|
gem 'haml', '>= 3.0'
|
||||||
gem 'sass'
|
gem 'sass'
|
||||||
|
|
|
@ -551,13 +551,14 @@ get('/') { markdown :index }
|
||||||
<tr>
|
<tr>
|
||||||
<td>依存</td>
|
<td>依存</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
<a href="https://github.com/jeremyevans/erubi" title="erubi">erubi</a>
|
||||||
|
または <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
||||||
または erb (Rubyに同梱)
|
または erb (Rubyに同梱)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>ファイル拡張子</td>
|
<td>ファイル拡張子</td>
|
||||||
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubis</tt> (Erubisだけ)</td>
|
<td><tt>.erb</tt>, <tt>.rhtml</tt> または <tt>.erubi</tt> (Erubiだけ) または<tt>.erubis</tt> (Erubisだけ)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>例</td>
|
<td>例</td>
|
||||||
|
|
|
@ -611,13 +611,15 @@ get('/') { markdown :index }
|
||||||
<tr>
|
<tr>
|
||||||
<td>Dependency</td>
|
<td>Dependency</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
<a href="https://github.com/jeremyevans/erubi" title="erubi">erubi</a>
|
||||||
|
or <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
|
||||||
or erb (included in Ruby)
|
or erb (included in Ruby)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>File Extensions</td>
|
<td>File Extensions</td>
|
||||||
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubis</tt> (Erubis only)</td>
|
<td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubi</tt> (Erubi only)
|
||||||
|
or <tt>.erubis</tt> (Erubis only)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Example</td>
|
<td>Example</td>
|
||||||
|
|
|
@ -22,7 +22,7 @@ Currently included:
|
||||||
|
|
||||||
* [`sinatra/config_file`][sinatra-config-file]: Allows loading configuration from yaml files.
|
* [`sinatra/config_file`][sinatra-config-file]: Allows loading configuration from yaml files.
|
||||||
|
|
||||||
* [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb,
|
* [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb, Erubi,
|
||||||
Erubis and Slim.
|
Erubis and Slim.
|
||||||
|
|
||||||
* [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies.
|
* [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies.
|
||||||
|
|
|
@ -86,6 +86,7 @@ module Sinatra
|
||||||
|
|
||||||
DUMMIES = {
|
DUMMIES = {
|
||||||
:haml => "!= capture_haml(*args, &block)",
|
:haml => "!= capture_haml(*args, &block)",
|
||||||
|
:erubi => "<% @capture = yield(*args) %>",
|
||||||
:erubis => "<% @capture = yield(*args) %>",
|
:erubis => "<% @capture = yield(*args) %>",
|
||||||
:slim => "== yield(*args)"
|
:slim => "== yield(*args)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Sinatra
|
||||||
# blocks inside views to be rendered later during the request. The most
|
# blocks inside views to be rendered later during the request. The most
|
||||||
# common use is to populate different parts of your layout from your view.
|
# common use is to populate different parts of your layout from your view.
|
||||||
#
|
#
|
||||||
# The currently supported engines are: Erb, Erubis, Haml and Slim.
|
# The currently supported engines are: Erb, Erubi, Erubis, Haml and Slim.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
|
|
@ -11,6 +11,15 @@ module Sinatra
|
||||||
@current_engine == :erb
|
@current_engine == :erb
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true if the current engine is `:erubi`, or `Tilt[:erb]` is set
|
||||||
|
# to Tilt::ErubisTemplate.
|
||||||
|
#
|
||||||
|
# @return [Boolean] Returns true if current engine is `:erubi`.
|
||||||
|
def erubi?
|
||||||
|
@current_engine == :erubi or
|
||||||
|
erb? && Tilt[:erb] == Tilt::ErubiTemplate
|
||||||
|
end
|
||||||
|
|
||||||
# Returns true if the current engine is `:erubis`, or `Tilt[:erb]` is set
|
# Returns true if the current engine is `:erubis`, or `Tilt[:erb]` is set
|
||||||
# to Tilt::ErubisTemplate.
|
# to Tilt::ErubisTemplate.
|
||||||
#
|
#
|
||||||
|
|
|
@ -245,7 +245,7 @@ module Sinatra
|
||||||
:css => [:less, :sass, :scss],
|
:css => [:less, :sass, :scss],
|
||||||
:xml => [:builder, :nokogiri],
|
:xml => [:builder, :nokogiri],
|
||||||
:js => [:coffee],
|
:js => [:coffee],
|
||||||
:html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab,
|
:html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius, :mab,
|
||||||
:markdown, :textile, :rdoc],
|
:markdown, :textile, :rdoc],
|
||||||
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
|
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
|
||||||
[:mab] - [:find_template, :markaby]),
|
[:mab] - [:find_template, :markaby]),
|
||||||
|
|
|
@ -45,6 +45,7 @@ EOF
|
||||||
|
|
||||||
s.add_development_dependency "rspec", "~> 3.4"
|
s.add_development_dependency "rspec", "~> 3.4"
|
||||||
s.add_development_dependency "haml"
|
s.add_development_dependency "haml"
|
||||||
|
s.add_development_dependency "erubi"
|
||||||
s.add_development_dependency "erubis"
|
s.add_development_dependency "erubis"
|
||||||
s.add_development_dependency "slim"
|
s.add_development_dependency "slim"
|
||||||
s.add_development_dependency "less"
|
s.add_development_dependency "less"
|
||||||
|
|
|
@ -19,7 +19,10 @@ describe Sinatra::Capture do
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for "a template language" do |engine|
|
shared_examples_for "a template language" do |engine|
|
||||||
lang = engine == :erubis ? :erb : engine
|
lang = engine
|
||||||
|
if engine == :erubi || engine == :erubis
|
||||||
|
lang = :erb
|
||||||
|
end
|
||||||
require "#{engine}"
|
require "#{engine}"
|
||||||
|
|
||||||
it "captures content" do
|
it "captures content" do
|
||||||
|
@ -33,6 +36,7 @@ describe Sinatra::Capture do
|
||||||
|
|
||||||
describe('haml') { it_behaves_like "a template language", :haml }
|
describe('haml') { it_behaves_like "a template language", :haml }
|
||||||
describe('slim') { it_behaves_like "a template language", :slim }
|
describe('slim') { it_behaves_like "a template language", :slim }
|
||||||
|
describe('erubi') { it_behaves_like "a template language", :erubi }
|
||||||
describe('erubis') { it_behaves_like "a template language", :erubis }
|
describe('erubis') { it_behaves_like "a template language", :erubis }
|
||||||
|
|
||||||
describe 'erb' do
|
describe 'erb' do
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe Sinatra::ContentFor do
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: liquid radius markaby builder nokogiri
|
# TODO: liquid radius markaby builder nokogiri
|
||||||
engines = %w[erb erubis haml slim]
|
engines = %w[erb erubi erubis haml slim]
|
||||||
|
|
||||||
engines.each do |inner|
|
engines.each do |inner|
|
||||||
describe inner.capitalize do
|
describe inner.capitalize do
|
||||||
|
|
|
@ -105,6 +105,14 @@ class ERBTest < Minitest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
require 'erubi'
|
||||||
|
class ErubiTest < ERBTest
|
||||||
|
def engine; Tilt::ErubiTemplate end
|
||||||
|
end
|
||||||
|
rescue LoadError
|
||||||
|
warn "#{$!}: skipping erubi tests"
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'erubis'
|
require 'erubis'
|
||||||
|
|
Loading…
Reference in a new issue