On 4 Dez., 12:27, Robert Klemme <shortcut... / googlemail.com> wrote:
> 2009/12/4 jakemiles <jacob.mi... / gmail.com>:
>
> > Thanks!  ¨Βθε ®γθονπ ζιψειτ>
> For me moving the "%>" to the next line fixed it.
>
>
>
> > No, the intention isn't to create helper functions in Java.  ¨Βθε χε> > page happens to be a tutorial on Java.  ¨Βθε θεμπες ζυξγτιοξ ισ ςυβω
> > 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
> >  ¨ΒΠαξεπαξεξεΚΠαξεμ ¨ξεχ ΗςιδΒαηΜαωουτ¨©©>
> > / three labels on the first row
> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΟξεΆ©©> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤχοΆ©©> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤθςεεεεεΆ©©»
>
> > CODE
> > %>
>
> > And the helper function it calls is this:
>
> >  ¨Βεζ γοδε¨μαξη¬ βμογλ©
> > <script type=\"syntaxhighlighter\" class=\"brush: #{lang}\"><!
> > [CDATA[#{block}]]></script>"
> >  ¨Βξδ
>
> > This turns the provided block of code into this HTML:
>
> > script type="syntaxhighlighter" class="brush: java"><![CDATA[
> > / create a panel using a GridBagLayout
> >  ¨ΒΠαξεπαξεξεΚΠαξεμ ¨ξεχ ΗςιδΒαηΜαωουτ¨©©>
> > / three labels on the first row
> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΟξεΆ©©> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤχοΆ©©> >  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤθςεεεεεΆ©©»
> > ]]></script>
>
> > Which is the syntax for the syntaxhighlighter package that syntax-
> > highlights the code in the page andmakes it look quite sharp.  ¨Βθε
> > helper will also automagically include the right javascript file for
> > the language of the formatted code block.
>
> Erm, why do you need a helper function for this? Why not directly
> place this in the ERB template
>
> script type="syntaxhighlighter" class="brush: java"><![CDATA[
> / create a panel using a GridBagLayout
>  ¨ΒΠαξεπαξεξεΚΠαξεμ ¨ξεχ ΗςιδΒαηΜαωουτ¨©©>
> / three labels on the first row
>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΟξεΆ©©>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤχοΆ©©>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤθςεεεεεΆ©©»
> ]]></script>
>
> Or even do
>
> <%= CODE_INTRO_JAVA %>
> / create a panel using a GridBagLayout
>  ¨ΒΠαξεπαξεξεΚΠαξεμ ¨ξεχ ΗςιδΒαηΜαωουτ¨©©>
> / three labels on the first row
>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΟξεΆ©©>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤχοΆ©©>  ¨Βαξεμ®αδδ ¨ξεχ ΚΜαβεμ ¨ΆΤθςεεεεεΆ©©»
> <%= CODE_END %>
>
> with proper definitions of both constants?  ¨Βθααν νισσιξηΏ
>
> Kind regards
>
> robert
>
> PS: Please do not top post.
>
> --
> remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/

Ah - thanks for all the suggestions.

1) you're right, it was moving the %> to its own line that did it.
The chomp isn't necessary.

2) I'll look at the HAML approach, which seems great.

3) I didn't think of using a constant, but I wouldn't.  I also always
opt for functional abstraction over a variable or constant, in case I
want to extend the behavior later without having to change all the
instances of usage.

For example, I did end up extending the functionality.  It now takes a
hash of options that it passes to syntaxhighlighter, and other options
that do my own custom stuff and wrap additional html around it.

The resulting code, much cleaner than the full syntaxhighlighter html,
is this:

<%= code :brush => "java",
         :code => <<-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
%>

And I was able to easily extend it with an option that places an image
floating to the right of the code (and changes the css class of the
syntaxhighlighter thing itself so it doesn't fill 100% of the page
width):

<%= code :brush => "java",
         :image => "http://jakemiles.smugmug.com/photos/
702110106_Wtyxg-S.jpg",
         :code => <<-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
%>