From: Wybo Dekker Date: 2009-12-04T22:08:55+09:00 Subject: Re: using heredoc string in erb Is this what you need?: #!/usr/bin/env ruby require 'erb' e = ERB.new(DATA.read) print e.result __END__ <%= code = <<-CODE.chomp // create a panel using a GridBagLayout JPanel panel = new JPanel (new GridBagLayout()); // three labels on the first row panel.add (new JLabel ("One")); panel.add (new JLabel ("Two")); panel.add (new JLabel ("Threeeee")); CODE %> jakemiles wrote: > Hi. I'd like to use heredoc notation in an erb view (I'm using Merb, > but I believe this is an erb issue, not specific to merb). For > example, I wrote a helper function that lets me use syntax like that > below. However, this example produces a parser error: > > can't find string "CODE" anywhere before EOF > > Any ideas how I can get this to work? I posted this on the merb group > as well, but I suspect it's really an erb issue: > > <%= code "java", <<-CODE > > // create a panel using a GridBagLayout > JPanel panel = new JPanel (new GridBagLayout()); > > // three labels on the first row > panel.add (new JLabel ("One")); > panel.add (new JLabel ("Two")); > panel.add (new JLabel ("Threeeee")); > > CODE %> > > If I can get this to work it would be a really cool technique for > writing HTML helper functions. > -- Wybo