Niclas Hedhman wrote:
On Wed, Mar 18, 2009 at 7:31 AM, Georg Ragaller <[email protected]> wrote:
I think the inconsistency stems from the fact, that the codebase is still in
a state of flux (which is good at this time) and that the code snippets used
as example code are not tied to the codebase (which is not so good). The
glue between the codebase and the sample snippets is manual work. And that
gets easily forgotten when performing a refactoring.
When possible, I have tried to tie the actual code from samples or
tutorial codebase, and as you have realized it makes the samples too
large in most cases and noise obscures the actual benefit.
Realized that and agree with you.
5. reference code snippets from the (current) codebase in the samples =>
samples are always compileable; with appropriate testcases, chances are high
that the code will even run most of the time; sample code is refactoring
safe
public class Sample
{
// $$Snippet(main)$$
public static void main( String[] args )
{
for( String string : args )
{
System.out.println();
}
}
// $$Snippet$$
}
One could wrap this functionality with a servlet (or e.g. a SiteVison-Plugin
or whatever is possible), to create the notion of a snippet-url like e.g.
This sounds like an excellent idea. Especially if one could support;
ObjectBuilder</* $$Html( "<b>") */Person/*$$Html("</b>") */> builder = ...;
And Sitevision is very capable when it comes to "Retrieve a Resource"
and sticking that into a page, so making a servlet to be mounted
sounds like straightforward.
Cheers
Niclas
I also realized that there is need for more markup, since the currrent
samples also use highlighting with bold face to attract the readers
attention.
My solution was like the following:
@Test
public void testHtmlInlineStyleDecorator()
throws MalformedURLException,
IOException,
ParseException
{
JSnippyParser jsp = new JSnippyParser();
List<StylePattern> styles = new ArrayList<StylePattern>();
styles.add( StylePattern.literal( "...", "color:#EEEEEE" ));
styles.add( StylePattern.regex( "(new)?\\s*Energy4Java",
"font-weight:bold" ) );
styles.add( StylePattern.regex( "\\s//.*", "color:green" ) );
styles.add( StylePattern.regex(
"(public|private|protected|static|final|implements|extends|new|throws|void)",
"color:blue;font-weight:bold" ) );
List<PlainSnippet> ss = jsp.parse( new File( fileName
).toURI().toURL() );
for( PlainSnippet snippet : ss )
{
Snippet hsn = new HtmlInlineStyleDecorator( new
HtmlDecorator( snippet ), styles );
System.out.println( hsn.format( true, false ) );
}
}
But that's
1. not refactoring safe and
2. one must pass the regex/stype pairs in the snippet-url, also bad.
I like your idea with the $$Html comments, even if it's verbose, but
it's solves 1. and 2.
I'll go for that, but don't expect the solution very soon, because I
currently have limited time for it.
Cheers
Georg
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev