Hi Guys,
I usually use relative assets, but to create an amazon S3 error.html I need one page to use absolute assets. Unfortunately middleman does not offer this functionality by default. I managed to modify asset_url() of the relative_assets helper like this:
def asset_url(path, prefix='')
path = super(path, prefix)
forceAbsolute = false
if(current_page.data["forceAbsolute"] != nil)
forceAbsolute = current_page.data.forceAbsolute
end
if path.include?('//') || path.start_with?('data:') || !current_resource || forceAbsolute
path
else
current_dir = Pathname('/' + current_resource.destination_path)
Pathname(path).relative_path_from(current_dir.dirname).to_s
end
end
end
This way I can add the forceAbsolute: true frontmatter to a page and only this page will use absolute assets.
This works well, but I really don’t want to modify the default extensions. I would much rather create a helper in my config.rb and use that to overwrite asset_url().
I want to check whether forceAbsolute is set in a page and if it is, I want to call Middleman::CoreExtensions::DefaultHelpers.asset_url(), which would skip relative_asset’s asset_url.
Unfortunately I cannot figure out how to call a method of a specific module. I am very new to Ruby, so I would really appreciate it if someone could point me into the right direction.
Greetings, Kim