[Powertop] [PATCH v3 03/31] html-report: add title and div tags

Alexandra Yates <alexandra.yates at linux.intel.com>
Newsgroups dev.linux.lists.powertop
Message-ID <1384806442-20294-4-git-send-email-alexandra.yates@linux.intel.com>
Implements add_title and add_div methods that pass css attributes for
modular styling.

Signed-off-by: Alexandra Yates <alexandra.yates(a)linux.intel.com>
---
 src/report/report-data-html.h        |    4 ++++
 src/report/report-formatter-html.cpp |   35 ++++++++++++++++++++++++++++++++++
 src/report/report-formatter-html.h   |    5 ++++-
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 src/report/report-data-html.h

diff --git a/src/report/report-data-html.h b/src/report/report-data-html.h
new file mode 100644
index 0000000..70ccbdb
--- /dev/null
+++ b/src/report/report-data-html.h
@@ -0,0 +1,4 @@
+struct tag_attr {
+	const char *css_class;
+	const char *css_id;
+};
diff --git a/src/report/report-formatter-html.cpp b/src/report/report-formatter-html.cpp
index 79a0c35..2e59725 100644
--- a/src/report/report-formatter-html.cpp
+++ b/src/report/report-formatter-html.cpp
@@ -464,6 +464,8 @@ report_formatter_html::set_cpu_number(int nr)
 	cpu_nr = nr;
 }
 
+
+/* Report Style */
 void
 report_formatter_html::add_logo()
 {
@@ -481,3 +483,36 @@ report_formatter_html::end_hheader()
 {
 	add_exact("</header>\n\n");
 }
+
+void
+report_formatter_html::add_div(struct tag_attr * div_attr)
+{
+	std::string empty="";
+	std::string tmp_str;
+
+	if (div_attr->css_class == empty && div_attr->css_id == empty)
+		add_exact("<div>\n");
+
+	else if (div_attr->css_class == empty && div_attr->css_id != empty)
+		addf_exact("<div id=\"%s\">\n", div_attr->css_id);
+
+	else if (div_attr->css_class != empty && div_attr->css_id == empty)
+		addf_exact("<div class=\"%s\">\n", div_attr->css_class);
+
+	else if (div_attr->css_class != empty && div_attr->css_id != empty)
+		addf_exact("<div class=\"%s\" id=\"%s\">\n",
+				div_attr->css_class, div_attr->css_id);
+}
+
+void
+report_formatter_html::end_div()
+{
+	add_exact("</div>\n");
+}
+
+void
+report_formatter_html::add_title(struct tag_attr *title_att, const char *title)
+{
+	addf_exact("<h2 class=\"%s\"> %s </h2>\n", title_att->css_class, title);
+}
+
diff --git a/src/report/report-formatter-html.h b/src/report/report-formatter-html.h
index 1ade760..0f508d3 100644
--- a/src/report/report-formatter-html.h
+++ b/src/report/report-formatter-html.h
@@ -29,7 +29,7 @@
 #include <string>
 
 #include "report-formatter-base.h"
-
+#include "report-data-html.h"
 /* Whether to replace " and ' in HTML by &quot; and &apos; respectively */
 /*#define REPORT_HTML_ESCAPE_QUOTES*/
 
@@ -86,6 +86,9 @@ public:
 	void add_logo();
 	void add_header();
 	void end_hheader();
+	void add_div(struct tag_attr *div_attr);
+	void end_div();
+	void add_title(struct tag_attr *title_att, const char *title);
 
 private:
 	/* Document structure related functions */
-- 
1.7.9.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.