Decant is a dependency-free frontmatter-aware framework-agnostic wrapper around a directory of static content (probably Markdown).
kramdown (sic, not Kramdown or KramDown, just kramdown) is a free MIT-licensed Ruby library for parsing and converting a superset of Markdown.
Use Decant and kramdown to parse static markdown content files through Rails’ router, controller, model and view.
...
gem "decant"
gem "kramdown"
gem "kramdown-parser-gfm"
...
bundle
Page = Decant.define(dir: "content/pages", ext: "md") do
# Declare frontmatter convenience readers.
frontmatter :title
# Add custom methods - it's a standard Ruby class.
def shouty
"#{title.upcase}!!!"
end
end
module ApplicationHelper
def render_content_from(page)
Kramdown::Document.new(page.content, input: "GFM").to_html.html_safe
end
end
class PagesController < ApplicationController
def show
@page = Page.find(params[:slug])
end
end
<%= render_content_from @page %>
Rails.application.routes.draw do
...
root "pages#show", slug: "index"
get "/*slug", to: "pages#show", as: :page
end
# Rails Static
dev
Visit localhost:3000 to see the first static page.
To add a new web page, just create the corresponding markdown file in content/pages/
folder. Pages can be nested in sub folders.
Commit: Decant and Kramdown