Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created June 10, 2013 21:02
Show Gist options
  • Select an option

  • Save miketheman/5752267 to your computer and use it in GitHub Desktop.

Select an option

Save miketheman/5752267 to your computer and use it in GitHub Desktop.
erb relative inclusion
$ erubis outer-template.erb
bash -x -c '
echo $(date +%s) > /tmp/test-templates
echo "this is an outer template" >> /tmp/test-templates
'
bash -x -c '
echo "This is an inner template" >> /tmp/test-templates
echo "Some inner ruby: 25"
'
bash -x -c '
echo "This is an inner template" >> /tmp/test-templates
echo "Some inner template ruby math results: <%= 5 * 5 %>"
'
bash -x -c '
echo $(date +%s) > /tmp/test-templates
echo "this is an outer template" >> /tmp/test-templates
'
<%
def import(fname)
eruby = Erubis::Eruby.new
here = Pathname.new(__FILE__).dirname.realpath
input = File.read(File.join(here, fname))
src = eruby.convert(input)
eval src
end
-%>
<%= import('inner-template.erb') %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment