Created
September 2, 2020 02:06
-
-
Save jubishop/3a591ca28ab4e6091a44a091ca50c2bd to your computer and use it in GitHub Desktop.
Erb on Jekyll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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