proposal for "separator" support

4 views
Skip to first unread message

Craig Silverstein

unread,
Jun 12, 2008, 7:43:10 PM6/12/08
to google-c...@googlegroups.com
For repeated sections, it's sometimes useful to have text that's put
*in between* the sections; that is, that's included for all
repetitions of the section except for the last. To do that now, you
need a new variable that you set up properly in code, which is kind of
annoying. It would be nice to add support to the template language
proper.

Here's the design I've come up with. If you have any thoughts or
suggestions, please speak up! Once the conversation has settled down
for a few days, I'll take some time to implement this.

craig

--cut here--

For a section named SEC, a sub-section named SEC-separator has a
special meaning. Every time we expand SEC, except for the last time,
we also expand SEC-separator exaclty once. Here's an example:

Here are the meeting attendees:
{{#SEC}}
{{NAME}}
{{#SEC-separator}}, {{/SEC-separator}}
{{/SEC}}
.

Here's something more crazy: a convoluted date specifier.
{{#DATE}}{{DATE_COMPONENT}}{{#DATE_separator}}{{SEP}}{{/DATE_separator}}{{/DATE}}

You'd set up a template dictionary to repeat DATE three times, with
DATE_COMPONENT set to the month, day, and year (or day, month, and
year :-) ), and SEP set to "/" or "-" or what-have-you.

Each time DATE_separator emits, it uses the dictionary in place at
that time (so, in the second example, you could modify SEP each time
through). If you decide to add dictionaries for SEC-separator
explicitly, they'll be expanded *in adddition* to the all-but-last
expansion that the template code will do. I can't imagine someone
doing this for any reason other than an Obfuscated Ctemplate contest.

James A. Morrison

unread,
Jun 13, 2008, 12:39:08 AM6/13/08
to google-c...@googlegroups.com

One reason I wanted SEP-separator instead of SEP_separator (the
proposal is for SEP-separator right? The date example should be fixed
:) is that the k.._... variable cannot be generated for C++.

--
Thanks,
Jim
http://phython.blogspot.com

Craig Silverstein

unread,
Jun 13, 2008, 2:54:26 AM6/13/08
to google-c...@googlegroups.com
} One reason I wanted SEP-separator instead of SEP_separator (the
} proposal is for SEP-separator right? The date example should be
} fixed :)

Right, the DATE example had a typo and said DATE_separator instead of
DATE-separator, which is the new proposed syntax. Here's the
corrected proposal:

{{#DATE}}{{DATE_COMPONENT}}{{#DATE-separator}}{{SEP}}{{/DATE-separator}}{{/DATE}}

craig

Craig Silverstein

unread,
Jun 16, 2008, 7:11:52 PM6/16/08
to google-c...@googlegroups.com
} {{#DATE}}{{DATE_COMPONENT}}{{#DATE-separator}}{{SEP}}{{/DATE-separator}}{{/DATE}}

I've been playing around with the new syntax, and I have to admit it
just doesn't look right to me. I'm going back to the original idea of
DATE_separator (rather than DATE-separator) as the name. If that
turns out to not be a favorite of folks, we can switch back to the
hyphen.

craig

Reply all
Reply to author
Forward
0 new messages