--- /dev/null
+## vim: set noexpandtab tabstop=4 shiftwidth=4:
+##----------------------------------------------------------------------------
+## fast
+##----------------------------------------------------------------------------
+## This file is part of fast.
+##
+## fast is free software; you can redistribute it and/or modify it under the
+## terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 2 of the License, or (at your option) any later
+## version.
+##
+## fast is distributed in the hope that it will be useful, but WITHOUT ANY
+## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along
+## with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+## Place, Suite 330, Boston, MA 02111-1307 USA
+##----------------------------------------------------------------------------
+## Creado: sáb feb 7 17:22:25 ART 2004
+## Autores: Leandro Lucarella <luca@lugmen.org.ar>
+##----------------------------------------------------------------------------
+##
+## $Id: Makefile.am 247 2003-11-20 20:26:01Z luca $
+##
+
+SUBDIRS = src tests
+
--- /dev/null
+## vim: set noexpandtab tabstop=4 shiftwidth=4:
+##----------------------------------------------------------------------------
+## fast
+##----------------------------------------------------------------------------
+## This file is part of fast.
+##
+## fast is free software; you can redistribute it and/or modify it under the
+## terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 2 of the License, or (at your option) any later
+## version.
+##
+## fast is distributed in the hope that it will be useful, but WITHOUT ANY
+## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along
+## with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+## Place, Suite 330, Boston, MA 02111-1307 USA
+##----------------------------------------------------------------------------
+## Creado: sáb feb 7 17:22:50 ART 2004
+## Autores: Leandro Lucarella <luca@lugmen.org.ar>
+##----------------------------------------------------------------------------
+##
+## $Id: configure.in 450 2003-12-05 14:57:11Z luca $
+##
+
+AC_INIT(configure.in)
+AM_INIT_AUTOMAKE(fast, 0.1)
+AM_MAINTAINER_MODE
+
+dnl Prevents setting flags.
+CXXFLAGS=""
+
+AC_ISC_POSIX
+AC_PROG_CXX
+AM_PROG_CC_STDC
+AC_PROG_RANLIB
+AC_HEADER_STDC
+
+dnl Debugging turned on
+AC_MSG_CHECKING(for debugging)
+AC_ARG_ENABLE(debug,[ --enable-debug compile for debugging])
+AC_MSG_RESULT([$enable_debug])
+if test "x$enable_debug" = "xyes" ; then
+CXXFLAGS="${CXXFLAGS} -g -DDEBUG"
+fi
+
+## pkg_modules="libgnomeui-2.0"
+##PKG_CHECK_MODULES(PACKAGE,
+## libxml-2.0 >= 0.15.0 \
+## libxml++-1.0 >= 0.15.0 \
+## gthread-2.0 \
+## sigc++-1.2)
+
+AC_SUBST(PACKAGE_CFLAGS)
+AC_SUBST(PACKAGE_LIBS)
+
+AC_OUTPUT([
+Makefile
+src/Makefile
+tests/Makefile
+])
+
+echo
+echo "fast is now ready for compilation. Just run make."
+echo
+
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 20:04:43 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#ifndef FAST_BASIC_TEMPLATE_H
+#define FAST_BASIC_TEMPLATE_H
+
+//#include "fast/string.h"
+//#include "fast/string_map.h"
+//#include <map>
+#include <stack>
+
+namespace fast {
+
+/**
+ * bate - BAse Template Engine.
+ *
+ * bate is the base template engine implemented in faste.
+ */
+template < class F, class S, class M >
+class basic_template {
+
+ // Types.
+ public:
+ /// Cache traits type.
+ typedef F file_content_type;
+ /// String type.
+ typedef S string_type;
+ /// Map type.
+ typedef M< string_type, string_type > map_type;
+
+ // Attributes.
+ private:
+ /// Root directory where to search for templates.
+ string_type _root;
+ /// Postfix added to the blockname to convert it to a filename.
+ string_type _postfix;
+ /// Function object to get the contents of a "file".
+ file_content_type _file_content;
+ /// Group stack.
+ std::stack< string_type > _group;
+
+ // Methods.
+ protected:
+ /**
+ * Gets a filename based on the block.
+ *
+ * @param block Name of the block to get the filename.
+ *
+ * @return Block's filename.
+ */
+ string_type build_filename(const string_type& block) const
+ {
+ string_type group = _group.top();
+ if (group.length()) group += '/';
+ return _root + '/' + group + block + _postfix;
+ }
+
+ public:
+ /**
+ * Constructor.
+ *
+ * @param root Root directory from where to get the templates.
+ * @param postfix Postfix of the template files.
+ * @param group Starting group.
+ * @param file_content Function object to get the contents of a "file".
+ */
+ basic_template(const string_type& root = ".",
+ const string_type& postfix = ".tpl", const string_type& group = "",
+ const file_content_type& file_content = file_content_type())
+ : _root(root), _postfix(postfix), _file_content(file_content)
+ { _group.push(group); }
+
+ /// Gets templates root directory.
+ string_type root(void) const
+ { return _root; }
+
+ /// Sets templates root directory.
+ void root(const string_type& root)
+ { _root = root; }
+
+ /// Gets templates postfix.
+ string_type postfix(void) const
+ { return _postfix; }
+
+ /// Sets templates postfix.
+ void postfix(const string_type& postfix)
+ { _postfix = postfix; }
+
+ /**
+ * Gets the current working group.
+ *
+ * @return Current template's group.
+ */
+ string_type group(void) const
+ { return _group.top(); }
+
+ /**
+ * Starts working with a new group of templates.
+ *
+ * @param group Group of templates to work with.
+ */
+ void push_group(const string_type& group)
+ { _group.push(group); }
+
+ /**
+ * Stops working with a group of templates.
+ *
+ * @return Last template's group used.
+ */
+ string_type pop_group(void)
+ {
+ string_type group = _group.top();
+ _group.pop();
+ return group;
+ }
+
+ /**
+ * Parses a block replacing keys with values in the hash.
+ *
+ * @param block Name of the block to parse.
+ * @param vars Hash containing the variable names and their values.
+ *
+ * @return Parsed block with variables replaced.
+ */
+ string_type parse(const string_type& block, const map_type& vars) const
+ {
+ // TODO - el build_filename() debería ser parte de la política
+ // de reemplazo? o del file_contents?
+ // TODO: capturar excepción (pensar política para reportar errores)
+ string_type content = _file_content(build_filename(block));
+ for (map_type::const_iterator i = vars.begin();
+ i != vars.end(); ++i) {
+ // TODO - Parametrizar los 'separadores' y toda la política
+ // de search & replace en un template para hacerlo más
+ // flexible e implementar cosas como funciones de
+ // transformación, por ej. {upper(KEYWORD)}
+ string_type key = string("{") + i->first + "}";
+ string_type::size_type pos;
+ while ((pos = content.find(key)) != string_type::npos) {
+ content.replace(pos, key.length(), i->second);
+ }
+ }
+ return content;
+ }
+
+}; // class basic_template
+
+} // namespace fast
+
+#endif // FAST_BASIC_TEMPLATE_H
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 20:13:34 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#ifndef FAST_GET_FILE_CONTENT_H
+#define FAST_GET_FILE_CONTENT_H
+
+#include "fast/string.h"
+
+namespace fast {
+
+/**
+ * Gets file content.
+ *
+ * @param filename Name of the file to get the content.
+ * @return File content.
+ */
+class get_file_content {
+ public:
+ string operator()(const string&) const;
+};
+
+} // namespace fast
+
+#endif // FAST_GET_FILE_CONTENT_H
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 20:04:43 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#ifndef FAST_GET_FILE_CONTENT_CACHED_H
+#define FAST_GET_FILE_CONTENT_CACHED_H
+
+#include "fast/string.h"
+#include "fast/string_map.h"
+#include "fast/get_file_content.h"
+
+namespace fast {
+
+/**
+ * Gets file content from a cache.
+ *
+ * @param filename Name of the file to get the content.
+ * @return File content.
+ */
+class get_file_content_cached {
+ private:
+ mutable string_map _cache;
+ public:
+ string operator()(const string&) const;
+};
+
+} // namespace fast
+
+#endif // FAST_GET_FILE_CONTENT_CACHED_H
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 22:21:00 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+
+#ifndef FAST_STRING_H
+#define FAST_STRING_H
+
+#include <string>
+
+namespace fast {
+
+/// String.
+typedef std::string string;
+
+} // namespace fast
+
+#endif // FAST_STRING_H
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 22:23:59 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#ifndef FAST_STRING_MAP_H
+#define FAST_STRING_MAP_H
+
+#include "fast/string.h"
+#include <map>
+
+namespace fast {
+
+/// String map used to describe a set of variables.
+typedef std::map< string, string > string_map;
+
+} // namespace fast
+
+#endif // FAST_STRING_MAP_H
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 23:19:07 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+//{{{ include
+#include "fast/get_file_content.h"
+#include <fstream>
+#include <sstream>
+#include <stdexcept>
+//}}}
+
+//{{{ get_file_content
+fast::string fast::get_file_content::operator()(const string& filename) const
+{
+ std::ifstream in(filename.c_str());
+ // TODO - Verificar apertura.
+ // - Tirar excepción si pasa algo (21.3.6 Stroustrup).
+ if (!in) {
+ throw std::runtime_error(filename);
+ }
+ std::stringstream out;
+ out << in.rdbuf();
+ return out.str();
+}
+//}}} get_file_content
+
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
+//----------------------------------------------------------------------------
+// fast
+//----------------------------------------------------------------------------
+// This file is part of fast.
+//
+// fast is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// fast is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with fast; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb feb 7 20:04:43 ART 2004
+// Autores: Leandro Lucarella <luca@lugmen.org.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+//{{{ include
+#include "fast/get_file_content_cached.h"
+#include "fast/get_file_content.h"
+//}}}
+
+//{{{ get_file_content_cached
+fast::string fast::get_file_content_cached::operator()(const string& filename)
+ const
+{
+ string_map::const_iterator c = _cache.find(filename);
+ if (c == _cache.end()) { // Not found.
+ // Get file contents using regular function object.
+ get_file_content file;
+ _cache[filename] = file(filename);
+ return _cache[filename];
+ } else {
+ return c->second;
+ }
+}
+//}}} get_file_content_cached
+
--- /dev/null
+CXXFLAGS=-Wall -g -I../include #-DDEBUG
+
+bate: fast.cpp ../src/get_file_content.cpp ../include/fast/basic_template.h
+ $(CXX) $(CXXFLAGS) -o fast fast.cpp ../src/get_file_content.cpp
--- /dev/null
+// vim: set expandtab tabstop=4 shiftwidth=4:
+
+#include "fast/basic_template.h"
+#include "fast/get_file_content.h"
+#include <iostream>
+#include <exception>
+#include <string>
+#include <map>
+
+int main(int argc, char* argv[]) {
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ if (argc < 3) {
+ std::cerr << "Argument missing." << std::endl;
+ return 1;
+ } else if (!(argc % 2)) { // is even
+ std::cerr << "Malformed arguments." << std::endl;
+ return 2;
+ }
+ fast::basic_template< fast::get_file_content, std::string, std::map > tpl(argv[1]);
+ std::string block = argv[2];
+ fast::map_type vars;
+ for (int i = 3; i < argc; ++i) {
+ vars[argv[i]] = argv[++i];
+ }
+ std::cout << tpl.parse(block, vars);
+ return 0;
+}
+
--- /dev/null
+Hola, me llamo {NOMBRE} y soy un {CLASE}.
+
+El que lee es {ALGO}.