contentfs 0.0.0 → 0.3.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/CHANGELOG.md +40 -0
- data/lib/contentfs/content.rb +9 -6
- data/lib/contentfs/database.rb +55 -27
- data/lib/contentfs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5386e4d1a1ef23527ec457ecb544d4d36d02e44811fe81f87db93f4188d82145
|
4
|
+
data.tar.gz: f44614daf6d97aabd4d83a0e2339dd8d20e19d742b8b8403c37fc2967dd40925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39ee593b9c158d2093d5a8bc59a8d8510adb8a206d4b786a0465347e79f12323806765be999be8ad7fd14bccb4e32134696c1f851fa466a1a515d3b44d7ecc63
|
7
|
+
data.tar.gz: f1ab2b7a9cc994b5d91cef392fa8d4a4c1bedaac69428ceb9552143b7f969391ec32a16ae1240c66da616a80440945bfae9f8a30e010bcd47f2f36f7aa89e3ef
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
## v0.3.0
|
2
|
+
|
3
|
+
*unreleased*
|
4
|
+
|
5
|
+
* `chg` [#8](https://github.com/metabahn/contentfs/pull/8) Load database content from _content to avoid collisions ([bryanp](https://github.com/bryanp))
|
6
|
+
|
7
|
+
## v0.2.1
|
8
|
+
|
9
|
+
*unreleased*
|
10
|
+
|
11
|
+
* `fix` [#7](https://github.com/metabahn/contentfs/pull/7) Order content and databases by prefix or slug ([bryanp](https://github.com/bryanp))
|
12
|
+
|
13
|
+
## [v0.2.0](https://github.com/metabahn/contentfs/releases/tag/v0.2.0)
|
14
|
+
|
15
|
+
*released on 2020-11-14*
|
16
|
+
|
17
|
+
* `add` [#6](https://github.com/metabahn/contentfs/pull/6) Expose database metadata ([bryanp](https://github.com/bryanp))
|
18
|
+
|
19
|
+
## [v0.1.1](https://github.com/metabahn/contentfs/releases/tag/v0.1.1)
|
20
|
+
|
21
|
+
*released on 2020-11-13*
|
22
|
+
|
23
|
+
* `fix` [#5](https://github.com/metabahn/contentfs/pull/5) Remove front-matter from content ([bryanp](https://github.com/bryanp))
|
24
|
+
|
25
|
+
## [v0.1.0](https://github.com/metabahn/contentfs/releases/tag/v0.1.0)
|
26
|
+
|
27
|
+
*released on 2020-11-12*
|
28
|
+
|
29
|
+
* `add` [#4](https://github.com/metabahn/contentfs/pull/4) Expose namespaces for databases and content ([bryanp](https://github.com/bryanp))
|
30
|
+
* `add` [#3](https://github.com/metabahn/contentfs/pull/3) Introduce `Database#nested` for iterating over databases ([bryanp](https://github.com/bryanp))
|
31
|
+
* `chg` [#2](https://github.com/metabahn/contentfs/pull/2) Rename `Database#all` to `Database#content` ([bryanp](https://github.com/bryanp))
|
32
|
+
* `add` [#1](https://github.com/metabahn/contentfs/pull/1) Introduce `Database#find` for safer traversal ([bryanp](https://github.com/bryanp))
|
33
|
+
|
34
|
+
## [v0.0.0](https://github.com/metabahn/contentfs/releases/tag/v0.0.0)
|
35
|
+
|
36
|
+
*released on 2020-11-11*
|
37
|
+
|
38
|
+
* Initial release.
|
39
|
+
|
40
|
+
|
data/lib/contentfs/content.rb
CHANGED
@@ -12,16 +12,16 @@ module ContentFS
|
|
12
12
|
#
|
13
13
|
class Content
|
14
14
|
class << self
|
15
|
-
def load(path, metadata: {})
|
16
|
-
new(path: path, metadata: metadata)
|
15
|
+
def load(path, metadata: {}, namespace: [])
|
16
|
+
new(path: path, metadata: metadata, namespace: namespace)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
FRONT_MATTER_REGEXP = /\A---\s*\n(.*?\n?)^---\s*$\n?/m
|
21
21
|
|
22
|
-
attr_reader :format, :prefix, :slug, :metadata
|
22
|
+
attr_reader :format, :prefix, :slug, :metadata, :namespace
|
23
23
|
|
24
|
-
def initialize(path:, metadata: {})
|
24
|
+
def initialize(path:, metadata: {}, namespace: [])
|
25
25
|
path = Pathname.new(path)
|
26
26
|
extname = path.extname
|
27
27
|
name = path.basename(extname)
|
@@ -29,8 +29,11 @@ module ContentFS
|
|
29
29
|
@prefix = prefix
|
30
30
|
@format = extname.to_s[1..-1]&.to_sym
|
31
31
|
@slug = Slug.build(remainder)
|
32
|
-
@
|
33
|
-
|
32
|
+
@namespace = namespace.dup << @slug
|
33
|
+
|
34
|
+
content = path.read
|
35
|
+
@metadata = metadata.merge(parse_metadata(content))
|
36
|
+
@content = content.gsub(FRONT_MATTER_REGEXP, "")
|
34
37
|
end
|
35
38
|
|
36
39
|
def to_s
|
data/lib/contentfs/database.rb
CHANGED
@@ -11,58 +11,84 @@ module ContentFS
|
|
11
11
|
#
|
12
12
|
class Database
|
13
13
|
class << self
|
14
|
-
def load(path)
|
15
|
-
new(path: path)
|
14
|
+
def load(path, namespace: [], root: true)
|
15
|
+
new(path: path, namespace: namespace, root: root)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
METADATA_FILE = "_metadata.yml"
|
20
20
|
|
21
|
-
attr_reader :prefix, :slug
|
21
|
+
attr_reader :prefix, :slug, :namespace, :metadata
|
22
22
|
|
23
|
-
def initialize(path:)
|
23
|
+
def initialize(path:, namespace: [], root: false)
|
24
24
|
path = Pathname.new(path)
|
25
25
|
name = path.basename(path.extname)
|
26
26
|
prefix, remainder = Prefix.build(name)
|
27
27
|
@prefix = prefix
|
28
|
-
@
|
29
|
-
|
30
|
-
|
28
|
+
@namespace = namespace.dup
|
29
|
+
|
30
|
+
unless root
|
31
|
+
@slug = Slug.build(remainder)
|
32
|
+
@namespace << @slug
|
33
|
+
end
|
31
34
|
|
32
35
|
metadata_path = path.join(METADATA_FILE)
|
33
36
|
|
34
|
-
metadata = if metadata_path.exist?
|
37
|
+
@metadata = if metadata_path.exist?
|
35
38
|
YAML.safe_load(metadata_path.read).to_h
|
36
39
|
else
|
37
40
|
{}
|
38
41
|
end
|
39
42
|
|
43
|
+
content_path = path.join.glob("_content.*")[0]
|
44
|
+
|
45
|
+
@content = if content_path&.exist?
|
46
|
+
Content.load(content_path, metadata: @metadata, namespace: @namespace)
|
47
|
+
end
|
48
|
+
|
49
|
+
children, nested = {}, {}
|
40
50
|
Pathname.new(path).glob("*") do |path|
|
41
51
|
next if path.basename.to_s.start_with?("_")
|
42
52
|
|
43
53
|
if path.directory?
|
44
|
-
database = Database.load(path)
|
45
|
-
|
54
|
+
database = Database.load(path, namespace: @namespace, root: false)
|
55
|
+
nested[database.slug] = database
|
46
56
|
else
|
47
|
-
content = Content.load(path, metadata: metadata)
|
57
|
+
content = Content.load(path, metadata: @metadata, namespace: @namespace)
|
48
58
|
|
49
|
-
|
50
|
-
@content = content
|
51
|
-
else
|
52
|
-
@children[content.slug] = content
|
53
|
-
end
|
59
|
+
children[content.slug] = content
|
54
60
|
end
|
55
61
|
end
|
62
|
+
|
63
|
+
@children = Hash[
|
64
|
+
children.sort_by { |key, content|
|
65
|
+
(content.prefix || content.slug).to_s
|
66
|
+
}
|
67
|
+
]
|
68
|
+
|
69
|
+
@nested = Hash[
|
70
|
+
nested.sort_by { |key, database|
|
71
|
+
(database.prefix || database.slug).to_s
|
72
|
+
}
|
73
|
+
]
|
56
74
|
end
|
57
75
|
|
58
|
-
def
|
59
|
-
return to_enum(:
|
76
|
+
def content
|
77
|
+
return to_enum(:content) unless block_given?
|
60
78
|
|
61
79
|
@children.each_value do |value|
|
62
80
|
yield value
|
63
81
|
end
|
64
82
|
end
|
65
83
|
|
84
|
+
def nested
|
85
|
+
return to_enum(:nested) unless block_given?
|
86
|
+
|
87
|
+
@nested.each_value do |value|
|
88
|
+
yield value
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
66
92
|
def filter(**filters)
|
67
93
|
return to_enum(:filter, **filters) unless block_given?
|
68
94
|
|
@@ -77,6 +103,16 @@ module ContentFS
|
|
77
103
|
}
|
78
104
|
end
|
79
105
|
|
106
|
+
def find(name, *nested)
|
107
|
+
if @children.key?(name)
|
108
|
+
@children[name]
|
109
|
+
elsif @nested.key?(name)
|
110
|
+
nested.inject(@nested[name]) { |database, next_nested|
|
111
|
+
database.find(next_nested.to_sym)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
80
116
|
def to_s
|
81
117
|
@content&.to_s.to_s
|
82
118
|
end
|
@@ -86,15 +122,7 @@ module ContentFS
|
|
86
122
|
end
|
87
123
|
|
88
124
|
def method_missing(name, *nested, **)
|
89
|
-
|
90
|
-
@children[name]
|
91
|
-
elsif @nested.key?(name)
|
92
|
-
nested.inject(@nested[name]) { |database, next_nested|
|
93
|
-
database.public_send(next_nested.to_sym)
|
94
|
-
}
|
95
|
-
else
|
96
|
-
super
|
97
|
-
end
|
125
|
+
find(name, *nested) || super
|
98
126
|
end
|
99
127
|
|
100
128
|
def respond_to_missing?(name, *)
|
data/lib/contentfs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A structured content file system.
|
14
14
|
email: bryan@metabahn.com
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- CHANGELOG.md
|
19
20
|
- LICENSE
|
20
21
|
- README.md
|
21
22
|
- lib/contentfs.rb
|