From: jakemiles Date: 2009-12-05T01:10:24+09:00 Subject: Re: using heredoc string in erb Thanks! The .chomp fixed it. No, the intention isn't to create helper functions in Java. The web page happens to be a tutorial on Java. The helper function is a ruby helper that appliers google's syntaxhighlighting javascript thing to the provided block of text. The resulting code in the view, for posterity, is: <%= code "java", <<-"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 %> And the helper function it calls is this: def code(lang, block) "" end This turns the provided block of code into this HTML: Which is the syntax for the syntaxhighlighter package that syntax- highlights the code in the page andmakes it look quite sharp. The helper will also automagically include the right javascript file for the language of the formatted code block. On Dec 4, 9:51 am, Robert Klemme wrote: > 2009/12/4 jakemiles : > > > > > 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 %> > > Make that > CODE > %> > > IOW, place the %> on the next line. > > > If I can get this to work it would be a really cool technique for > > writing HTML helper functions. > > HTML helper functions in Java in an ERB template?  How does this work? > > Cheers > > robert > > -- > remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/