Static Markdown pages with YAML frontmatter and inline Erb, embedded in your Rails app.
As simple as, …
app/views/pages/exorcism_tips.html.md
:
---
title: 3 tips for the PERFECT exorcism
author: Beelzebub
tags:
- listicles
- devil worship
- activity ideas
---
By <%= data.author %>.
Through trial and error, I've found that the perfect exorcism
starts with a refreshing drink.
Tagged <%= render "tag_list", tags: data.tags %>:
## Devilishly good lemonade recipe
…
Usage
In app/views/layouts/pages.html.erb
:
<%= render_layout "application" do %>
<h1><%= data.title %></h1>
<article>
<%= yield %>
</article>
<% end %>
Frontmatter is supplied as a struct like object.
Given this frontmatter:
---
author: Beelzebub
---
Use !
and ?
method helpers for added strictness.
data.author # => "Beelzebub"
data.author! # => "Beelzebub"
data.author? # => true
data.title # => nil
data.title! # => raises SatanicPages::Frontmatter::MissingAttributeError
data.title? # => false
Installation
Add this line to your application's Gemfile:
$ bundle add satanic_pages
$ bundle install
Add the Concern to a regular controller:
class PagesController < ApplicationController
include SatanicPages::Controller
end
And set up a wildcard route:
get("*page", to: "pages#show", as: :page, constraints: PagesController.constraint)