Skip to content

A dependency-free frontmatter-aware framework-agnostic wrapper around a directory of static content.

License

Notifications You must be signed in to change notification settings

benpickles/decant

Repository files navigation

Decant

Ruby

A dependency-free frontmatter-aware framework-agnostic wrapper around a directory of static content.

Installation

Add Decant to your application's Gemfile and run bundle install.

gem 'decant'

Usage

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 .finding 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!!!"

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Decant project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

A dependency-free frontmatter-aware framework-agnostic wrapper around a directory of static content.

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages