I’d like to manipulate page content during the build process, like, for example, doing a find-and-replace, substituting the word “foo” with the word “bar” wherever it appears on the page.
I think I can do this by making an extension (which uses manipulate_resource_list
) and activate the extension in config.rb
during the configure :build do
block.
I can read the page content with render()
but I can’t figure out how to write to the page. Here’s my attempt thus far…
def manipulate_resource_list(resources)
# Replace the word "foo" with "bar" in all resources.
resources.each do |resource|
# This does nothing because I cannot write to the resource.
resource.render({:layout => false}).gsub!("foo", "bar")
end
end
Does anyone know if I’m heading in the right direction? What am I missing?