conditionally build ENGINES constant in respond_with to fix jruby dep issues

- jruby does not support redcarpet(markdown), yajl
This commit is contained in:
Ashley Williams 2015-05-15 14:54:15 -04:00
parent a987f3aabb
commit bbc888647a
2 changed files with 30 additions and 6 deletions

View File

@ -16,13 +16,13 @@ group :development, :test do
platform :jruby, :ruby do
gem 'slim', '2.1.0'
gem 'liquid', '2.6.1'
end
platform :ruby do
gem 'execjs', '2.0.0'
gem 'nokogiri', '1.5.10'
gem 'redcarpet', '2.3.0'
gem 'liquid', '2.6.1'
gem 'yajl-ruby'
gem 'therubyracer'
end

View File

@ -227,19 +227,43 @@ module Sinatra
super
end
def self.all
engines = Sinatra::Templates.instance_methods.map(&:to_sym) + [:mab] -
[:find_template, :markaby]
if defined? JRUBY_VERSION
jrubyify(engines)
end
engines
end
def self.html
engines = [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab, :markdown,
:textile, :rdoc]
if defined? JRUBY_VERSION
jrubyify(engines)
end
engines
end
def self.jrubyify(engs)
not_supported = [:yajl, :markdown]
engs.delete_if { |eng| not_supported.include?(eng) }
end
ENGINES = {
:css => [:less, :sass, :scss],
:xml => [:builder, :nokogiri],
:js => [:coffee],
:json => [:yajl],
:html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab, :markdown,
:textile, :rdoc],
:all => Sinatra::Templates.instance_methods.map(&:to_sym) + [:mab] -
[:find_template, :markaby]
:html => html,
:all => all
}
(defined? JRUBY_VERSION) ? (ENGINES[:json] = [:json_pure]) : (ENGINES[:json] = [:yajl])
ENGINES.default = []
puts ENGINES.inspect
def self.registered(base)
base.set :ext_map, Hash.new { |h,k| h[k] = [] }
base.set :template_engines, ENGINES.dup