// HTMLWriter.cpp
// object for opening and writing an HTMLWriter

#include "htmlwriter.h"

// Constructor - initializes outfile
HTMLWriter::HTMLWriter() : outfile(ios::out) {
	//cout << "\nHTMLWriter called";
}

// opens outfile
int HTMLWriter::open( string name) {
		//cout << "\nOpening |" << name.c_str() << "|";
		outfile.close();
		outfile.open(name.c_str(), ios::out);
		if (!outfile) cout << "\nError! Unable to open " << name;
}

// closes outfile
void HTMLWriter::close() {
		outfile.close();
}

// writes header, accepting title and misc. js or css code.  
void HTMLWriter::header(string title, string javaScript) {
		outfile << "<HTML>\n<HEAD>\n<TITLE>" << title << "</TITLE>\n" << javaScript << "\n</HEAD>\n<BODY>\n<H1>";
		outfile << title << "</H1><HR>\n";
}

// writes appropriate ending HTML tags and info
void HTMLWriter::footer() {
		outfile <<"\n</BODY>\n</HTML>\n";
}

// writes a link to the outfile, accepting the link description, and the link location
void HTMLWriter::link(string description, string URL) {
		outfile << "<A HREF='" << URL << "'>" << description << "</A>\n";
}

// writes a paragraph of body text
void HTMLWriter::bodyText(string text) {
		outfile << "<P>" << text << "</P>\n";
}

// writes a divider for paragraphs
void HTMLWriter::divider() {
		outfile << "\n<HR>\n";
}

// writes a divider for an inline list
void HTMLWriter::divideList() {
		outfile << " | ";
}
