]> git.llucax.com Git - software/bife/bife++.git/commitdiff
Added a fallback implementation.
authorLeandro Lucarella <llucax@gmail.com>
Fri, 15 Aug 2003 05:42:35 +0000 (05:42 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Fri, 15 Aug 2003 05:42:35 +0000 (05:42 +0000)
Makefile
translate.cpp [new file with mode: 0644]
translate.h [new file with mode: 0644]

index 402293be63ade1d57841ece34b332676154eb331..e03f97c43631e44a95b252a9f067398b5a4a21f8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 CPPFLAGS=-g3 -Wall -DDEBUG
 #CPPFLAGS=-O3 -Wall
 
-TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o
+TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o translate.o
 
 all: main
 
diff --git a/translate.cpp b/translate.cpp
new file mode 100644 (file)
index 0000000..d3bb41b
--- /dev/null
@@ -0,0 +1,74 @@
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#include "translate.h"
+#include <sstream>
+
+using std::stringstream;
+using namespace bife;
+
+#ifdef DEBUG
+#include <iostream>
+using std::cerr;
+using std::endl;
+#endif
+
+Translate::Translate(const string& name): Fallback(name) {
+#ifdef DEBUG
+    cerr << "In Translate::Translate(name = '" << name << "');" << endl;
+#endif
+}
+
+Translate::Translate(const string& name, const Hash& attrs): Fallback(name, attrs) {
+#ifdef DEBUG
+    cerr << "In Translate::Translate(name = '" << name
+        << "', attrs = {" /* TODO << attrs */ << "});" << endl;
+#endif
+}
+
+Translate::Translate(const string& name, const Hash& attrs, Widget& content):
+        Fallback(name, attrs, content) {
+    // FIXME - this->content.push_back(content);
+#ifdef DEBUG
+    cerr << "In Translate::Translate(name = '" << name
+        << "', attrs = {" /* TODO << attrs */
+        << "}, content = {" /* TODO << content */ << "});" << endl;
+#endif
+}
+
+Translate::Translate(const string& name, Widget& content, const Hash& attrs):
+        Fallback(name, content, attrs) {
+    // FIXME - this->content.push_back(content);
+#ifdef DEBUG
+    cerr << "In Translate::Translate(name = '" << name
+        << "', content = {" /* TODO << content */
+        << "}, attrs = {" /* TODO << attrs */ << "});" << endl;
+#endif
+}
+
+Translate::~Translate(void) {
+#ifdef DEBUG
+    cerr << "In Translate destructor." << endl;
+#endif
+}
+
+string Translate::render(HIT& tpl) {
+    stringstream out;
+    if (false /* TODO tpl.exists(name, '')*/) {
+        Hash a = attrs;
+        a["CONTENT"] = renderContent(tpl);
+        out << tpl.parse(name, attrs /* TODO ,"", "" */);
+    } else {
+        out << "<" << name;
+        for (Hash::iterator i = attrs.begin(); i != attrs.end(); i++) {
+            out << " " << i->first << "=\"" << i->second << "\"";
+        }
+        string c = renderContent(tpl);
+        if (c.empty()) {
+            out << " />";
+        } else {
+            out << ">" << c << "</" << name << ">";
+        }
+    }
+    return out.str();
+}
+
diff --git a/translate.h b/translate.h
new file mode 100644 (file)
index 0000000..8a11499
--- /dev/null
@@ -0,0 +1,82 @@
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#ifndef BIFE_TRANSLATE_H
+#define BIFE_TRANSLATE_H
+
+#include "fallback.h"
+#include "widget.h"
+#include "hit.h"
+#include "hash.h"
+#include <vector>
+#include <string>
+
+namespace bife {
+
+    using std::string;
+
+    /**
+     * Base Translate Widget.
+     *
+     * @todo 
+     */
+    class Translate: public Fallback {
+        // Methods.
+        public:
+            /**
+             * Constructor.
+             *
+             * @param name    Name of the widget.
+             */
+            Translate(const string&);
+
+            /**
+             * Constructor.
+             *
+             * @param name    Name of the widget.
+             * @param attrs   Widget attributes.
+             */
+            Translate(const string&, const Hash&);
+
+            /**
+             * Constructor.
+             *
+             * @param name    Name of the widget.
+             * @param attrs   Widget attributes.
+             * @param content Content of the widget.
+             */
+            Translate(const string&, const Hash&, Widget&);
+
+            /**
+             * Constructor.
+             *
+             * @param name    Name of the widget.
+             * @param content Content of the widget.
+             */
+            Translate(const string&, Widget&);
+
+            /**
+             * Constructor.
+             *
+             * @param name    Name of the widget.
+             * @param content Content of the widget.
+             * @param attrs   Widget attributes.
+             */
+            Translate(const string&, Widget&, const Hash&);
+
+            /**
+             * Destructor.
+             */
+            virtual ~Translate(void);
+
+            /**
+             * Renders the widget using a HIT template.
+             *
+             * @param  hit HIT template to use to render de widget.
+             * @return Rendered widget.
+             */
+            virtual string render(HIT&);
+    };
+
+}
+
+#endif