Thanks for the detailed reply! Seems they can resolve the problem thoroughly although runChildrenWithText() is a really nice function that separates logic & look well.
The point here is that splices dispersed among the templates can't have a whole view how the dynamic tags should be grouped and to be executed in some batch mode. Consider the case below, some dynamic tags scatters over a big page so can't be grouped using runChildrenWithText(). <p> <NAME1/> .... <NAME2/> ..... </p> <p> .... <AGE1/> .... .... <AGE2/> ... <MSG1/> ... <MSG3/> .... <MSG1> ..... <MSG2/> <NAME3/>...... <AGE2/> ........... and even more. Say NAME1, AGE1, MSG1, *1 can be computed by just parsing one file once, FILE1.xml, etc... I don't know if runChildrenWithText() can resolve this problem by just putting all tags above to a big splice. Seems runChildrenWithText() is designed for little html snippet and not for this case. What I'd like to have is thata "super" function, which knows the how to group the computation. In the case below, it will group *1/*2/*3 and then execute *1, *2, *3, so each xml files need to be read/parsed only once. Want to use Heist in this way. - All the final HTML pages are generated in advance, with all static tags (those use <BIND> <APPLY>) substituted. - All dynamic tags remains in the final HTML and will be substituted when users really request the page which it's inside. In this way, some overhead can be saved, and more important, we can get the whole view of the dynamic tags/splices in the final HTML pages so to open to some optimization, like pass it a super function, or more, we don't substitute them in the server side, only compute them and send to the client, let JavaScript do the jobs..... Thanks again for the great tools. On Tue, Mar 22, 2011 at 12:29 AM, MightyByte <[email protected]> wrote: > Yes, I believe this implementation will cause the files to be read > multiple times. There are several ways you can deal with this. Both > of them involve using code that was added to the Heist git repository > within the last 3 days. Hopefully within the next week or so this > code should be available from hackage. > > The first option (which has been around for awhile) is to use the static > tag. > > <static> > <p><name/><email/></p> > <p><name/><email/></p> > </static> > > This ensures that the contents of the static tag are only evaluated > once when you start your application. Obviously this isn't > appropriate for dynamic data. In that case you could use the <cache> > tag in the same way. I added code implementing this tag a few days > ago. <cache ttl="5d"> will only reload the contents if it's been more > than 5 days since it was last reloaded. See the code comments in > Text.Templating.Heist.Splices.Cache for more detail. > > Neither of these two solutions prevent the files from being read > multiple times on the first load. To do that, you need to formulate > your splices a little differently. I would suggest something as > follows. > > <withContactInfo> > <p><name/><email/></p> > <p><name/><email/></p> > </withContactInfo> > > withContactInfoSplice :: Splice Application > withContactInfoSplice = do > name <- liftIO getName > email <- liftIO getEmail > runChildrenWithText [("name", name), ("email", email)] > > runChildrenWithText is a new function committed on Friday that run's > the splice's child nodes in a new "environment" that has the name and > email splices bound. I would guess that this "inversion of control" > pattern will end up being one of the most common patterns of using > splices. It keeps all of the business logic in the code and all of > the views in the templates. In my opinion it actually makes coding > HTML somewhat enjoyable (syntax objections of the lisp crowd > notwithstanding). > > On Mon, Mar 21, 2011 at 11:46 AM, LIN Sumang <[email protected]> wrote: > > Please consider the scenario below: > > A template like this > > > > <p> <NAME/> <EMAIL/> ............ </p> > > .... > > > > <p> <NAME/> <EMAIL/> ............</p> > > > > ...... > > > > NAME & EMAIL are splices implemented in Haskell source like > > name = do read fileA > > parse & get the name attribute > > > > email = do read fileA > > parse & get the email attribute > > > > So, when Heist render the template, how many times we need to read fileA? > > If it need four, how to ease the problem? > > > > _______________________________________________ > > Snap mailing list > > [email protected] > > http://mailman-mail5.webfaction.com/listinfo/snap > > > > >
_______________________________________________ Snap mailing list [email protected] http://mailman-mail5.webfaction.com/listinfo/snap
