A dependency-free frontmatter-aware framework-agnostic wrapper around a directory of static content.
Add Decant to your application's Gemfile and run bundle install
.
gem 'decant'
Define a Decant class pointing to a directory of files and add your own methods.
Page = Decant.define(dir: '_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
Given a file _pages/about.md
with the following contents:
---
title: About
stuff: nonsense
---
# About
More words.
You can fetch a Page
instance by .find
ing it by its extension-less path within the directory.
about = Page.find('about')
about.content # => "# About\n\nMore words.\n"
about.frontmatter # => {:title=>"About", :stuff=>"nonsense"}
about.title # => "About"
about.shouty # => "ABOUT!!!"
Bug reports and pull requests are welcome on GitHub at https://github.com/benpickles/decant. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Decant project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.