Discovering Turbine source I found that code for pages, screens and
layouts are similar for WebMacro, FreeMaker and possibly others
template engines in the future.

So what about to "generalize" design patterns for layouts and screens.

For example generic class for Layouts may be looking as:

public abstract class TemplateSiteLayout
    extends Layout
{
    public interface Context
    {
        public void put(String name, Object value);
    }

    public void doBuild( RunData data ) throws Exception
    {
        Context context = getContext( data );
        String returnValue = "";
        
        ConcreteElement results = ScreenLoader.getInstance()
            .eval(data, data.getScreen());
        if (results != null)
            returnValue = results.toString();

        context.put("screen_placeholder", returnValue);

        context.put("navigation", getNavigation( data ));

        String templateName = data.getTemplateInfo().getLayoutTemplate();
        if (templateName == null)
        {
            TemplateService ts = (TemplateService)TurbineServices
                .getInstance().getService(TemplateService.SERVICE_NAME);
            
            templateName = "/default."+ts.getDefaultExtension();
        }
        
        String page = generateLayout(data, context, "layouts" + templateName);
        
        data.getPage().getBody().addElement(page);
    }

    protected abstract Context getContext(RunData data);
    
    protected abstract Object getNavigation(RunData data);

    protected abstract String generateLayout(RunData data, Context context, String 
template);
    
}

And with this implementation of Layout for new template engine you need
only rewrite free methods.

This design may be useful also if you want to postprocess your
screens, layouts and navigations, for example with XSLT processor.


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to