Sinatra: Suppress Newline in ERB
Posted by Christopher Rigor on November 11, 2009
Filed Under Web Development
To suppress newline in ERB on Rails, you just add a dash on the closing tag -%>. In Sinatra, as of version 0.9.4, adding a dash doesn’t work. This has been fixed recently on the tilt gem version 0.3 which Sinatra uses for templates. You also need Sinatra newer than 0.9.4, which doesn’t exist yet so you need to get Sinatra from source.
You need to get tilt 0.3 from gemcutter.org.
sudo gem install --no-ri --no-rdoc tilt --source=http://gemcutter.org
To get the latest Sinatra
cd myapp
git clone git://github.com/sinatra/sinatra.git
and add it to the LOAD_PATH
$LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
To set the dash as the ‘trim’ character, add
set :erb, :trim => '-'