-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register custom renderers #10
Comments
Proposed syntaxA user could add custom renderers (or community-created renderers) from their require 'frontman-community-renderer' # Renderer from e.g. external package
require './lib/custom_renderer' # custom renderer in own project
Frontman::Config.set :custom_renderers, { comm: CommunityRenderer.instance, cust: CustomRenderer.instance } In def get_renderer(extension)
renderers = {
'erb': Frontman::ErbRenderer.instance,
'md': Frontman::MarkdownRenderer.instance,
'haml': Frontman::HamlRenderer.instance,
}.merge(Frontman::Config.get(:custom_renderers, fallback: {}))
renderers[extension.to_sym]
end |
How about we abstract away While writing this out I also noticed, theres likely a chance to improve performance via caching of the renderers hash Frontman::Config.set :custom_renderers, { comm: CommunityRenderer, cust: CustomRenderer }
def get_renderer(extension)
@renderers ||= begin
renderers = {
'erb': Frontman::ErbRenderer.instance,
'md': Frontman::MarkdownRenderer.instance,
'haml': Frontman::HamlRenderer.instance,
}.merge(Frontman::Config.get(:custom_renderers, fallback: {}))
custom_renderers = Frontman::Config.get(:custom_renderers, fallback: {})
custom_renderers.each do |k,v|
custom_renderers[k] = v.instance
end
renderers
end
@renderers[extension.to_sym]
end |
Great idea, let's try this out 😄 |
Description
Frontman supports HAML, ERB and Markdown out of the box. However, it could be nice to extend on this and give users the possibility to implement and add custom renderers, so that they can use even more templating languages.
Next steps
The text was updated successfully, but these errors were encountered: