filepress 0.1.0 → 0.2.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 +4 -4
- data/MIT-LICENSE +20 -0
- 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 +7 -6
- 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: e03605fd0950c7f477b42f3c7e0a1945fb36beb2e36712d07b3f3afea0589174
|
4
|
+
data.tar.gz: bb918105f4fcfd3e0c69c0c989a6be41894e364f86243f42ec609f251548cf66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 340b5ac2730761c80eb9c7168ba034df36c99035cb9fce1dc6ced9fab58535c81983c49386141e03c824765f0962810249e75abb485df445aedf288aad8038fd
|
7
|
+
data.tar.gz: 80ed126ff2e59a217d061f88f183d7ea2fde0d5f352547061f0b30dbf5c325862534ef8b0e995367fd19ee2694c83c2ad4b7df75dac53aa6111a2b767c53ce5c
|
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/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.
|
4
|
+
version: 0.2.0
|
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,13 +31,14 @@ 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
|
@@ -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