On Sep 23, 1:29 pm, Steven Roussey <[email protected]> wrote: > I take it back. I never allowed formatters in sections. Nor do I > (currently) allow node-b without the predicate. > > So currently, this is what I have working: > > {.section node-a} -- predicate function 'true' applied to node-a > {.section node-a predicate?} -- predicate applied to node-a > {.section node-a node-b|predicate?} -- predicate applied to node-b
Well, this syntax totally obscures the meaning of the | character. | is supposed to remind you of Unix pipes -- it's a filtering operation, and chainable, and associative. But I think I figured out a much preferable alternative. We will still do issue 32: http://code.google.com/p/json-template/issues/detail?id=32 And then on top of that, predicates have a slightly different syntax. This solves a number of use cases: the chaining of cases (if/elif/elif/ end), and your "moderator" use case: {.repeated section posts} Title: {title} Body: {body} {.moderator?} <-- A predicate is a directive that ends with ? <button> {id} {.end} {.end} The clever part is that a variable implicitly defines a predicate, but you can have user defined predicates too. The constructor will be t = Template("...", more_formatters=..., more_predicates=...) By default all variable names are also made into predicates. The "moderator" predicate is a function that returns whether the "moderator" variable is true. This also solves this case: {.section people} {.section num} {.plural?} There are {...@} people here. {.singular?} <-- This is an implicit {.end} for plural There is one person here. {.or} There are no people here. {.end} {.end} {.end} I think this offers all the power, with a clean syntax. The clean syntax is important. Sorry I think your syntax is a bit obscure. Even my suggestion of {.section @ if-moderator} or {.section @ if:moderator} is simply too obscure. The goal is to have someone unfamiliar with the language read it and basically get it. If we were going to do that, then I agree that {.if moderator} <button... {.end} Would be preferable. But I think the {.moderator?} scheme is even more flexible. The problem with {.if} is that it implies that there's going to be an expression after the if statement, and we already decided not to have any boolean operators in the language. What do you think? Andy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JSON Template" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/json-template?hl=en -~----------~----~----~----~------~----~------~--~---
