grim/gplate

propagate from branch 'org.guifications.misc.gplate' (head 20ab5922b903ddc86ef54d79a93ce68aab5da133)
to branch 'org.guifications.misc.gplate.variable_rewrite' (head 18e4dcf5085978b9251694eec1a45e6022f1ceb1)
--- a/ChangeLog Sun Mar 02 05:21:13 2008 -0600
+++ b/ChangeLog Mon Mar 17 01:43:37 2008 -0500
@@ -1,3 +1,7 @@
+Version 0.0.2:
+ * Fixed the bug where a default tag that didn't start with a word rendered
+ an empty string
+
Version 0.0.1 3/1/08:
* Initial release. Only basic templating and for loops work, I'm sure there
are plenty of bugs to be found.
--- a/gplate/gplate-template.c Sun Mar 02 05:21:13 2008 -0600
+++ b/gplate/gplate-template.c Mon Mar 17 01:43:37 2008 -0500
@@ -821,27 +821,43 @@
GType tag, GError **error)
{
GPlateFunction *function = NULL;
- gchar *name = NULL, *leftovers = NULL, *ret = NULL;
+ GType deftag = G_TYPE_INVALID;
gboolean deffunc = FALSE;
+ gchar *ret = NULL;
+
+ deftag = gplate_library_get_default_tag();
- name = gplate_util_get_first_word(contents, &leftovers);
- if(!name)
- return g_strdup("");
+ if(tag == deftag) {
+ GType f = gplate_library_get_default_function_for_tag(tag, NULL);
- function =
- gplate_template_render_find_function(name, tag, &deffunc, error);
+ function = g_object_new(f, NULL);
+
+ if(!function)
+ return g_strdup("");
- if(function) {
- if(deffunc)
- ret = gplate_function_evaluate(function, tplate, contents);
- else
- ret = gplate_function_evaluate(function, tplate, leftovers);
+ ret = gplate_function_evaluate(function, tplate, contents);
+ } else {
+ gchar *name = NULL, *leftovers = NULL;
+
+ name = gplate_util_get_first_word(contents, &leftovers);
+ if(!name)
+ return g_strdup("");
+
+ function =
+ gplate_template_render_find_function(name, tag, &deffunc, error);
- g_object_unref(G_OBJECT(function));
- }
+ if(function) {
+ if(deffunc)
+ ret = gplate_function_evaluate(function, tplate, contents);
+ else
+ ret = gplate_function_evaluate(function, tplate, leftovers);
- g_free(name);
- g_free(leftovers);
+ g_object_unref(G_OBJECT(function));
+ }
+
+ g_free(name);
+ g_free(leftovers);
+ }
return (ret) ? ret : g_strdup("");
}
--- a/tests/Makefile.am Sun Mar 02 05:21:13 2008 -0600
+++ b/tests/Makefile.am Mon Mar 17 01:43:37 2008 -0500
@@ -7,6 +7,7 @@
SUBDIRS=html templates
CLEANFILES=\
+ *.gcda \
*.gcno
if BUILD_TESTS
--- a/tests/test-syntax.c Sun Mar 02 05:21:13 2008 -0600
+++ b/tests/test-syntax.c Mon Mar 17 01:43:37 2008 -0500
@@ -96,6 +96,16 @@
OUTPUT_TEST(tplate, "abc \"{{ quoted }}\" xyz", "abc \"in quotes\" xyz");
END_TEST
+START_TEST(test_syntax_var_in_anchor_tag)
+ GPlateTemplate *tplate = gplate_template_new();
+
+ gplate_collection_add_string(tplate, "href", "http://guifications.org");
+
+ OUTPUT_TEST(tplate,
+ "<a href=\"{{ href }}\">{{ href }}</a>",
+ "<a href=\"http://guifications.org\">http://guifications.org</a>");
+END_TEST
+
START_TEST(test_syntax_two_vars_one_block)
GPlateTemplate *tplate = gplate_template_new();
@@ -182,6 +192,7 @@
tcase_add_test(tc, test_variable_newline_wrapped);
tcase_add_test(tc, test_syntax_var_in_single_quotes);
tcase_add_test(tc, test_syntax_var_in_double_quotes);
+ tcase_add_test(tc, test_syntax_var_in_anchor_tag);
tcase_add_test(tc, test_syntax_two_vars_one_block);
tcase_add_test(tc, test_syntax_one_var_nested);
tcase_add_test(tc, test_syntax_one_var_double_nested);