filepress 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +114 -9
- data/Rakefile +1 -11
- data/lib/filepress/model.rb +15 -0
- data/lib/filepress/railtie.rb +11 -0
- data/lib/filepress/version.rb +1 -3
- data/lib/filepress.rb +27 -64
- data/lib/tasks/filepress_tasks.rake +6 -0
- metadata +8 -7
- data/.rubocop.yml +0 -8
- data/LICENSE.txt +0 -21
- data/sig/filepress.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d19a795578233e2969fa1438a21c7614afab2650666a2a229338c2f322cccc0
|
4
|
+
data.tar.gz: cfcfbff322ea8909a384f580b6de6082f4a015808acb6d5e3f03a5bc02d17d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69c6dbb2a9491da1698d9d97ba37ebb4e3e6caceffa1b0d4e7c21d782c0d5d4111869c075fcddb339dd0df471db291a9f43f197cd11dbb9871042b013b5f14c
|
7
|
+
data.tar.gz: 9590840f2f26567dca12b04fc929c2273a5f21074b179abdf7fb0f96dc22de5720a9d2bb37c8eede06c516ebb7bfcf7b1c8e0ae7eacc6192b782a5a3c9406a4e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Carl Dawson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,17 +1,122 @@
|
|
1
1
|
# Filepress
|
2
2
|
|
3
|
-
|
3
|
+
Filepress is a minimal Rails plugin that offers the best of both worlds for content management:
|
4
|
+
- Write and version control your content in Markdown (or a similar format)
|
5
|
+
- Sync it seamlessly to ActiveRecord models so you can harness the full power of a Rails backend.
|
4
6
|
|
5
|
-
|
7
|
+
Ideal for blogs, documentation, or any content-driven Rails app where you want the flexibility of flat files and the structure of a database.
|
6
8
|
|
7
|
-
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
1. Install the gem
|
12
|
+
|
13
|
+
Add it to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "filepress"
|
17
|
+
```
|
18
|
+
Then run:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
2. Create a model to represent your content
|
25
|
+
|
26
|
+
Be sure to include a field that can serve as a unique identifier (e.g. `slug`):
|
27
|
+
|
28
|
+
```bash
|
29
|
+
rails g model Post title:string slug:string body:text
|
30
|
+
```
|
31
|
+
|
32
|
+
3. Enable Filepress for your model
|
8
33
|
|
9
|
-
|
34
|
+
Use the `filepress` method in your model class:
|
10
35
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
36
|
+
```ruby
|
37
|
+
class Post < ApplicationRecord
|
38
|
+
filepress
|
39
|
+
end
|
40
|
+
```
|
16
41
|
|
42
|
+
4. Add some content
|
43
|
+
|
44
|
+
Create Markdown files in `app/content/posts`. Each file should include frontmatter:
|
45
|
+
|
46
|
+
```markdown
|
47
|
+
---
|
48
|
+
title: My First Post
|
49
|
+
slug: first
|
17
50
|
---
|
51
|
+
|
52
|
+
# Hello, this is my first post
|
53
|
+
```
|
54
|
+
|
55
|
+
5. Sync your content
|
56
|
+
|
57
|
+
Run the sync task to import your files into the database:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
bin/rails filepress:sync
|
61
|
+
```
|
62
|
+
|
63
|
+
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.
|
64
|
+
|
65
|
+
## How it works
|
66
|
+
|
67
|
+
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).
|
68
|
+
|
69
|
+
## Configuration
|
70
|
+
|
71
|
+
You can customize how Filepress behaves by passing options to `filepress`:
|
72
|
+
|
73
|
+
### `from:` - Set a custom content directory
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class Post
|
77
|
+
filepress from: "app/my_custom_content_folder"
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
### `glob:` - Use filetypes besides Markdown
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class Post
|
85
|
+
filepress glob: "*.html"
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
### `key:` - Use a unique identifier other than `slug`
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
class Post
|
93
|
+
filepress key: :name
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
### `body:` - Set which attribute stores the main content
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
class Post
|
101
|
+
filepress body: :content
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
### `destroy_stale:` - Prevent deletion of records when files are removed
|
106
|
+
|
107
|
+
By default, Filepress deletes records when the corresponding file is removed. Disable this behavior with:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
class Post
|
111
|
+
filepress destroy_stale: false
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
## Why Filepress?
|
116
|
+
|
117
|
+
Filepress is for you if:
|
118
|
+
|
119
|
+
- You prefer writing content in files
|
120
|
+
- You want the convenience of version control for content
|
121
|
+
- And you still want powerful querying, associations, validations and all the other Rails goodness
|
122
|
+
|
data/Rakefile
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Filepress
|
2
|
+
module Model
|
3
|
+
def filepress(from: nil, glob: "*.md", key: :slug, body: :body, destroy_stale: true)
|
4
|
+
class_attribute :filepress_options, instance_accessor: false, default: {}
|
5
|
+
|
6
|
+
self.filepress_options = {
|
7
|
+
from: from || "app/content/#{name.underscore.pluralize}",
|
8
|
+
glob: glob,
|
9
|
+
key: key,
|
10
|
+
body: body,
|
11
|
+
destroy_stale: destroy_stale
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/filepress/version.rb
CHANGED
data/lib/filepress.rb
CHANGED
@@ -1,77 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "
|
4
|
-
require "active_support/core_ext"
|
5
|
-
require "active_support/concern"
|
6
|
-
|
7
|
-
require_relative "filepress/version"
|
1
|
+
require "filepress/version"
|
2
|
+
require "filepress/railtie"
|
3
|
+
require "filepress/model"
|
8
4
|
|
9
5
|
module Filepress
|
10
|
-
class
|
11
|
-
def
|
12
|
-
|
13
|
-
|
6
|
+
class << self
|
7
|
+
def sync
|
8
|
+
Rails.application.eager_load!
|
9
|
+
models = ActiveRecord::Base.descendants.select { |model| model.respond_to? :filepress_options }
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
models.each do |model|
|
12
|
+
options = model.filepress_options
|
13
|
+
raise "Filepress options missing for #{model.name}" unless options
|
18
14
|
|
19
|
-
|
15
|
+
path = Rails.root.join(options[:from])
|
16
|
+
key = options[:key]
|
17
|
+
body_attribute = options[:body]
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
keys = Dir.glob("#{path}/#{options[:glob]}").map do |file|
|
20
|
+
raw = File.read(file)
|
21
|
+
frontmatter, body = raw.split(/^---\s*$/, 3).reject(&:empty?)
|
22
|
+
data = YAML.safe_load(frontmatter, symbolize_names: true)
|
23
|
+
content = body.strip
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
identifier = data[key]
|
26
|
+
raise "Missing key `#{key}` in frontmatter for #{file}" unless identifier
|
29
27
|
|
30
|
-
|
28
|
+
record = model.find_or_initialize_by(key => identifier)
|
29
|
+
record.assign_attributes(data)
|
30
|
+
record.send("#{body_attribute}=", content)
|
31
|
+
record.save!
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
record.send("#{content_attr}=", content)
|
35
|
-
record.save!
|
36
|
-
end
|
33
|
+
identifier
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
model_class.where.not(key => seen_keys).destroy_all
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.sync_all!
|
43
|
-
models = ActiveRecord::Base.descendants.select do |klass|
|
44
|
-
klass.respond_to?(:filepress_options)
|
36
|
+
model.where.not(key => keys).destroy_all if options[:destroy_stale]
|
45
37
|
end
|
46
|
-
|
47
|
-
models.each { |model| sync!(model) }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
module ModelExt
|
52
|
-
def filepress_model(path: nil, glob: "*.md", key: :slug, content_attribute: :content)
|
53
|
-
class_attribute :filepress_options, instance_accessor: false, default: {}
|
54
|
-
|
55
|
-
self.filepress_options = {
|
56
|
-
path: path || "app/content/#{name.underscore.pluralize}",
|
57
|
-
glob: glob,
|
58
|
-
key: key,
|
59
|
-
content_attribute: content_attribute
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
ActiveSupport.on_load(:active_record) do
|
66
|
-
extend Filepress::ModelExt
|
67
|
-
end
|
68
|
-
|
69
|
-
if defined?(Rake::Task)
|
70
|
-
namespace :filepress do
|
71
|
-
desc "Sync all filepress-backed models"
|
72
|
-
task sync: :environment do
|
73
|
-
Rails.application.eager_load!
|
74
|
-
Filepress::Syncer.sync_all!
|
75
38
|
end
|
76
39
|
end
|
77
40
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filepress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Dawson
|
8
|
-
bindir:
|
8
|
+
bindir: bin
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
@@ -31,20 +31,21 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
-
|
35
|
-
- LICENSE.txt
|
34
|
+
- MIT-LICENSE
|
36
35
|
- README.md
|
37
36
|
- Rakefile
|
38
37
|
- lib/filepress.rb
|
38
|
+
- lib/filepress/model.rb
|
39
|
+
- lib/filepress/railtie.rb
|
39
40
|
- lib/filepress/version.rb
|
40
|
-
-
|
41
|
+
- lib/tasks/filepress_tasks.rake
|
41
42
|
homepage: https://github.com/carldaws/filepress
|
42
43
|
licenses:
|
43
44
|
- MIT
|
44
45
|
metadata:
|
45
46
|
allowed_push_host: https://rubygems.org
|
46
47
|
homepage_uri: https://github.com/carldaws/filepress
|
47
|
-
source_code_uri: https://github.com/
|
48
|
+
source_code_uri: https://github.com/carldaws/filepress
|
48
49
|
rdoc_options: []
|
49
50
|
require_paths:
|
50
51
|
- lib
|
@@ -52,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
53
|
requirements:
|
53
54
|
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
56
|
+
version: '0'
|
56
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
58
|
requirements:
|
58
59
|
- - ">="
|
data/.rubocop.yml
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2025 Carl Dawson
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/sig/filepress.rbs
DELETED