Using ruby (not rails), I’m trying to figure out how to replace (not append) a certain block in a static file with a string. For example, in static_file.html I want to replace everything between the html comments “start” and “end”:
<p>lorem ipsum blah blah ipsum</p>
<!--start-->
REPLACE MULTI-LINE
CONTENT HERE...
<!--end-->
<p>other stuff still here...</p>
Some of the answers here are helpful for inserting text at a certain spot, but does not handle between.
Here’s a function to handle it for you. Just pass it a file path and the contents to replace in between those HTML comment blocks:
As long as your comment blocks are always formatted the same: <–start–> and <!–end–>, this will work.