Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not include layout.haml in sinatra app

I have a ruby sinatra app that uses haml. I use layout.haml for a common menu across all pages. Let's say I have login.haml, main.haml and reports.haml. I only want to use layout.haml for login.haml and main.haml. How do I exclude layout.haml from reports.haml? thanks

like image 804
user2484638 Avatar asked Feb 16 '23 05:02

user2484638


1 Answers

Two (and a somewhat) ways:

Global

class MyApp < Sinatra::Base
  set :haml, :layout => false

  get '/reports' do
    haml :reports
  end
end

Blacklisting

If the number of routes that do not require layouts are less, then this is a pattern:

class MyApp < Sinatra::Base

  get '/reports' do
    haml :reports, :layout => false
  end

end

Whitelisting

If the routes that don't need a layout.haml file are more, however, Sinatra does not seem to support overriding the global declaration of set :haml, :layout => false. I've taken the liberty to open up an issue for this feature as it seems reasonable enough (Hope you won't mind).

like image 80
Kashyap Avatar answered Feb 24 '23 18:02

Kashyap