Skip to content

carldaws/filepress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Filepress

Filepress is a minimal Rails plugin that offers the best of both worlds for content management:

  • Write and version control your content in Markdown (or a similar format)
  • Sync it seamlessly to ActiveRecord models so you can harness the full power of a Rails backend.

Ideal for blogs, documentation, or any content-driven Rails app where you want the flexibility of flat files and the structure of a database.

Getting Started

  1. Install the gem

Add it to your Gemfile:

gem "filepress"

Then run:

bundle install
  1. Create a model to represent your content

Be sure to include a field that can serve as a unique identifier (e.g. slug):

rails g model Post title:string slug:string body:text
  1. Enable Filepress for your model

Use the filepress method in your model class:

class Post < ApplicationRecord
    filepress
end
  1. Add some content

Create Markdown files in app/content/posts. Each file should include frontmatter:

---
title: My First Post
slug: first
---

# Hello, this is my first post
  1. Sync your content

Run the sync task to import your files into the database:

bin/rails filepress:sync

That’s it! You’re now free to query your content via ActiveRecord like any other model. Filepress doesn't dictate how you render the body—use a Markdown parser like Kramdown, Redcarpet, or similar.

How it works

Filepress reads your content files, extracts YAML frontmatter, and uses the values to populate or update model attributes. The rest of the file becomes the value of the body attribute (or another field, if configured).

Configuration

You can customize how Filepress behaves by passing options to filepress:

from: - Set a custom content directory

class Post
    filepress from: "app/my_custom_content_folder"
end

glob: - Use filetypes besides Markdown

class Post
    filepress glob: "*.html"
end

key: - Use a unique identifier other than slug

class Post
    filepress key: :name
end

body: - Set which attribute stores the main content

class Post
    filepress body: :content
end

destroy_stale: - Prevent deletion of records when files are removed

By default, Filepress deletes records when the corresponding file is removed. Disable this behavior with:

class Post
    filepress destroy_stale: false
end

Why Filepress?

Filepress is for you if:

  • You prefer writing content in files
  • You want the convenience of version control for content
  • And you still want powerful querying, associations, validations and all the other Rails goodness

About

Write content as flat files, use it anywhere in your Rails app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published