MCPcopy Create free account
hub / github.com/Tracktion/choc / demonstrateHTMLGeneration

Function demonstrateHTMLGeneration

examples/text_processing.cpp:192–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192void demonstrateHTMLGeneration()
193{
194 std::cout << "\n=== HTML Generation Demo ===\n";
195
196 // Create an HTML document
197 choc::html::HTMLElement doc ("html");
198
199 // Add head section
200 auto& head = doc.addChild ("head");
201 head.addChild ("title").addContent ("Employee Report");
202 head.addChild ("meta").setProperty ("charset", "UTF-8");
203
204 // Add some CSS
205 auto& style = head.addChild ("style");
206 style.addRawContent (R"(
207 body { font-family: Arial, sans-serif; margin: 20px; }
208 table { border-collapse: collapse; width: 100%; margin: 20px 0; }
209 th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
210 th { background-color: #f2f2f2; font-weight: bold; }
211 .header { color: #333; border-bottom: 2px solid #4CAF50; }
212 .summary { background-color: #f9f9f9; padding: 15px; border-radius: 5px; }
213 .highlight { background-color: #ffffcc; }
214 )");
215
216 // Add body section
217 auto& body = doc.addChild ("body");
218
219 // Add header
220 body.addChild ("h1").setClass ("header").addContent ("Company Employee Report");
221 body.addChild ("p").addContent ("Generated on " + std::string (__DATE__) + " at " + std::string (__TIME__));
222
223 // Add employee table
224 body.addChild ("h2").addContent ("Employee Directory");
225 auto& table = body.addChild ("table");
226
227 // Table header
228 auto& thead = table.addChild ("thead");
229 auto& headerRow = thead.addChild ("tr");
230 headerRow.addChild ("th").addContent ("Name");
231 headerRow.addChild ("th").addContent ("Department");
232 headerRow.addChild ("th").addContent ("Age");
233 headerRow.addChild ("th").addContent ("Salary");
234 headerRow.addChild ("th").addContent ("Email");
235
236 // Table body
237 auto& tbody = table.addChild ("tbody");
238
239 std::vector<Employee> employees = {
240 {"Alice Johnson", "Engineering", 28, 75000.0, "alice@company.com"},
241 {"Bob Smith", "Marketing", 35, 65000.0, "bob@company.com"},
242 {"Carol Williams", "Engineering", 31, 82000.0, "carol@company.com"},
243 {"David Brown", "Sales", 29, 58000.0, "david@company.com"},
244 {"Eve Davis", "HR", 42, 70000.0, "eve@company.com"}
245 };
246
247 for (const auto& emp : employees)
248 {
249 auto& row = tbody.addChild ("tr");

Callers 1

mainFunction · 0.85

Calls 4

floatToStringFunction · 0.85
toDocumentMethod · 0.80
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected