--- a/gplate/functions/gplate-for-function.c Wed Dec 31 20:47:11 2008 -0600
+++ b/gplate/functions/gplate-for-function.c Thu Jan 01 01:04:23 2009 -0600
@@ -26,6 +26,7 @@
#include <gplate/gplate-iterator.h>
#include <gplate/gplate-tag.h>
#include <gplate/gplate-variable.h>
+#include <gplate/tags/gplate-code-tag.h> #define SYNTAX_REGEX "^(.+)\\s+in\\s+(.+)$"
@@ -116,8 +117,8 @@
iter = gplate_collection_get_iterator(collection);
while(gplate_iterator_has_next(iter)) {
GPlateCollection *tc = GPLATE_COLLECTION(tplate);
GPlateVariable *var = NULL;
@@ -130,21 +131,10 @@
ret = gplate_collection_add_variable_with_name(tc, iter_name, var);
/* iterate through the tokens */
- while((tag = gplate_template_next_tag(tplate))) {
- const gchar *contents = NULL;
- contents = gplate_tag_get_contents(tag);
- if(contents && g_utf8_collate(contents, "endfor") == 0)
- output = gplate_template_render_tag(tplate, tag);
- g_string_append_printf(str, "%s", output);
+ output = gplate_template_render_until(tplate, &count, + GPLATE_TYPE_CODE_TAG, "endfor", + g_string_append_printf(str, "%s", output); if(gplate_iterator_has_next(iter))
gplate_template_nth_previous_tag(tplate, count);
--- a/gplate/gplate-template.c Wed Dec 31 20:47:11 2008 -0600
+++ b/gplate/gplate-template.c Thu Jan 01 01:04:23 2009 -0600
@@ -700,14 +700,28 @@
+ * gplate_template_render_until: + * @tplate: The #GPlateTemplate + * @ntags: A return address for the number of tags that were rendered + * @Varargs: A NULL terminated list of #GType, content pairs. + * Renders the tags in a template from the current point until it a tag is + * found that is the correct type and has the same contents as one of the + * #GType, content pairs. -gplate_template_render_until(GPlateTemplate *tplate, ...) {
+gplate_template_render_until(GPlateTemplate *tplate, guint *ntags, ...) { + GType type = G_TYPE_INVALID; - gchar *contents = NULL;
+ gboolean backup = FALSE; g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
@@ -717,14 +731,17 @@
/* store all of the content/tag pairs */
- va_start(args, tplate);
- while((contents = va_arg(args, gchar *)) != NULL) {
+ while((type = va_arg(args, gsize)) != G_TYPE_INVALID) { GPlateTemplateTagData *td = NULL;
+ gchar *contents = NULL; td = g_new(GPlateTemplateTagData, 1);
- td->contents = contents;
- td->type = va_arg(args, GType);
+ contents = va_arg(args, gchar *); + td->contents = contents ? g_strdup(contents) : NULL; g_queue_push_tail(queue, td);
@@ -746,16 +763,21 @@
g_utf8_collate(ctd.contents, td->contents) == 0)
g_string_append_printf(str, "%s",
gplate_template_render_tag(tplate, tag));
/* now clean everything up... */
@@ -771,6 +793,18 @@
g_string_free(str, FALSE);
+ /* if backup is set, we back up to the tag which caused us to stop. In + * other words, the tag stack will currently be at the tag after the one + * we stopped at, but we want to be on the one that we stopped on. + gplate_template_previous_tag(tplate); @@ -846,7 +880,7 @@
* Moves the tag stack forward one tag and returns it.
- * Return Value: The previous tag or NULL.
+ * Return Value: The next tag or NULL. gplate_template_next_tag(GPlateTemplate *tplate) {
@@ -950,7 +984,7 @@
klass->insert_tags(tplate, tags);
gplate_template_render_token(GPlateTemplate *tplate, const gchar *contents,
GType tag, GError **error)
--- a/gplate/gplate-template.h Wed Dec 31 20:47:11 2008 -0600
+++ b/gplate/gplate-template.h Thu Jan 01 01:04:23 2009 -0600
@@ -76,7 +76,7 @@
gchar *gplate_template_render(GPlateTemplate *tplate, const gchar *tplate_string, GError **error);
gchar *gplate_template_render_file(GPlateTemplate *tplate, const gchar *filename, GError **error);
-gchar *gplate_template_render_until(GPlateTemplate *tplate, ...);
+gchar *gplate_template_render_until(GPlateTemplate *tplate, guint *ntags, ...); GPlateTag *gplate_template_first_tag(GPlateTemplate *tplate);
GPlateTag *gplate_template_last_tag(GPlateTemplate *tplate);