Module: Sinatra::MultiRender::Helpers
- Defined in:
- lib/sinatra/support/multirender.rb
Instance Method Summary collapse
-
#show(template, options = {}, locals = {}, &block) ⇒ Object
Shows a given template.
Instance Method Details
#show(template, options = {}, locals = {}, &block) ⇒ Object
Shows a given template.
You may pass options[:engine]
to specify which engines you will want to limit the search to. This defaults to App.multi_engines
, or Tilt’s supported engines if that’s not defined.
You may pass options[:views]
to specify which directories to scour. This defaults to App.multi_views
, or App.views
.
Examples
# Only HAML
show :home, engine: :haml
# HAML or ERB, favoring HAML first
show :home, engine: [:haml, :erb]
# Only look at certain paths
show :home, views: [ './views', './skins/default' ]
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sinatra/support/multirender.rb', line 58 def show(template, ={}, locals={}, &block) paths = [*([:views] || settings.multi_views)].join(',') engines = [*([:engine] || settings.multi_engines)].join(',') t = @template_cache.fetch template, do spec = "{#{paths}}/#{template}.{#{engines}}" template = Dir[spec].first or raise Errno::ENOENT.new(spec) ext = File.extname(template)[1..-1].to_sym = settings.send(ext).merge() if settings.respond_to?(ext) engine = Tilt[ext] or raise "Template engine not found: #{ext}" engine.new(template, 0, ) end t.render(self, locals, &block) if t end |