Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created September 2, 2020 02:06
Show Gist options
  • Save jubishop/3a591ca28ab4e6091a44a091ca50c2bd to your computer and use it in GitHub Desktop.
Save jubishop/3a591ca28ab4e6091a44a091ca50c2bd to your computer and use it in GitHub Desktop.
Erb on Jekyll
require 'erb'
require 'recursive-open-struct'
module EmbeddedRuby
def render_liquid(content, payload, info, path = nil)
liquid = super(content, payload, info, path)
site = RecursiveOpenStruct.new(payload.site.to_h,
recurse_over_arrays: true)
page = RecursiveOpenStruct.new(payload.page,
recurse_over_arrays: true)
layout = RecursiveOpenStruct.new(payload.layout,
recurse_over_arrays: true)
content = payload.content
paginator = RecursiveOpenStruct.new(payload.paginator,
recurse_over_arrays: true)
return ERB.new(liquid).result(binding)
end
end
module Jekyll
class Renderer
prepend EmbeddedRuby
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment