Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1487 update test and docs to support erubi #1494

Merged
merged 4 commits into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if RUBY_ENGINE == "ruby"
gem 'stylus'
gem 'rabl'
gem 'builder'
gem 'erubi'
gem 'erubis'
gem 'haml', '>= 3.0'
gem 'sass'
Expand Down
5 changes: 3 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,14 @@ get('/') { markdown :index }
<tr>
<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に同梱)
</td>
</tr>
<tr>
<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>
<td>例</td>
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,15 @@ get('/') { markdown :index }
<tr>
<td>Dependency</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)
</td>
</tr>
<tr>
<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>
<td>Example</td>
Expand Down
4 changes: 4 additions & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ def erb(template, options = {}, locals = {}, &block)
render(:erb, template, options, locals, &block)
end

def erubi(template, options = {}, locals = {}, &block)
render(:erubi, template, options, locals, &block)
end
tkmru marked this conversation as resolved.
Show resolved Hide resolved

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."
Expand Down
1 change: 1 addition & 0 deletions sinatra-contrib/lib/sinatra/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module Capture

DUMMIES = {
:haml => "!= capture_haml(*args, &block)",
:erubi => "<% @capture = yield(*args) %>",
:erubis => "<% @capture = yield(*args) %>",
:slim => "== yield(*args)"
}
Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/lib/sinatra/content_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Sinatra
# 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.
#
# The currently supported engines are: Erb, Erubis, Haml and Slim.
# The currently supported engines are: Erb, Erubi, Erubis, Haml and Slim.
#
# == Usage
#
Expand Down
9 changes: 9 additions & 0 deletions sinatra-contrib/lib/sinatra/engine_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def erb?
@current_engine == :erb
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
# to Tilt::ErubisTemplate.
#
Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/lib/sinatra/respond_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def self.engines
:css => [:less, :sass, :scss],
:xml => [:builder, :nokogiri],
:js => [:coffee],
:html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab,
:html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius, :mab,
:markdown, :textile, :rdoc],
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
[:mab] - [:find_template, :markaby]),
Expand Down
1 change: 1 addition & 0 deletions sinatra-contrib/sinatra-contrib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ EOF

s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "haml"
s.add_development_dependency "erubi"
s.add_development_dependency "erubis"
s.add_development_dependency "slim"
s.add_development_dependency "less"
Expand Down
6 changes: 5 additions & 1 deletion sinatra-contrib/spec/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def render(engine, template)
end

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}"

it "captures content" do
Expand All @@ -33,6 +36,7 @@ def render(engine, template)

describe('haml') { it_behaves_like "a template language", :haml }
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 'erb' do
Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/spec/content_for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def render(engine, template)
end

# TODO: liquid radius markaby builder nokogiri
engines = %w[erb erubis haml slim]
engines = %w[erb erubi erubis haml slim]
tkmru marked this conversation as resolved.
Show resolved Hide resolved

engines.each do |inner|
describe inner.capitalize do
Expand Down
8 changes: 8 additions & 0 deletions test/erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def is; "IS." end
end
end

begin
require 'erubi'
class ErubiTest < ERBTest
def engine; Tilt::ErubiTemplate end
end
rescue LoadError
warn "#{$!}: skipping erubi tests"
end

begin
require 'erubis'
Expand Down