In this coding exercise we’ll examine how to leverage the Ruby Here Doc syntax to generate HTML with dynamic content.
Build a program that dynamically generates the HTML boilerplate code and dynamically integrate a custom title.
Given the following strings:
and the HTML boilerplate code:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Title Placeholder</title> </head> <body> </body> </html>
Write a program that generates the full HTML boilerplate code with the title integrated.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My Site</title> </head> <body> </body> </html>
Real World Usage
This is a common process you will utilize whenever working with multi-line strings. Specifically, this is something you’re likely to come across when you need to generate HTML code if you’re working with web applications.
Can be found on the solutions branch on github.