In this coding exercise we’ll examine how to leverage the Ruby Here Doc syntax to generate HTML with dynamic content.
Summary
Build a program that dynamically generates the HTML boilerplate code and dynamically integrate a custom title.
Exercise File
Exercise Description
Given the following strings:
'My Site'
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.
Sample Output
<!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.
Solution
Can be found on the solutions branch on github.