Reputation: 15075
I want to merge one HTML file into another. Not just include it, but merge.
master.html:
<!DOCTYPE html>
<html>
<head>
<title>My cat</title>
</head>
<body>
<h1>My cat is awesome!</h1>
</body>
</html>
_index.html:
<!DOCTYPE html>
<html>
<body>
<p><img src="cat.jpg"/></p>
</body>
</html>
Now I merge _index.html into master.html.
$ html_merge master.html _index.html > result.html
result.html
<!DOCTYPE html>
<html>
<head>
<title>My cat</title>
</head>
<body>
<h1>My cat is awesome!</h1>
<p><img src="cat.jpg"/></p>
</body>
</html>
html_merge
is a script what I'm looking for. I'll use it for building static websites.
I would like to use Ruby, but it's not required.
I don't want to reinvent yet another template language. There is a lot of template languages with include
/yield
statement and partials support. Liquid, mustache and so on. I use them for different tasks. Now I need to merge HTML files, nothing more.
Upvotes: 4
Views: 1321
Reputation: 107738
This looks remarkably like the layout / template relationship in Rails. While this may seem a little heavy handed, it will let you have a layout that you want content merged into:
application.html.erb
<html>
<head></head>
<body>
Some content before hand.
<%= yield %>
Some content "after hand"
</body>
</html>
index.html.erb
<strong>This is my cat: <%= image_tag "cat.jpg" %></strong>.
If you wish to have static pages served from this you can generate the cached versions of the page.
Upvotes: 0
Reputation: 362
Doing a merge like that requires knowledge about the content which to me sounds like you need to use a template system that is able to create static pages.
I've used http://www.cheetahtemplate.org/ on some projects, but it might be a bit of an overkill for your needs.
Upvotes: 0
Reputation: 57333
Think carefully about what such a script would look like, and specifically how you'd have to write the individual html files in order for them to be mergable. How would you associate nodes? by named divs? by insuring that each had parallel structure?
Upvotes: 0
Reputation: 13425
Could this help ? (It's in Java, though...)
http://www.javaworld.com/javaworld/jw-07-2007/jw-07-xmlmerge.html
Upvotes: 1