grim/gplate

The start of the rendering rewrite
render_rewrite
2008-02-12, grim
5b36743914fd
Parents d2a01081f3df
Children 05bb9395cf2e
The start of the rendering rewrite
--- a/gplate/gplate-code-tag.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-code-tag.c Tue Feb 12 04:00:11 2008 -0600
@@ -35,11 +35,6 @@
return "%}";
}
-static gchar *
-gplate_code_tag_render(const GPlateTag *tag, GPlateTemplate *tplate) {
- return NULL;
-}
-
/******************************************************************************
* Object Stuff
*****************************************************************************/
@@ -49,8 +44,6 @@
tag_class->get_prefix = gplate_code_tag_class_get_prefix;
tag_class->get_suffix = gplate_code_tag_class_get_suffix;
-
- tag_class->render = gplate_code_tag_render;
}
/******************************************************************************
--- a/gplate/gplate-comment-tag.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-comment-tag.c Tue Feb 12 04:00:11 2008 -0600
@@ -35,11 +35,6 @@
return "#}";
}
-static gchar *
-gplate_comment_tag_render(const GPlateTag *tag, GPlateTemplate *tplate) {
- return g_strdup("");
-}
-
/******************************************************************************
* Object Stuff
*****************************************************************************/
@@ -49,8 +44,6 @@
tag_class->get_prefix = gplate_comment_tag_class_get_prefix;
tag_class->get_suffix = gplate_comment_tag_class_get_suffix;
-
- tag_class->render = gplate_comment_tag_render;
}
/******************************************************************************
--- a/gplate/gplate-function.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-function.c Tue Feb 12 04:00:11 2008 -0600
@@ -53,15 +53,15 @@
/**
* gplate_function_evaluate:
* @function: The #GPlateFunction.
- * @variables: The #GPlateCollection to use as the variable store.
+ * @tplate: The #GPlateTemplate that @function is being evaluated for.
* @contents: The contents for the function to use.
*
- * Evaluates @contents using @function with the @variables collection.
+ * Evaluates @contents using @function for @tplate.
*
* Return Value: The evaluated output.
*/
gchar *
-gplate_function_evaluate(GPlateFunction *function, GPlateCollection *variables,
+gplate_function_evaluate(GPlateFunction *function, GPlateTemplate *tplate,
const gchar *contents)
{
GPlateFunctionClass *klass = NULL;
@@ -71,7 +71,7 @@
klass = GPLATE_FUNCTION_GET_CLASS(function);
if(klass && klass->evaluate)
- return klass->evaluate(function, variables, contents);
+ return klass->evaluate(function, tplate, contents);
return NULL;
}
--- a/gplate/gplate-function.h Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-function.h Tue Feb 12 04:00:11 2008 -0600
@@ -22,7 +22,7 @@
#include <glib.h>
#include <glib-object.h>
-#include <gplate/gplate-collection.h>
+#include <gplate/gplate-template.h>
#define GPLATE_TYPE_FUNCTION (gplate_function_get_gtype())
#define GPLATE_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLATE_TYPE_FUNCTION, GPlateFunction))
@@ -46,7 +46,7 @@
struct _GPlateFunctionClass {
GObjectClass parent;
- gchar *(*evaluate)(GPlateFunction *function, GPlateCollection *variables, const gchar *contents);
+ gchar *(*evaluate)(GPlateFunction *function, GPlateTemplate *tplate, const gchar *contents);
void (*_gplate_reserved1)(void);
void (*_gplate_reserved2)(void);
@@ -58,7 +58,7 @@
GType gplate_function_get_gtype(void);
-gchar *gplate_function_evaluate(GPlateFunction *function, GPlateCollection *variables, const gchar *contents);
+gchar *gplate_function_evaluate(GPlateFunction *function, GPlateTemplate *tplate, const gchar *contents);
G_END_DECLS
--- a/gplate/gplate-noop-function.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-noop-function.c Tue Feb 12 04:00:11 2008 -0600
@@ -22,27 +22,11 @@
#include <gplate/gplate-noop-function.h>
-#define GPLATE_NOOP_FUNCTION_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLATE_TYPE_NOOP_FUNCTION, GPlateNoopFunctionPrivate))
-
-/******************************************************************************
- * Enums
- *****************************************************************************/
-
-/******************************************************************************
- * Structs
- *****************************************************************************/
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-
/******************************************************************************
* NoopFunction Stuff
*****************************************************************************/
static gchar *
-gplate_noop_function_evaluate(GPlateFunction *function,
- GPlateCollection *variables,
+gplate_noop_function_evaluate(GPlateFunction *function, GPlateTemplate *tplate,
const gchar *contents)
{
return g_strdup("");
--- a/gplate/gplate-print-function.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-print-function.c Tue Feb 12 04:00:11 2008 -0600
@@ -27,8 +27,8 @@
*****************************************************************************/
static gchar *
gplate_print_function_evaluate(GPlateFunction *function,
- GPlateCollection *variables,
- const gchar *contents)
+ GPlateTemplate *tplate,
+ const gchar *contents)
{
return (contents) ? g_strdup(contents) : NULL;
}
--- a/gplate/gplate-tag.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-tag.c Tue Feb 12 04:00:11 2008 -0600
@@ -30,6 +30,7 @@
*****************************************************************************/
enum {
PROP_ZERO,
+ PROP_TEMPLATE,
PROP_CONTENTS,
PROP_LAST,
};
@@ -38,6 +39,7 @@
* Structs
*****************************************************************************/
typedef struct {
+ GPlateTemplate *tplate;
gchar *contents;
} GPlateTagPrivate;
@@ -49,11 +51,19 @@
/******************************************************************************
* Tag Stuff
*****************************************************************************/
-static const gchar *
+static void
+gplate_tag_real_set_template(GPlateTag *tag, GPlateTemplate *tplate) {
+ GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(tag);
+
+ if(GPLATE_IS_TEMPLATE(tplate))
+ priv->tplate = g_object_ref(tplate);
+}
+
+static gchar *
gplate_tag_real_get_contents(const GPlateTag *tag) {
GPlateTagPrivate *priv = GPLATE_TAG_GET_PRIVATE(tag);
- return priv->contents;
+ return (priv->contents) ? g_strdup(priv->contents) : NULL;
}
static void
@@ -75,6 +85,9 @@
GPlateTag *tag = GPLATE_TAG(obj);
switch(param_id) {
+ case PROP_TEMPLATE:
+ g_value_set_object(value, gplate_tag_get_template(tag));
+ break;
case PROP_CONTENTS:
g_value_set_string(value, gplate_tag_get_contents(tag));
break;
@@ -91,6 +104,9 @@
GPlateTag *tag = GPLATE_TAG(obj);
switch(param_id) {
+ case PROP_TEMPLATE:
+ gplate_tag_real_set_template(tag, g_value_get_object(value));
+ break;
case PROP_CONTENTS:
gplate_tag_real_set_contents(tag, g_value_get_string(value));
break;
@@ -124,6 +140,12 @@
klass->get_contents = gplate_tag_real_get_contents;
+ pspec = g_param_spec_object("template", "template",
+ "The template this tag belongs to.",
+ GPLATE_TYPE_TEMPLATE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property(obj_class, PROP_TEMPLATE, pspec);
+
pspec = g_param_spec_string("contents", "contents",
"The contents of the tag.",
NULL,
@@ -160,6 +182,25 @@
}
/**
+ * gplate_tag_get_template:
+ * @tag: The #GPlateTag.
+ *
+ * Gets the #GPlateTemplate to which @tag belongs.
+ *
+ * Return Value: The #GPlateTemplate that @tag belongs to.
+ */
+GPlateTemplate *
+gplate_tag_get_template(const GPlateTag *tag) {
+ GPlateTagPrivate *priv = NULL;
+
+ g_return_val_if_fail(GPLATE_IS_TAG(tag), NULL);
+
+ priv = GPLATE_TAG_GET_PRIVATE(tag);
+
+ return priv->tplate;
+}
+
+/**
* gplate_tag_get_contents:
* @tag: The #GPlateTag whose contents to get.
*
@@ -167,7 +208,7 @@
*
* Return Value: The contents of @tag.
*/
-const gchar *
+gchar *
gplate_tag_get_contents(const GPlateTag *tag) {
GPlateTagClass *klass = NULL;
@@ -182,29 +223,6 @@
}
/**
- * gplate_tag_render:
- * @tag: The #GPlateTag to render.
- * @tplate: The #GPlateTemplate that's rendering @tag.
- *
- * Renders @tag.
- *
- * Return Value: The rendered output of @tag.
- */
-gchar *
-gplate_tag_render(const GPlateTag *tag, GPlateTemplate *tplate) {
- GPlateTagClass *klass = NULL;
-
- g_return_val_if_fail(GPLATE_IS_TAG(tag), NULL);
-
- klass = GPLATE_TAG_GET_CLASS(tag);
-
- if(klass && klass->render)
- return klass->render(tag, tplate);
-
- return NULL;
-}
-
-/**
* gplate_tag_class_get_prefix:
* @tag_class: The #GPlateTagClass whose prefix to grab
*
--- a/gplate/gplate-tag.h Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-tag.h Tue Feb 12 04:00:11 2008 -0600
@@ -22,9 +22,9 @@
#include <glib.h>
#include <glib-object.h>
-#define GPLATE_TYPE_TAG (gplate_tag_get_gtype())
-#define GPLATE_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLATE_TYPE_TAG, GPlateTag))
-#define GPLATE_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GPLATE_TYPE_TAG, GPlateTagClass))
+#define GPLATE_TYPE_TAG (gplate_tag_get_gtype())
+#define GPLATE_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLATE_TYPE_TAG, GPlateTag))
+#define GPLATE_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GPLATE_TYPE_TAG, GPlateTagClass))
#define GPLATE_IS_TAG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GPLATE_TYPE_TAG))
#define GPLATE_IS_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GPLATE_TYPE_TAG))
#define GPLATE_TAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GPLATE_TYPE_TAG, GPlateTagClass))
@@ -46,9 +46,7 @@
struct _GPlateTagClass {
GObjectClass parent;
- const gchar *(*get_contents)(const GPlateTag *tag);
-
- gchar *(*render)(const GPlateTag *tag, GPlateTemplate *tplate);
+ gchar *(*get_contents)(const GPlateTag *tag);
const gchar *(*get_prefix)(const GPlateTagClass *tag_class);
const gchar *(*get_suffix)(const GPlateTagClass *tag_class);
@@ -63,9 +61,8 @@
GType gplate_tag_get_gtype(void);
-const gchar *gplate_tag_get_contents(const GPlateTag *tag);
-
-gchar *gplate_tag_render(const GPlateTag *tag, GPlateTemplate *tplate);
+GPlateTemplate *gplate_tag_get_template(const GPlateTag *tag);
+gchar *gplate_tag_get_contents(const GPlateTag *tag);
const gchar *gplate_tag_class_get_prefix(const GPlateTagClass *tag_class);
const gchar *gplate_tag_class_get_suffix(const GPlateTagClass *tag_class);
--- a/gplate/gplate-template.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-template.c Tue Feb 12 04:00:11 2008 -0600
@@ -22,6 +22,7 @@
#include <gplate/gplate-template.h>
+#include <gplate/gplate-collection.h>
#include <gplate/gplate-dictionary-variable.h>
#include <gplate/gplate-errors.h>
#include <gplate/gplate-library.h>
--- a/gplate/gplate-text-tag.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-text-tag.c Tue Feb 12 04:00:11 2008 -0600
@@ -23,26 +23,6 @@
#include <gplate/gplate-text-tag.h>
/******************************************************************************
- * Tag stuff
- *****************************************************************************/
-static gchar *
-gplate_text_tag_render(const GPlateTag *tag, GPlateTemplate *tplate) {
- const gchar *contents = gplate_tag_get_contents(tag);
-
- return (contents) ? g_strdup(contents) : NULL;
-}
-
-/******************************************************************************
- * Object Stuff
- *****************************************************************************/
-static void
-gplate_text_tag_class_init(GPlateTextTagClass *klass) {
- GPlateTagClass *tag_class = GPLATE_TAG_CLASS(klass);
-
- tag_class->render = gplate_text_tag_render;
-}
-
-/******************************************************************************
* GPlateTextTag API
*****************************************************************************/
GType
@@ -54,7 +34,7 @@
sizeof(GPlateTextTagClass),
NULL,
NULL,
- (GClassInitFunc)gplate_text_tag_class_init,
+ NULL,
NULL,
NULL,
sizeof(GPlateTextTag),
--- a/gplate/gplate-variable-tag.c Mon Feb 11 05:10:17 2008 -0600
+++ b/gplate/gplate-variable-tag.c Tue Feb 12 04:00:11 2008 -0600
@@ -26,6 +26,11 @@
#include <gplate/gplate-variable.h>
/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static GObjectClass *parent_class = NULL;
+
+/******************************************************************************
* Tag stuff
*****************************************************************************/
static const gchar *
@@ -39,11 +44,12 @@
}
static gchar *
-gplate_variable_tag_render(const GPlateTag *tag, GPlateTemplate *tplate) {
+gplate_variable_tag_get_contents(const GPlateTag *tag) {
+ GPlateTemplate *tplate = NULL;
GPlateVariable *variable = NULL;
GRegex *regex = NULL;
GMatchInfo *info = NULL;
- gchar *name = NULL;
+ gchar *name = NULL, *contents = NULL;
const gchar *value = NULL;
/* create our regex with available variable characters and ignore
@@ -56,8 +62,12 @@
if(!regex)
return g_strdup("");
+ /* grab the contents from the parent */
+ contents = GPLATE_TAG_CLASS(parent_class)->get_contents(tag);
+
/* make sure our regex matches */
- if(!g_regex_match(regex, gplate_tag_get_contents(tag), 0, &info)) {
+ if(!g_regex_match(regex, contents, 0, &info)) {
+ g_free(contents);
g_regex_unref(regex);
return g_strdup("");
@@ -68,6 +78,7 @@
/* make sure we have the correct number of matches */
if(g_match_info_get_match_count(info) < 2) {
+ g_free(contents);
g_match_info_free(info);
return g_strdup("");
@@ -75,6 +86,9 @@
/* get and validate the variable name */
name = g_match_info_fetch(info, 1);
+
+ g_free(contents);
+
if(!name) {
g_match_info_free(info);
@@ -82,6 +96,7 @@
}
/* find the variable from the name */
+ tplate = gplate_tag_get_template(tag);
variable = gplate_collection_find_variable(GPLATE_COLLECTION(tplate),
name);
g_free(name);
@@ -107,10 +122,12 @@
gplate_variable_tag_class_init(GPlateVariableTagClass *klass) {
GPlateTagClass *tag_class = GPLATE_TAG_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+
tag_class->get_prefix = gplate_variable_tag_class_get_prefix;
tag_class->get_suffix = gplate_variable_tag_class_get_suffix;
- tag_class->render = gplate_variable_tag_render;
+ tag_class->get_contents = gplate_variable_tag_get_contents;
}
/******************************************************************************