Created
January 13, 2024 02:13
-
-
Save MatheusRich/e3726647afa6b58678e057c961c4ebd4 to your computer and use it in GitHub Desktop.
Hacky ERB post-processor to Jekyll
This file contains 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
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