contentfs 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +1 -1
- data/lib/contentfs/content.rb +15 -10
- data/lib/contentfs/database.rb +9 -8
- data/lib/contentfs/renderers/markdown.rb +31 -1
- data/lib/contentfs/renderers/markdown/code.rb +7 -3
- data/lib/contentfs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d306cf3d13ffb780150e9666fa6693854dbc890661f394347bbea65ae70729f0
|
4
|
+
data.tar.gz: 5c01ca933b98c6cdbb1d402796fcefc738a5557e5967ee2cf9ca802972a5d809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f2196a1436b9057ccb50a69bcd38bffa40c9d171e846bb6aa5bda478cb26a9677cfc294f8ea5543b6169673173040ea12603bbc06aa74af354350f9c613bad9
|
7
|
+
data.tar.gz: 2b4e549b0481a2da7fb093de521532f2e32865fdf7a275915c7ff46f8571f3b897b6449bce4de6e549999594d7286cacba73008b41e4186ee4a6ed547426f57a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
## [v0.7.0](https://github.com/metabahn/contentfs/releases/tag/v0.7.0)
|
2
|
+
|
3
|
+
*released on 2021-04-07*
|
4
|
+
|
5
|
+
* `add` [#15](https://github.com/metabahn/contentfs/pull/15) Add support for typed blockquotes ([bryanp](https://github.com/bryanp))
|
6
|
+
|
7
|
+
## [v0.6.2](https://github.com/metabahn/contentfs/releases/tag/v0.6.2)
|
8
|
+
|
9
|
+
*released on 2021-04-05*
|
10
|
+
|
11
|
+
* `fix` [#14](https://github.com/metabahn/contentfs/pull/14) Load metadata for root content ([bryanp](https://github.com/bryanp))
|
12
|
+
|
13
|
+
## [v0.6.1](https://github.com/metabahn/contentfs/releases/tag/v0.6.1)
|
14
|
+
|
15
|
+
*released on 2021-04-02*
|
16
|
+
|
17
|
+
* `fix` [#13](https://github.com/metabahn/contentfs/pull/13) Resolve includes after rendering ([bryanp](https://github.com/bryanp))
|
18
|
+
|
19
|
+
## [v0.6.0](https://github.com/metabahn/contentfs/releases/tag/v0.6.0)
|
20
|
+
|
21
|
+
*released on 2021-04-02*
|
22
|
+
|
23
|
+
* `add` [#12](https://github.com/metabahn/contentfs/pull/12) Provide a pattern for preprocessing content ([bryanp](https://github.com/bryanp))
|
24
|
+
|
25
|
+
## [v0.5.1](https://github.com/metabahn/contentfs/releases/tag/v0.5.1)
|
26
|
+
|
27
|
+
*released on 2021-04-02*
|
28
|
+
|
29
|
+
* `fix` [#11](https://github.com/metabahn/contentfs/pull/11) Handle code blocks with no available lexer ([bryanp](https://github.com/bryanp))
|
30
|
+
|
1
31
|
## [v0.5.0](https://github.com/metabahn/contentfs/releases/tag/v0.5.0)
|
2
32
|
|
3
33
|
*released on 2021-04-01*
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ The `content` name is special in that it defines content for the containing fold
|
|
40
40
|
|
41
41
|
### Formats
|
42
42
|
|
43
|
-
Markdown is supported by default. Simply add the `
|
43
|
+
Markdown is supported by default. Simply add the `commonmarker` gem to your project's `Gemfile`. For automatic syntax highlighting, add the `rouge` to your `Gemfile` as well.
|
44
44
|
|
45
45
|
Unknown formats default to plain text.
|
46
46
|
|
data/lib/contentfs/content.rb
CHANGED
@@ -12,8 +12,8 @@ module ContentFS
|
|
12
12
|
#
|
13
13
|
class Content
|
14
14
|
class << self
|
15
|
-
def load(path, database:, metadata: {}, namespace: [])
|
16
|
-
new(path: path, database: database, metadata: metadata, namespace: namespace)
|
15
|
+
def load(path, database:, metadata: {}, namespace: [], &block)
|
16
|
+
new(path: path, database: database, metadata: metadata, namespace: namespace, &block)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,7 @@ module ContentFS
|
|
22
22
|
|
23
23
|
attr_reader :format, :prefix, :slug, :metadata, :namespace
|
24
24
|
|
25
|
-
def initialize(path:, database:, metadata: {}, namespace: [])
|
25
|
+
def initialize(path:, database:, metadata: {}, namespace: [], &block)
|
26
26
|
path = Pathname.new(path)
|
27
27
|
extname = path.extname
|
28
28
|
name = path.basename(extname)
|
@@ -34,6 +34,7 @@ module ContentFS
|
|
34
34
|
@database = database
|
35
35
|
|
36
36
|
content = path.read
|
37
|
+
content = block.call(content) if block
|
37
38
|
@metadata = metadata.merge(parse_metadata(content))
|
38
39
|
@content = content.gsub(FRONT_MATTER_REGEXP, "")
|
39
40
|
end
|
@@ -43,19 +44,23 @@ module ContentFS
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def render
|
46
|
-
|
47
|
+
if @format && (renderer = Renderers.resolve(@format))
|
48
|
+
resolve_includes(renderer.render(@content))
|
49
|
+
else
|
50
|
+
resolve_includes(to_s)
|
51
|
+
end
|
52
|
+
end
|
47
53
|
|
48
|
-
|
54
|
+
private def resolve_includes(content)
|
55
|
+
working_content = content.dup
|
56
|
+
|
57
|
+
content.scan(INCLUDE_REGEXP) do |match|
|
49
58
|
if (include = @database.find_include(match[0]))
|
50
59
|
working_content.gsub!($~.to_s, include.render)
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
54
|
-
|
55
|
-
renderer.render(working_content)
|
56
|
-
else
|
57
|
-
to_s
|
58
|
-
end
|
63
|
+
working_content
|
59
64
|
end
|
60
65
|
|
61
66
|
private def parse_metadata(content)
|
data/lib/contentfs/database.rb
CHANGED
@@ -11,8 +11,8 @@ module ContentFS
|
|
11
11
|
#
|
12
12
|
class Database
|
13
13
|
class << self
|
14
|
-
def load(path, parent: nil, namespace: [], root: true)
|
15
|
-
new(path: path, parent: parent, namespace: namespace, root: root)
|
14
|
+
def load(path, parent: nil, namespace: [], root: true, &block)
|
15
|
+
new(path: path, parent: parent, namespace: namespace, root: root, &block)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module ContentFS
|
|
20
20
|
|
21
21
|
attr_reader :prefix, :slug, :namespace, :metadata
|
22
22
|
|
23
|
-
def initialize(path:, parent: nil, namespace: [], root: false)
|
23
|
+
def initialize(path:, parent: nil, namespace: [], root: false, &block)
|
24
24
|
path = Pathname.new(path)
|
25
25
|
name = path.basename(path.extname)
|
26
26
|
prefix, remainder = Prefix.build(name)
|
@@ -43,8 +43,9 @@ module ContentFS
|
|
43
43
|
|
44
44
|
content_path = path.join.glob("_content.*")[0]
|
45
45
|
|
46
|
-
|
47
|
-
Content.load(content_path, database: self, metadata: @metadata, namespace: @namespace)
|
46
|
+
if content_path&.exist?
|
47
|
+
@content = Content.load(content_path, database: self, metadata: @metadata, namespace: @namespace, &block)
|
48
|
+
@metadata = @content.metadata.dup
|
48
49
|
end
|
49
50
|
|
50
51
|
children, nested, includes = {}, {}, {}
|
@@ -53,14 +54,14 @@ module ContentFS
|
|
53
54
|
next if underscored && path.directory?
|
54
55
|
|
55
56
|
if path.directory?
|
56
|
-
database = Database.load(path, parent: self, namespace: @namespace, root: false)
|
57
|
+
database = Database.load(path, parent: self, namespace: @namespace, root: false, &block)
|
57
58
|
nested[database.slug] = database
|
58
59
|
elsif underscored
|
59
|
-
content = Content.load(path, database: self, metadata: @metadata, namespace: @namespace)
|
60
|
+
content = Content.load(path, database: self, metadata: @metadata, namespace: @namespace, &block)
|
60
61
|
|
61
62
|
includes[content.slug.to_s[1..].to_sym] = content
|
62
63
|
else
|
63
|
-
content = Content.load(path, database: self, metadata: @metadata, namespace: @namespace)
|
64
|
+
content = Content.load(path, database: self, metadata: @metadata, namespace: @namespace, &block)
|
64
65
|
|
65
66
|
children[content.slug] = content
|
66
67
|
end
|
@@ -8,7 +8,37 @@ module ContentFS
|
|
8
8
|
class Markdown
|
9
9
|
class << self
|
10
10
|
def render(content)
|
11
|
-
CommonMarker.
|
11
|
+
renderer.render(CommonMarker.render_doc(content))
|
12
|
+
end
|
13
|
+
|
14
|
+
private def renderer
|
15
|
+
ContentFSRenderer.new(options: [:DEFAULT, :UNSAFE])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ContentFSRenderer < CommonMarker::HtmlRenderer
|
20
|
+
def blockquote(node)
|
21
|
+
blockquote_type = if (match = node.to_plaintext.strip.match(/\[(.*)\]/))
|
22
|
+
match[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
blockquote_class = if blockquote_type
|
26
|
+
" class=\"#{blockquote_type}\""
|
27
|
+
end
|
28
|
+
|
29
|
+
block do
|
30
|
+
container("<blockquote#{sourcepos(node)}#{blockquote_class}>\n", "</blockquote>") do
|
31
|
+
node.each.with_index do |child, index|
|
32
|
+
content = if blockquote_class && index == 0
|
33
|
+
child.to_html.gsub("<p>[#{blockquote_type}] ", "<p>")
|
34
|
+
else
|
35
|
+
child
|
36
|
+
end
|
37
|
+
|
38
|
+
out(content)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
12
42
|
end
|
13
43
|
end
|
14
44
|
end
|
@@ -19,18 +19,22 @@ module ContentFS
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class SyntaxRenderer <
|
22
|
+
class SyntaxRenderer < ContentFSRenderer
|
23
23
|
def code_block(node)
|
24
24
|
block do
|
25
25
|
language = node.fence_info.split(/\s+/)[0]
|
26
26
|
out("<div class=\"highlight\"><pre class=\"highlight #{language}\"><code>")
|
27
27
|
out(syntax_highlight(node.string_content, language))
|
28
|
-
out(
|
28
|
+
out("</code></pre></div>")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
private def syntax_highlight(source, language)
|
33
|
-
|
33
|
+
if (lexer = Rouge::Lexer.find(language))
|
34
|
+
Rouge::Formatters::HTML.new.format(lexer.lex(source))
|
35
|
+
else
|
36
|
+
source
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
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.7.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: 2021-04-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A structured content file system.
|
14
14
|
email: bryan@metabahn.com
|
@@ -40,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 2.
|
43
|
+
version: 2.6.7
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|