filepress 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e18ee52d65d384ba64e31f69826907c5768e90530880e519b2e60b08c7b3792
4
+ data.tar.gz: d0120941b4b5808438c7003c8a8fa9652587dd26eee6ee6c4f5d78efe2fd8336
5
+ SHA512:
6
+ metadata.gz: b375a0c1a6335d95df185db9c47d9b69d4366f7dd3176fb66ae0ff21fdd6ad8542019880bf68faf7f935249008991b0794570522eec79dc3c14da878f1f61770
7
+ data.tar.gz: dd4b78d2e56ead2fc7b4c3c9233652c90840c1f1682b6eaf1b51e651e5e2b6ab4d505dfeadd8ba68a43555731c7fecdeb13ceb06b50873490f55b0cad1430b3a
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Filepress
2
+
3
+ **Write content as flat files. Use it anywhere in your Rails app.**
4
+
5
+ Filepress lets you manage content in plain text files with frontmatter โ€” like Markdown, HTML, or anything else โ€” and sync them directly into your ActiveRecord models. It's the simplicity of static files, with the full power of a Rails backend.
6
+
7
+ ---
8
+
9
+ ## โœจ Why use Filepress?
10
+
11
+ - ๐Ÿ“ Write content in any editor โ€” no CMS required
12
+ - ๐Ÿ” Keep content version-controlled with Git
13
+ - โšก Instantly available in your Rails app via ActiveRecord
14
+ - ๐Ÿง  Works with any file type (Markdown, HTML, plain text, etc.)
15
+ - ๐Ÿงน Automatically adds, updates, and deletes records
16
+
17
+ ---
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Filepress
4
+ VERSION = "0.1.0"
5
+ end
data/lib/filepress.rb ADDED
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+ require "active_support/concern"
6
+
7
+ require_relative "filepress/version"
8
+
9
+ module Filepress
10
+ class Syncer
11
+ def self.sync!(model_class)
12
+ opts = model_class.filepress_options
13
+ raise "Missing Filepress Options" unless opts
14
+
15
+ path = Rails.root.join(opts[:path])
16
+ key = opts[:key]
17
+ content_attr = opts[:content_attribute]
18
+
19
+ seen_keys = []
20
+
21
+ Dir.glob("#{path}/#{opts[:glob]}").each do |file|
22
+ raw = File.read(file)
23
+ frontmatter, body = raw.split(/^---\s*$/, 3).reject(&:empty?)
24
+ data = YAML.safe_load(frontmatter, symbolize_names: true)
25
+ content = body.strip
26
+
27
+ identifier = data[key]
28
+ raise "Missing key `#{key}` in frontmatter for #{file}" unless identifier
29
+
30
+ seen_keys << identifier
31
+
32
+ record = model_class.find_or_initialize_by(key => identifier)
33
+ record.assign_attributes(data)
34
+ record.send("#{content_attr}=", content)
35
+ record.save!
36
+ end
37
+
38
+ # Clean up records whose source file no longer exists
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)
45
+ 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
+ end
76
+ end
77
+ end
data/sig/filepress.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Filepress
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filepress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carl Dawson
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '5.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '5.2'
26
+ description: Filepress lets you manage content as simple flat files, with all the
27
+ power of ActiveRecord.
28
+ email:
29
+ - email@carldaws.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/filepress.rb
39
+ - lib/filepress/version.rb
40
+ - sig/filepress.rbs
41
+ homepage: https://github.com/carldaws/filepress
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ allowed_push_host: https://rubygems.org
46
+ homepage_uri: https://github.com/carldaws/filepress
47
+ source_code_uri: https://github.com/carldawson/filepress
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.1.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.6.7
63
+ specification_version: 4
64
+ summary: Write content as flat files, use it anywhere in your Rails app.
65
+ test_files: []