lib/grape-rabl/formatter.rb in grape-rabl-0.4.1 vs lib/grape-rabl/formatter.rb in grape-rabl-0.4.2
- old
+ new
@@ -46,11 +46,11 @@
def rablable?
!!rabl_template
end
def rabl
- fail 'missing rabl template' unless rabl_template
+ raise 'missing rabl template' unless rabl_template
set_view_root unless env['api.tilt.root']
yield rabl_template
end
def locals
@@ -60,16 +60,16 @@
def rabl_template
env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl]
end
def set_view_root
- fail "Use Rack::Config to set 'api.tilt.root' in config.ru"
+ raise "Use Rack::Config to set 'api.tilt.root' in config.ru"
end
def tilt_template(template)
if Grape::Rabl.configuration.cache_template_loading
- Grape::Rabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) }
+ Grape::Rabl::Formatter.tilt_cache.fetch(tilt_cache_key(template)) { ::Tilt.new(view_path(template), tilt_options) }
else
::Tilt.new(view_path(template), tilt_options)
end
end
@@ -78,13 +78,17 @@
end
def layout_template
layout_path = view_path(env['api.tilt.layout'] || 'layouts/application')
if Grape::Rabl.configuration.cache_template_loading
- Grape::Rabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) }
+ Grape::Rabl::Formatter.tilt_cache.fetch(tilt_cache_key(layout_path)) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) }
else
::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path)
end
+ end
+
+ def tilt_cache_key(path)
+ Digest::MD5.hexdigest("#{path}#{tilt_options}")
end
end
end
end