<commit_before>/***************************************************************************
*   Copyright (C) 2006 by                                                 *
*   <NAME> (<EMAIL>)                                  *
*                                                                         *
*   This program 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.                                   *
***************************************************************************/

#include "htmlbookexporter.h"

#include <qfile.h>

#include <kdebug.h>

#include "backends/recipedb.h"

HTMLBookExporter::HTMLBookExporter( RecipeDB *db, const QString& basedir, const QString &format ) :
		HTMLExporter( db, basedir+"/index", format ), database( db ), m_basedir(basedir)
{
}

HTMLBookExporter::~HTMLBookExporter()
{
	QMap<QString,QTextStream*>::const_iterator it;
	for ( it = fileMap.begin(); it != fileMap.end(); ++it ) {
		(*it)->device()->close();

		//does it matter the order of deletion here?
		QIODevice *file = (*it)->device();
		delete *it;
		delete file;
	}
}

int HTMLBookExporter::headerFlags() const
{
	return RecipeDB::Categories | RecipeDB::Title;
}

QString HTMLBookExporter::createContent( const RecipeList& recipes )
{
	RecipeList::const_iterator recipe_it;
	for ( recipe_it = recipes.begin(); recipe_it != recipes.end(); ++recipe_it ) {
		for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
			QMap<QString,QTextStream*>::iterator stream_it = fileMap.find( (*cat_it).name );
			(**stream_it) << QString("<a name=\""+(*recipe_it).title+"\">");
			(**stream_it) << HTMLExporter::createContent(*recipe_it);
			(**stream_it) << QString("[ <a href=\"#top\">Top</a> ]");
			(**stream_it) << QString("[ <a href=\"index.html\">Back</a> ]");
		}
	}

	return QString::null;
}

QString HTMLBookExporter::createHeader( const RecipeList &list )
{
	QString output = HTMLExporter::createHeader(list);
	QStringList catLinks;

	RecipeList::const_iterator recipe_it;
	for ( recipe_it = list.begin(); recipe_it != list.end(); ++recipe_it ) {
		for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
			QMap<QString,QTextStream*>::iterator stream_it = fileMap.find( (*cat_it).name );
			if ( stream_it == fileMap.end() ) {
				QString catPageName = m_basedir+"/"+escape((*cat_it).name)+".html";
				QFile *catPage = new QFile( catPageName );
				catPage->open( IO_WriteOnly );
				QTextStream *stream = new QTextStream( catPage );
				stream->setEncoding( QTextStream::UnicodeUTF8 );
				(*stream) << HTMLExporter::createHeader(list);
				(*stream) << "<h1>"<<(*cat_it).name<<"</h1>";

				catLinks << QString("<a href=\"" + catPageName + "\">" + (*cat_it).name + "</a>");

				stream_it = fileMap.insert((*cat_it).name,stream);
			}
			(**stream_it) << QString("[ <a href=\"#" + (*recipe_it).title + "\">" + (*recipe_it).title + "</a> ]");
		}
	}

	return output+"<h1>Krecipes Recipes</h1><div><ul><li>"+catLinks.join("</li><li>")+"</li></ul></div>";
}

QString HTMLBookExporter::createFooter()
{
	QString output = HTMLExporter::createFooter();

	return output;
}<commit_msg>Put the closing </body></html> on the multi-page export<commit_after>/***************************************************************************
*   Copyright (C) 2006 by                                                 *
*   <NAME> (<EMAIL>)                                  *
*                                                                         *
*   This program 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.                                   *
***************************************************************************/

#include "htmlbookexporter.h"

#include <qfile.h>

#include <kdebug.h>

#include "backends/recipedb.h"

HTMLBookExporter::HTMLBookExporter( RecipeDB *db, const QString& basedir, const QString &format ) :
		HTMLExporter( db, basedir+"/index", format ), database( db ), m_basedir(basedir)
{
}

HTMLBookExporter::~HTMLBookExporter()
{
}

int HTMLBookExporter::headerFlags() const
{
	return RecipeDB::Categories | RecipeDB::Title;
}

QString HTMLBookExporter::createContent( const RecipeList& recipes )
{
	RecipeList::const_iterator recipe_it;
	for ( recipe_it = recipes.begin(); recipe_it != recipes.end(); ++recipe_it ) {
		for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
			QMap<QString,QTextStream*>::iterator stream_it = fileMap.find( (*cat_it).name );
			(**stream_it) << QString("<a name=\""+(*recipe_it).title+"\">");
			(**stream_it) << HTMLExporter::createContent(*recipe_it);
			(**stream_it) << QString("[ <a href=\"#top\">Top</a> ]");
			(**stream_it) << QString("[ <a href=\"index.html\">Back</a> ]");
		}
	}

	return QString::null;
}

QString HTMLBookExporter::createHeader( const RecipeList &list )
{
	QString output = HTMLExporter::createHeader(list);
	QStringList catLinks;

	RecipeList::const_iterator recipe_it;
	for ( recipe_it = list.begin(); recipe_it != list.end(); ++recipe_it ) {
		for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
			QMap<QString,QTextStream*>::iterator stream_it = fileMap.find( (*cat_it).name );
			if ( stream_it == fileMap.end() ) {
				QString catPageName = m_basedir+"/"+escape((*cat_it).name)+".html";
				QFile *catPage = new QFile( catPageName );
				catPage->open( IO_WriteOnly );
				QTextStream *stream = new QTextStream( catPage );
				stream->setEncoding( QTextStream::UnicodeUTF8 );
				(*stream) << HTMLExporter::createHeader(list);
				(*stream) << "<h1>"<<(*cat_it).name<<"</h1>";

				catLinks << QString("<a href=\"" + catPageName + "\">" + (*cat_it).name + "</a>");

				stream_it = fileMap.insert((*cat_it).name,stream);
			}
			(**stream_it) << QString("[ <a href=\"#" + (*recipe_it).title + "\">" + (*recipe_it).title + "</a> ]");
		}
	}

	return output+"<h1>Krecipes Recipes</h1><div><ul><li>"+catLinks.join("</li><li>")+"</li></ul></div>";
}

QString HTMLBookExporter::createFooter()
{
	QMap<QString,QTextStream*>::const_iterator it;
	for ( it = fileMap.begin(); it != fileMap.end(); ++it ) {
		(**it) << HTMLExporter::createFooter();

		(*it)->device()->close();

		//does it matter the order of deletion here?
		QIODevice *file = (*it)->device();
		delete *it;
		delete file;
	}

	QString output = HTMLExporter::createFooter();
	return output;
}
{'fraction_non_alphanumeric': 0.21581288563638973, 'fraction_numerical': 0.0028698522026115655, 'mean_word_length': 3.7772446881425634, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6796148', 'n_tokens_mistral': 2375, 'n_tokens_neox': 2208, 'n_words': 457}