contentfs 0.4.0 → 0.6.2
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 +2 -27
- data/lib/contentfs/renderers/markdown/code.rb +19 -5
- data/lib/contentfs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44c0630662c386eee30711ce48061817fecc4d20b619d524b2496811472062a4
|
4
|
+
data.tar.gz: b605d224de8a8662cedfa5df0404206b6f5b05d66616954d1e781a1c0845dec6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6fe40b8bbb1b4f05cd85b4bca5d5535b2cbe73886e679153e02a510a62d3bbe113ac5caa8b8c41b3f77b9c2331b2ff8f2b615a8aae507119394b9cdae3bb232
|
7
|
+
data.tar.gz: 50fe653eb6e89011b9ce39021c04e67c26e7037043b536c9776d03f7fc1212621b93a3663785c01e06897346f7d09a67e67ef2fdd9bb043e734fca723e08cc1a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
## [v0.6.2](https://github.com/metabahn/contentfs/releases/tag/v0.6.2)
|
2
|
+
|
3
|
+
*released on 2021-04-05*
|
4
|
+
|
5
|
+
* `fix` [#14](https://github.com/metabahn/contentfs/pull/14) Load metadata for root content ([bryanp](https://github.com/bryanp))
|
6
|
+
|
7
|
+
## [v0.6.1](https://github.com/metabahn/contentfs/releases/tag/v0.6.1)
|
8
|
+
|
9
|
+
*released on 2021-04-02*
|
10
|
+
|
11
|
+
* `fix` [#13](https://github.com/metabahn/contentfs/pull/13) Resolve includes after rendering ([bryanp](https://github.com/bryanp))
|
12
|
+
|
13
|
+
## [v0.6.0](https://github.com/metabahn/contentfs/releases/tag/v0.6.0)
|
14
|
+
|
15
|
+
*released on 2021-04-02*
|
16
|
+
|
17
|
+
* `add` [#12](https://github.com/metabahn/contentfs/pull/12) Provide a pattern for preprocessing content ([bryanp](https://github.com/bryanp))
|
18
|
+
|
19
|
+
## [v0.5.1](https://github.com/metabahn/contentfs/releases/tag/v0.5.1)
|
20
|
+
|
21
|
+
*released on 2021-04-02*
|
22
|
+
|
23
|
+
* `fix` [#11](https://github.com/metabahn/contentfs/pull/11) Handle code blocks with no available lexer ([bryanp](https://github.com/bryanp))
|
24
|
+
|
25
|
+
## [v0.5.0](https://github.com/metabahn/contentfs/releases/tag/v0.5.0)
|
26
|
+
|
27
|
+
*released on 2021-04-01*
|
28
|
+
|
29
|
+
* `chg` [#10](https://github.com/metabahn/contentfs/pull/10) Replace redcarpet with cmark ([bryanp](https://github.com/bryanp))
|
30
|
+
|
1
31
|
## [v0.4.0](https://github.com/metabahn/contentfs/releases/tag/v0.4.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
|
@@ -1,39 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "commonmarker"
|
4
4
|
|
5
5
|
module ContentFS
|
6
6
|
module Renderers
|
7
7
|
# @api private
|
8
8
|
class Markdown
|
9
9
|
class << self
|
10
|
-
OPTIONS = {
|
11
|
-
autolink: true,
|
12
|
-
footnotes: true,
|
13
|
-
fenced_code_blocks: true,
|
14
|
-
tables: true
|
15
|
-
}.freeze
|
16
|
-
|
17
10
|
def render(content)
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def options
|
22
|
-
OPTIONS
|
23
|
-
end
|
24
|
-
|
25
|
-
private def renderer
|
26
|
-
@_renderer ||= Redcarpet::Markdown.new(Renderer, options)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Renderer < Redcarpet::Render::HTML
|
31
|
-
def block_quote(quote)
|
32
|
-
if (match = quote.match(/<p>\[(.*)\]/))
|
33
|
-
%(<blockquote class="#{match[1]}">#{quote.gsub("[#{match[1]}]", "")}</blockquote>)
|
34
|
-
else
|
35
|
-
super
|
36
|
-
end
|
11
|
+
CommonMarker.render_html(content, [:DEFAULT, :UNSAFE])
|
37
12
|
end
|
38
13
|
end
|
39
14
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rouge"
|
4
|
-
require "rouge/plugins/redcarpet"
|
5
4
|
|
6
5
|
require_relative "../markdown"
|
7
6
|
|
@@ -12,16 +11,31 @@ module ContentFS
|
|
12
11
|
class Code
|
13
12
|
class << self
|
14
13
|
def render(content)
|
15
|
-
renderer.render(content)
|
14
|
+
renderer.render(CommonMarker.render_doc(content))
|
16
15
|
end
|
17
16
|
|
18
17
|
private def renderer
|
19
|
-
|
18
|
+
SyntaxRenderer.new(options: [:DEFAULT, :UNSAFE])
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
class
|
24
|
-
|
22
|
+
class SyntaxRenderer < CommonMarker::HtmlRenderer
|
23
|
+
def code_block(node)
|
24
|
+
block do
|
25
|
+
language = node.fence_info.split(/\s+/)[0]
|
26
|
+
out("<div class=\"highlight\"><pre class=\"highlight #{language}\"><code>")
|
27
|
+
out(syntax_highlight(node.string_content, language))
|
28
|
+
out('</code></pre></div>')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private def syntax_highlight(source, language)
|
33
|
+
if (lexer = Rouge::Lexer.find(language))
|
34
|
+
Rouge::Formatters::HTML.new.format(lexer.lex(source))
|
35
|
+
else
|
36
|
+
source
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
27
41
|
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.6.2
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A structured content file system.
|
14
14
|
email: bryan@metabahn.com
|