Skip to content

Instantly share code, notes, and snippets.

@MatheusRich
Created January 13, 2024 02:13
Show Gist options
  • Save MatheusRich/e3726647afa6b58678e057c961c4ebd4 to your computer and use it in GitHub Desktop.
Save MatheusRich/e3726647afa6b58678e057c961c4ebd4 to your computer and use it in GitHub Desktop.
Hacky ERB post-processor to Jekyll
module EmbeddedRuby
module ErbRenderer
class Context
def initialize(variables)
variables.each do |key, value|
instance_variable_set(:"@#{key}", value)
self.class.attr_reader key
end
end
def get_binding
binding
end
end
def self.render(content, variables)
context_binding = Context.new(variables).get_binding
ERB.new(content).result(context_binding)
end
end
def render_liquid(content, payload, info, path = nil)
content = super(content, payload, info, path)
return content if !content.include?("<%")
ErbRenderer.render(content, payload)
end
end
Jekyll::Renderer.class_eval do
prepend EmbeddedRuby
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment