diff --git a/Gemfile b/Gemfile index 7989a8a5..13bee90d 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ if RUBY_ENGINE == "ruby" gem 'stylus' gem 'rabl' gem 'builder' + gem 'erubi' gem 'erubis' gem 'haml', '>= 3.0' gem 'sass' diff --git a/README.ja.md b/README.ja.md index 1b9d2313..6205494d 100644 --- a/README.ja.md +++ b/README.ja.md @@ -551,13 +551,14 @@ get('/') { markdown :index } 依存 - erubis + erubi + または erubis または erb (Rubyに同梱) ファイル拡張子 - .erb, .rhtml or .erubis (Erubisだけ) + .erb, .rhtml または .erubi (Erubiだけ) または.erubis (Erubisだけ) 例 diff --git a/README.md b/README.md index 63684beb..336ac2b9 100644 --- a/README.md +++ b/README.md @@ -611,13 +611,15 @@ get('/') { markdown :index } Dependency - erubis + erubi + or erubis or erb (included in Ruby) File Extensions - .erb, .rhtml or .erubis (Erubis only) + .erb, .rhtml or .erubi (Erubi only) + or .erubis (Erubis only) Example diff --git a/sinatra-contrib/README.md b/sinatra-contrib/README.md index 599cf93e..1dbb518d 100644 --- a/sinatra-contrib/README.md +++ b/sinatra-contrib/README.md @@ -22,7 +22,7 @@ Currently included: * [`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. * [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies. diff --git a/sinatra-contrib/lib/sinatra/capture.rb b/sinatra-contrib/lib/sinatra/capture.rb index 8a5d5fd9..0bbe7a17 100644 --- a/sinatra-contrib/lib/sinatra/capture.rb +++ b/sinatra-contrib/lib/sinatra/capture.rb @@ -86,6 +86,7 @@ module Sinatra DUMMIES = { :haml => "!= capture_haml(*args, &block)", + :erubi => "<% @capture = yield(*args) %>", :erubis => "<% @capture = yield(*args) %>", :slim => "== yield(*args)" } diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb index c61d8191..5fb88559 100644 --- a/sinatra-contrib/lib/sinatra/content_for.rb +++ b/sinatra-contrib/lib/sinatra/content_for.rb @@ -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 # diff --git a/sinatra-contrib/lib/sinatra/engine_tracking.rb b/sinatra-contrib/lib/sinatra/engine_tracking.rb index 47239afb..5ff2f75b 100644 --- a/sinatra-contrib/lib/sinatra/engine_tracking.rb +++ b/sinatra-contrib/lib/sinatra/engine_tracking.rb @@ -11,6 +11,15 @@ module Sinatra @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. # diff --git a/sinatra-contrib/lib/sinatra/respond_with.rb b/sinatra-contrib/lib/sinatra/respond_with.rb index 096a5f8a..8521ca98 100644 --- a/sinatra-contrib/lib/sinatra/respond_with.rb +++ b/sinatra-contrib/lib/sinatra/respond_with.rb @@ -245,7 +245,7 @@ module Sinatra :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]), diff --git a/sinatra-contrib/sinatra-contrib.gemspec b/sinatra-contrib/sinatra-contrib.gemspec index a61cd8bf..7d0d7852 100644 --- a/sinatra-contrib/sinatra-contrib.gemspec +++ b/sinatra-contrib/sinatra-contrib.gemspec @@ -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" diff --git a/sinatra-contrib/spec/capture_spec.rb b/sinatra-contrib/spec/capture_spec.rb index b65fcafb..bb94f1fc 100644 --- a/sinatra-contrib/spec/capture_spec.rb +++ b/sinatra-contrib/spec/capture_spec.rb @@ -19,7 +19,10 @@ describe Sinatra::Capture do 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 @@ -33,6 +36,7 @@ describe Sinatra::Capture do 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 diff --git a/sinatra-contrib/spec/content_for_spec.rb b/sinatra-contrib/spec/content_for_spec.rb index d0902889..684f4a76 100644 --- a/sinatra-contrib/spec/content_for_spec.rb +++ b/sinatra-contrib/spec/content_for_spec.rb @@ -73,7 +73,7 @@ describe Sinatra::ContentFor do end # TODO: liquid radius markaby builder nokogiri - engines = %w[erb erubis haml slim] + engines = %w[erb erubi erubis haml slim] engines.each do |inner| describe inner.capitalize do diff --git a/test/erb_test.rb b/test/erb_test.rb index 40d02ce6..90c616f8 100644 --- a/test/erb_test.rb +++ b/test/erb_test.rb @@ -105,6 +105,14 @@ class ERBTest < Minitest::Test end end +begin + require 'erubi' + class ErubiTest < ERBTest + def engine; Tilt::ErubiTemplate end + end +rescue LoadError + warn "#{$!}: skipping erubi tests" +end begin require 'erubis'