Forum: Ruby New Lines on Unexecuted ERB If Statements

2f034754f0c731c93e5721deeee757b2?d=identicon&s=25 Severen Redwood (insanity133)
on 2014-08-15 08:59
Given I have this ERB template:
require File.join([File.dirname(__FILE__), 'lib', '<%= @args[0].downcase
%>', 'version.rb'])
spec = Gem::Specification.new do |s|
  s.name = '<%= @args[0].downcase %>'
  s.version = <%= @args[0].capitalize %>::VERSION
  s.author = 'Severen Redwood'
  s.email = 'severen.redwood@gmail.com'
  s.homepage = 'https://github.com/Insanity133/<%= @args[0] %>'
  s.platform = Gem::Platform::RUBY
  s.summary = 'The Swiss Army knife of project generators'
  s.description = '<%= @args[0] %> is an extensible project generator.'
  s.license = 'Apache-2.0'
  s.files = `git ls-files`.split("
")
  s.require_paths << 'lib'
  s.bindir = 'bin'
  s.executables << '<%= @args[0].downcase %>'
  s.add_development_dependency('rake')
  <% if @options[:yard] == true %>
  s.add_development_dependency('yard')
  <% else %>
  s.add_development_dependency('rdoc')
  <% end %>
  <% if @options[:cucumber] == true && @options[:minitest] == true %>
  s.add_development_dependency('cucumber')
  s.add_development_dependency('minitest')
  <% elsif @options[:cucumber] == true && @options[:minitest] == false
%>
  s.add_development_dependency('cucumber')
  s.add_development_dependency('rspec')
  <% elsif @options[:minitest] == true %>
  s.add_development_dependency('minitest')
  <% elsif @options[:minitest] == false %>
  s.add_development_dependency('rspec')
  <% end %>
  <% if @options[:man] == true %>
  s.add_development_dependency('ronn')
  <% end %>
  <% if @options[:rubocop] == true %>
  s.add_development_dependency('rubocop')
  <% end %>
  <% if @options[:rubocop] == true && @options[:minitest] == false %>
  s.add_development_dependency('rubocop-rspec')
  <% end %>
end

and I have these variables set:
@options = { rubocop: false, minitest: false, cucumber: false, yard:
false }
@args = ['Lels']

I get this output:
require File.join([File.dirname(__FILE__), 'lib', 'lels', 'version.rb'])
spec = Gem::Specification.new do |s|
  s.name = 'lels'
  s.version = Lels::VERSION
  s.author = 'Severen Redwood'
  s.email = 'severen.redwood@gmail.com'
  s.homepage = 'https://github.com/Insanity133/Lels'
  s.platform = Gem::Platform::RUBY
  s.summary = 'The Swiss Army knife of project generators'
  s.description = 'Lels is an extensible project generator.'
  s.license = 'Apache-2.0'
  s.files = `git ls-files`.split("
")
  s.require_paths << 'lib'
  s.bindir = 'bin'
  s.executables << 'lels'
  s.add_development_dependency('rake')

  s.add_development_dependency('rdoc')


  s.add_development_dependency('rspec')




end

What seems to be happening is that any embedded if statements that are
not executed leave new lines where they would be, however if they are
executed the new lines are removed. Any help with removing these
unwanted new lines would be much appreciated.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.