Update the render helper to process ERB before sending content to kramdown:
module ApplicationHelper
def render_content_from(page)
erb_processed_content = render(inline: page.content, layout: false)
Kramdown::Document.new(erb_processed_content, input: "GFM").to_html.html_safe
end
end
Use Ruby directly in markdown files:
...
<%- Page.all.select(&:position).sort_by(&:position).each do |page| %>
- <%= link_to page.title, page.slug %>
<%- end %>
...
To display:
Create more helpers for use in page content files:
module PagesHelper
def link_to_page(slug, html_options = nil)
link_to Page.find(slug).title, page_path(slug), html_options
end
def pages_image_tag(path)
image_tag "pages/#{@page.slug}/#{path}"
end
end
The pages_image_tag
helper requires that we add the content folder to Propshaft’s assets paths:
...
module RailsStatic
class Application < Rails::Application
...
config.assets.paths << Rails.root.join("content")
end
end
Commit: ERB