yarrow 0.6.4 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/lib/yarrow/config.rb +7 -4
- data/lib/yarrow/configuration.rb +7 -4
- data/lib/yarrow/console_runner.rb +21 -24
- data/lib/yarrow/content/collection_expander.rb +66 -43
- data/lib/yarrow/content/expansion.rb +51 -0
- data/lib/yarrow/content/graph.rb +15 -2
- data/lib/yarrow/content/manifest.rb +61 -0
- data/lib/yarrow/content/{content_type.rb → object_type.rb} +1 -1
- data/lib/yarrow/content/source_collector.rb +38 -15
- data/lib/yarrow/content/tree_expansion.rb +83 -0
- data/lib/yarrow/defaults.yml +1 -1
- data/lib/yarrow/generator.rb +49 -19
- data/lib/yarrow/output/result.rb +13 -0
- data/lib/yarrow/output/web/indexed_file.rb +7 -1
- data/lib/yarrow/server.rb +44 -3
- data/lib/yarrow/version.rb +1 -1
- data/lib/yarrow.rb +7 -3
- data/yarrow.gemspec +2 -2
- metadata +16 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395db81bd349ed8e1a6b5cdc67d0fd191f6ede369bd358483611e0b79fb27cec
|
4
|
+
data.tar.gz: '028961b86756cfc6bc1453c6d3ad7789149e8921066fb5429358e1b3b08393eb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f531ff89949b7d1b80e215529f2c6c29d812f958e9af4491d58b7a0f10f9419a9ee26385ac58891cc435053fff31123d2dcfed0e02c8dcd48927d0b47c312f9f
|
7
|
+
data.tar.gz: 8a5bb918411a04ac7d5e8b3c649501346e94d3cc76c17097ec9eed436685b163a04294b40491b38f0ea8539a28722bc8e77043bdab81aec493e04d5ccc0b6e0e
|
data/.github/workflows/ruby.yml
CHANGED
data/lib/yarrow/config.rb
CHANGED
@@ -37,20 +37,23 @@ module Yarrow
|
|
37
37
|
:port,
|
38
38
|
:host,
|
39
39
|
:handler,
|
40
|
+
:docroot,
|
40
41
|
:middleware,
|
41
42
|
:root_dir
|
42
43
|
)
|
43
44
|
|
44
|
-
# Top level root config namespace.
|
45
|
-
#
|
45
|
+
# Top level root config namespace.
|
46
|
+
#
|
47
|
+
# `content_dir` and `output_dir` are placeholders and should be overriden
|
48
|
+
# with more fine-grained config for web and book outputs in future.
|
46
49
|
#
|
47
50
|
# Additional server config is optional and only needed if running the dev
|
48
51
|
# server locally.
|
49
52
|
#
|
50
53
|
# TODO: meta should be union of Type::Optional and Config::Meta
|
51
54
|
Instance = Yarrow::Schema::Value.new(
|
52
|
-
|
53
|
-
|
55
|
+
project_dir: Pathname,
|
56
|
+
content_dir: Pathname,
|
54
57
|
output_dir: Pathname,
|
55
58
|
meta: Yarrow::Schema::Type::Any,
|
56
59
|
server: Yarrow::Schema::Type::Any
|
data/lib/yarrow/configuration.rb
CHANGED
@@ -52,13 +52,13 @@ module Yarrow
|
|
52
52
|
# automated as part of the schema types or a default value should be
|
53
53
|
# generated here (eg: `"#{Dir.pwd}/docs"`)
|
54
54
|
out_dir_or_string = config[:output_dir] || ""
|
55
|
-
source_dir_or_string = config[:
|
56
|
-
content_dir_or_string = config[:
|
55
|
+
source_dir_or_string = config[:project_dir] || ""
|
56
|
+
content_dir_or_string = config[:content_dir] || ""
|
57
57
|
|
58
58
|
Yarrow::Config::Instance.new(
|
59
59
|
output_dir: Pathname.new(File.expand_path(out_dir_or_string)),
|
60
|
-
|
61
|
-
|
60
|
+
project_dir: Pathname.new(File.expand_path(source_dir_or_string)),
|
61
|
+
content_dir: Pathname.new(File.expand_path(content_dir_or_string)),
|
62
62
|
meta: meta_obj,
|
63
63
|
server: server_obj
|
64
64
|
)
|
@@ -69,5 +69,8 @@ module Yarrow
|
|
69
69
|
##
|
70
70
|
# Raised when a required config section or property is missing.
|
71
71
|
class ConfigurationError < StandardError
|
72
|
+
def self.missing_section(name)
|
73
|
+
new("Missing config section #{name.to_sym}")
|
74
|
+
end
|
72
75
|
end
|
73
76
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module Yarrow
|
2
|
-
|
3
2
|
class ConsoleRunner
|
4
3
|
|
5
4
|
SUCCESS = 0
|
@@ -31,27 +30,27 @@ module Yarrow
|
|
31
30
|
|
32
31
|
def run_application
|
33
32
|
print_header
|
34
|
-
|
33
|
+
|
35
34
|
begin
|
36
35
|
process_arguments
|
37
|
-
|
36
|
+
|
38
37
|
if has_option?(:version)
|
39
38
|
return SUCCESS
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
if has_option?(:help)
|
43
42
|
print_help
|
44
43
|
return SUCCESS
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
process_configuration
|
48
|
-
|
47
|
+
|
49
48
|
run_input_process
|
50
|
-
|
49
|
+
|
51
50
|
run_output_process
|
52
|
-
|
51
|
+
|
53
52
|
print_footer
|
54
|
-
|
53
|
+
|
55
54
|
SUCCESS
|
56
55
|
rescue Exception => e
|
57
56
|
print_error e
|
@@ -81,26 +80,25 @@ module Yarrow
|
|
81
80
|
|
82
81
|
def process_configuration
|
83
82
|
# load_configuration(Dir.pwd)
|
84
|
-
|
83
|
+
|
85
84
|
# @targets.each do |input_path|
|
86
85
|
# @config.deep_merge! load_configuration(input_path)
|
87
86
|
# end
|
88
|
-
|
87
|
+
|
89
88
|
if has_option?(:config)
|
90
89
|
path = @options[:config]
|
91
90
|
@config.deep_merge! Configuration.load(path)
|
92
91
|
end
|
93
|
-
|
92
|
+
|
94
93
|
@config.options = @options.to_hash
|
95
94
|
|
96
95
|
# normalize_theme_path
|
97
|
-
|
96
|
+
|
98
97
|
# theme = @config.options.theme
|
99
98
|
# @config.append load_configuration(theme)
|
100
99
|
end
|
101
100
|
|
102
101
|
def normalize_theme_path
|
103
|
-
|
104
102
|
# noop
|
105
103
|
end
|
106
104
|
|
@@ -113,9 +111,9 @@ module Yarrow
|
|
113
111
|
else
|
114
112
|
value = true
|
115
113
|
end
|
116
|
-
|
114
|
+
|
117
115
|
name = option.gsub("-", "")
|
118
|
-
|
116
|
+
|
119
117
|
if option[0..1] == "--"
|
120
118
|
if ENABLED_OPTIONS.has_value?(name.to_sym)
|
121
119
|
@options[name.to_sym] = value
|
@@ -127,7 +125,7 @@ module Yarrow
|
|
127
125
|
return
|
128
126
|
end
|
129
127
|
end
|
130
|
-
|
128
|
+
|
131
129
|
raise "Unrecognized option: #{raw_option}"
|
132
130
|
end
|
133
131
|
|
@@ -139,12 +137,11 @@ module Yarrow
|
|
139
137
|
@options.has_key? option
|
140
138
|
end
|
141
139
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
# noop
|
140
|
+
def run_generation_process
|
141
|
+
generator = Generator.new(@config)
|
142
|
+
generator.process do |manifest|
|
143
|
+
p manifest
|
144
|
+
end
|
148
145
|
end
|
149
146
|
|
150
147
|
def print_header
|
@@ -161,7 +158,7 @@ module Yarrow
|
|
161
158
|
|
162
159
|
def print_help
|
163
160
|
help = <<HELP
|
164
|
-
See http://
|
161
|
+
See http://yarrow.maetl.net for more information.
|
165
162
|
|
166
163
|
Usage:
|
167
164
|
|
@@ -3,19 +3,26 @@ module Yarrow
|
|
3
3
|
class CollectionExpander
|
4
4
|
include Yarrow::Tools::FrontMatter
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# If a list of object types is not provided, a default `pages` type is
|
7
|
+
# created.
|
8
|
+
def initialize(object_types=nil)
|
9
|
+
@object_types = object_types || [
|
10
|
+
Yarrow::Content::ObjectType.from_name(:pages)
|
9
11
|
]
|
10
12
|
end
|
11
13
|
|
12
14
|
def expand(graph)
|
13
|
-
@
|
14
|
-
expand_nested(graph,
|
15
|
+
@object_types.each do |object_type|
|
16
|
+
expand_nested(graph, object_type)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def expand_nested(graph, content_type)
|
21
|
+
strategy = TreeExpansion.new(graph)
|
22
|
+
strategy.expand(content_type)
|
23
|
+
end
|
24
|
+
|
25
|
+
def expand_nested_legacy(graph, content_type)
|
19
26
|
type = content_type.collection
|
20
27
|
exts = content_type.extensions
|
21
28
|
|
@@ -87,40 +94,70 @@ module Yarrow
|
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
90
|
-
subcollections
|
91
|
-
|
92
|
-
|
97
|
+
# If there are no subcollections then we need to look at the start node
|
98
|
+
# TODO: test to verify if this could be used in all cases, not just
|
99
|
+
# the situation where there are subfolders to be mapped.
|
100
|
+
if subcollections.empty?
|
101
|
+
# Collect files that match the content type extension and group them
|
102
|
+
# under a common key for each slug (this is so we can merge multiple
|
103
|
+
# files with the same name together into a single content type, a
|
104
|
+
# specific pattern found in some legacy content folders).
|
105
|
+
#
|
106
|
+
# Ideally, this code should be deleted once we have a clean workflow
|
107
|
+
# and can experiment with decoupling different strategies for
|
108
|
+
# expansion/enrichment of content objects.
|
109
|
+
objects = start_node.out(:file).all.select do |file|
|
93
110
|
file.props[:name].end_with?(*exts)
|
94
111
|
end.group_by do |file|
|
95
112
|
file.props[:slug]
|
96
113
|
end
|
97
114
|
|
115
|
+
# This is a massive hack to deal with situations where we don’t
|
116
|
+
# recurse down the list of directories. The best way to clean it up
|
117
|
+
# will be to document the different supported mapping formats and
|
118
|
+
# URL generation strategies and break these up into separate
|
119
|
+
# traversal objects for each particular style of content organisation.
|
120
|
+
if index.nil?
|
121
|
+
index = graph.create_node do |collection_node|
|
122
|
+
collection_node.label = :collection
|
123
|
+
collection_node.props[:type] = type
|
124
|
+
collection_node.props[:name] = type
|
125
|
+
collection_node.props[:slug] = type.to_s
|
126
|
+
collection_node.props[:title] = metadata[:title]
|
127
|
+
|
128
|
+
# Override default status so that mapped index collections always show
|
129
|
+
# up in the resulting document manifest, when they don’t have
|
130
|
+
# associated metadata. This is the opposite of how individual pieces
|
131
|
+
# of content behave (default to draft status if one isn’t supplied).
|
132
|
+
collection_node.props[:status] = if data[:status]
|
133
|
+
data[:status]
|
134
|
+
else
|
135
|
+
"published"
|
136
|
+
end
|
137
|
+
|
138
|
+
# TODO: URL generation might need to happen elsewhere
|
139
|
+
collection_node.props[:url] = if data[:url]
|
140
|
+
data[:url]
|
141
|
+
else
|
142
|
+
"/#{type}/"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
98
147
|
build_content_nodes(graph, objects, type, index)
|
99
148
|
end
|
100
|
-
end
|
101
149
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
# TODO: pass in content converter object
|
111
|
-
# TODO: index/body content by default if extracted from frontmatter
|
112
|
-
body, data = process_content(meta_file.props[:entry])
|
113
|
-
else
|
114
|
-
# Otherwise, assume default collection behaviour
|
115
|
-
data = {}
|
116
|
-
end
|
150
|
+
# Go through each subcollection and expand content nodes step by step.
|
151
|
+
subcollections.each do |path, index|
|
152
|
+
# Group files matching the same slug under a common key
|
153
|
+
objects = graph.n(path: path).out(:file).all.select do |file|
|
154
|
+
file.props[:name].end_with?(*exts)
|
155
|
+
end.group_by do |file|
|
156
|
+
file.props[:slug]
|
157
|
+
end
|
117
158
|
|
118
|
-
|
119
|
-
unless data.key?(:title)
|
120
|
-
data[:title] = type.to_s.capitalize
|
159
|
+
build_content_nodes(graph, objects, type, index)
|
121
160
|
end
|
122
|
-
|
123
|
-
data
|
124
161
|
end
|
125
162
|
|
126
163
|
def build_content_nodes(graph, objects, type, parent_index)
|
@@ -199,20 +236,6 @@ module Yarrow
|
|
199
236
|
end
|
200
237
|
end
|
201
238
|
end
|
202
|
-
|
203
|
-
# Workaround for handling meta and content source in multiple files or a single
|
204
|
-
# file with front matter.
|
205
|
-
def process_content(path)
|
206
|
-
case path.extname
|
207
|
-
when '.htm', '.md'
|
208
|
-
read_split_content(path.to_s, symbolize_keys: true)
|
209
|
-
# when '.md'
|
210
|
-
# body, data = read_split_content(path.to_s, symbolize_keys: true)
|
211
|
-
# [Kramdown::Document.new(body).to_html, data]
|
212
|
-
when '.yml'
|
213
|
-
[nil, YAML.load(File.read(path.to_s), symbolize_names: true)]
|
214
|
-
end
|
215
|
-
end
|
216
239
|
end
|
217
240
|
end
|
218
241
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Yarrow
|
2
|
+
module Content
|
3
|
+
class Expansion
|
4
|
+
include Yarrow::Tools::FrontMatter
|
5
|
+
|
6
|
+
attr_reader :graph
|
7
|
+
|
8
|
+
def initialize(graph)
|
9
|
+
@graph = graph
|
10
|
+
end
|
11
|
+
|
12
|
+
# Extract collection level configuration/metadata from the root node for
|
13
|
+
# this content type.
|
14
|
+
def extract_metadata(node, type)
|
15
|
+
# TODO: support _index or _slug convention as well
|
16
|
+
meta_file = node.out(slug: type.to_s).first
|
17
|
+
|
18
|
+
if meta_file
|
19
|
+
# Process metadata and add it to the collection node
|
20
|
+
# TODO: pass in content converter object
|
21
|
+
# TODO: index/body content by default if extracted from frontmatter
|
22
|
+
body, data = process_content(meta_file.props[:entry])
|
23
|
+
else
|
24
|
+
# Otherwise, assume default collection behaviour
|
25
|
+
data = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Generate a default title if not provided in metadata
|
29
|
+
unless data.key?(:title)
|
30
|
+
data[:title] = type.to_s.capitalize
|
31
|
+
end
|
32
|
+
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
# Workaround for handling meta and content source in multiple files or a single
|
37
|
+
# file with front matter.
|
38
|
+
def process_content(path)
|
39
|
+
case path.extname
|
40
|
+
when '.htm', '.md'
|
41
|
+
read_split_content(path.to_s, symbolize_keys: true)
|
42
|
+
# when '.md'
|
43
|
+
# body, data = read_split_content(path.to_s, symbolize_keys: true)
|
44
|
+
# [Kramdown::Document.new(body).to_html, data]
|
45
|
+
when '.yml'
|
46
|
+
[nil, YAML.load(File.read(path.to_s), symbolize_names: true)]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/yarrow/content/graph.rb
CHANGED
@@ -2,9 +2,12 @@ module Yarrow
|
|
2
2
|
module Content
|
3
3
|
# A directed graph of every element of content in the project.
|
4
4
|
class Graph
|
5
|
-
# Construct a graph collected from
|
5
|
+
# Construct a graph collected from files and directories in the configured
|
6
|
+
# content directory.
|
7
|
+
#
|
8
|
+
# @return [Yarrow::Content::Graph]
|
6
9
|
def self.from_source(config)
|
7
|
-
new(SourceCollector.collect(config.
|
10
|
+
new(SourceCollector.collect(config.content_dir), config)
|
8
11
|
end
|
9
12
|
|
10
13
|
attr_reader :graph, :config
|
@@ -28,6 +31,16 @@ module Yarrow
|
|
28
31
|
def directories
|
29
32
|
graph.nodes(:directory)
|
30
33
|
end
|
34
|
+
|
35
|
+
# List of mapped content object collections
|
36
|
+
def collections
|
37
|
+
graph.nodes(:collection)
|
38
|
+
end
|
39
|
+
|
40
|
+
# List of mapped content object items
|
41
|
+
def items
|
42
|
+
graph.nodes(:item)
|
43
|
+
end
|
31
44
|
end
|
32
45
|
end
|
33
46
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Yarrow
|
2
|
+
module Content
|
3
|
+
class Manifest
|
4
|
+
def self.build(graph)
|
5
|
+
manifest = new
|
6
|
+
|
7
|
+
graph.n(:collection).each do |collection|
|
8
|
+
|
9
|
+
unless collection.props[:content_only]
|
10
|
+
manifest.add_document(collection_context(collection))
|
11
|
+
end
|
12
|
+
|
13
|
+
unless collection.props[:index_only]
|
14
|
+
collection.out(:item).each do |item|
|
15
|
+
#if item[:entity].status.to_sym == :published
|
16
|
+
manifest.add_document(item_context(item))
|
17
|
+
#end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
manifest
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :documents, :resources
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@documents = []
|
29
|
+
@resources = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.collection_context(collection)
|
33
|
+
Yarrow::Output::Context.new(
|
34
|
+
parent: collection.in(:collection).first,
|
35
|
+
name: collection.props[:name],
|
36
|
+
#url: collection.props[:url],
|
37
|
+
title: collection.props[:title],
|
38
|
+
type: collection.props[:type]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.item_context(item)
|
43
|
+
Yarrow::Output::Context.new(
|
44
|
+
parent: item.in(:collection).first,
|
45
|
+
name: item.props[:name],
|
46
|
+
#url: item.props[:url],
|
47
|
+
title: item.props[:title],
|
48
|
+
type: item.props[:type]
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_document(document)
|
53
|
+
@documents << document
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_resource(resource)
|
57
|
+
@resources << resource
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -9,38 +9,61 @@ module Yarrow
|
|
9
9
|
root.label = :root
|
10
10
|
end
|
11
11
|
|
12
|
+
root_dir_entry = Pathname.new(input_dir)
|
13
|
+
|
14
|
+
root_dir = create_node do |dir|
|
15
|
+
dir.label = :directory
|
16
|
+
dir.props = {
|
17
|
+
name: root_dir_entry.basename.to_s,
|
18
|
+
path: root_dir_entry.to_s,
|
19
|
+
entry: root_dir_entry
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
create_edge do |child|
|
24
|
+
child.label = :child
|
25
|
+
child.from = root.id
|
26
|
+
child.to = root_dir.id
|
27
|
+
end
|
28
|
+
|
12
29
|
directories = {
|
13
|
-
|
30
|
+
root_dir_entry.to_s => root_dir.id
|
14
31
|
}
|
15
32
|
|
16
33
|
Pathname.glob("#{input_dir}/**/**").each do |entry|
|
17
34
|
if entry.directory?
|
18
|
-
#puts "Reading directory: #{entry}"
|
19
|
-
|
20
35
|
content_node = create_node do |dir|
|
21
36
|
dir.label = :directory
|
22
|
-
dir.props[:name] = entry.basename.to_s
|
23
|
-
dir.props[:slug] = entry.basename.to_s
|
24
|
-
dir.props[:path] = entry.to_s
|
25
|
-
dir.props[:entry] = entry
|
37
|
+
# dir.props[:name] = entry.basename.to_s
|
38
|
+
# dir.props[:slug] = entry.basename.to_s
|
39
|
+
# dir.props[:path] = entry.to_s
|
40
|
+
# dir.props[:entry] = entry
|
41
|
+
dir.props = {
|
42
|
+
name: entry.basename.to_s,
|
43
|
+
path: entry.to_s,
|
44
|
+
entry: entry
|
45
|
+
}
|
26
46
|
end
|
27
47
|
|
28
48
|
directories[entry.to_s] = content_node.id
|
29
49
|
else
|
30
|
-
#puts "Reading file: #{entry} (#{entry.basename.sub_ext('')})"
|
31
|
-
|
32
50
|
content_node = create_node do |file|
|
33
51
|
file.label = :file
|
34
|
-
file.props[:name] = entry.basename.to_s
|
35
|
-
file.props[:slug] = entry.basename.sub_ext('').to_s
|
36
|
-
file.props[:path] = entry.to_s
|
37
|
-
file.props[:entry] = entry
|
52
|
+
# file.props[:name] = entry.basename.to_s
|
53
|
+
# file.props[:slug] = entry.basename.sub_ext('').to_s
|
54
|
+
# file.props[:path] = entry.to_s
|
55
|
+
# file.props[:entry] = entry
|
56
|
+
|
57
|
+
file.props = {
|
58
|
+
name: entry.basename.to_s,
|
59
|
+
ext: entry.extname.to_s,
|
60
|
+
path: entry.to_s,
|
61
|
+
entry: entry
|
62
|
+
}
|
38
63
|
end
|
39
64
|
end
|
40
65
|
|
41
66
|
if directories.key?(entry.dirname.to_s)
|
42
|
-
#puts "Create parent edge: #{directories[entry.dirname.to_s]}"
|
43
|
-
|
44
67
|
create_edge do |edge|
|
45
68
|
edge.label = :child
|
46
69
|
edge.from = directories[entry.dirname.to_s]
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Yarrow
|
2
|
+
module Content
|
3
|
+
class TreeExpansion < Expansion
|
4
|
+
def expand(content_type)
|
5
|
+
type = content_type.collection
|
6
|
+
exts = content_type.extensions
|
7
|
+
|
8
|
+
# If match path represents entire content dir, then include the entire
|
9
|
+
# content dir instead of scanning from a subfolder matching the name of
|
10
|
+
# the collection.
|
11
|
+
start_node = if content_type.match_path == "."
|
12
|
+
graph.n(:root)
|
13
|
+
else
|
14
|
+
graph.n(:root).out(name: type.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Extract metadata from given start node
|
18
|
+
collection_metadata = extract_metadata(start_node, type)
|
19
|
+
|
20
|
+
# Collect all nested collections in the subgraph for this content type
|
21
|
+
subcollections = {}
|
22
|
+
item_links = []
|
23
|
+
index = nil
|
24
|
+
|
25
|
+
# Scan and collect all nested files from the root
|
26
|
+
start_node.depth_first.each do |node|
|
27
|
+
if node.label == :directory
|
28
|
+
# Create a collection node representing a collection of documents
|
29
|
+
index = graph.create_node do |collection_node|
|
30
|
+
collection_node.label = :collection
|
31
|
+
collection_node.props[:type] = type
|
32
|
+
collection_node.props[:name] = node.props[:name]
|
33
|
+
|
34
|
+
# TODO: title needs to be defined from metadata
|
35
|
+
collection_node.props[:title] = node.props[:name].capitalize
|
36
|
+
end
|
37
|
+
|
38
|
+
# Add this collection id to the lookup table for edge construction
|
39
|
+
subcollections[node.props[:path]] = index
|
40
|
+
|
41
|
+
# Join the collection to its parent
|
42
|
+
unless node.props[:slug] == type.to_s || !subcollections.key?(node.props[:entry].parent.to_s)
|
43
|
+
graph.create_edge do |edge|
|
44
|
+
edge.label = :child
|
45
|
+
edge.from = subcollections[node.props[:entry].parent.to_s].id
|
46
|
+
edge.to = index.id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
elsif node.label == :file
|
50
|
+
body, meta = process_content(node.props[:entry])
|
51
|
+
|
52
|
+
# Create an item node representing a file mapped to a unique content object
|
53
|
+
item = graph.create_node do |item_node|
|
54
|
+
item_node.label = :item
|
55
|
+
item_node.props[:type] = content_type.entity
|
56
|
+
item_node.props[:name] = node.props[:entry].basename(node.props[:entry].extname).to_s
|
57
|
+
item_node.props[:body] = body if body
|
58
|
+
item_node.props[:title] = meta[:title] if meta
|
59
|
+
# TODO: better handling of metadata on node props
|
60
|
+
end
|
61
|
+
|
62
|
+
# We may not have an expanded node for the parent collection if this is a
|
63
|
+
# preorder traversal so save it for later
|
64
|
+
item_links << {
|
65
|
+
parent_path: node.props[:entry].parent.to_s,
|
66
|
+
item_id: item.id
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Once all files and directories have been expanded, connect all the child
|
72
|
+
# edges between collections and items
|
73
|
+
item_links.each do |item_link|
|
74
|
+
graph.create_edge do |edge|
|
75
|
+
edge.label = :child
|
76
|
+
edge.from = subcollections[item_link[:parent_path]].id
|
77
|
+
edge.to = item_link[:item_id]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/yarrow/defaults.yml
CHANGED
data/lib/yarrow/generator.rb
CHANGED
@@ -1,27 +1,57 @@
|
|
1
1
|
module Yarrow
|
2
|
+
class ScanSource < Process::StepProcessor
|
3
|
+
accepts Config::Instance
|
4
|
+
provides Content::Graph
|
5
|
+
|
6
|
+
def step(config)
|
7
|
+
Yarrow::Content::Graph.from_source(config)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ExpandCollections < Process::StepProcessor
|
12
|
+
accepts Content::Graph
|
13
|
+
provides Content::Graph
|
14
|
+
|
15
|
+
def step(content)
|
16
|
+
expander = Content::CollectionExpander.new
|
17
|
+
expander.expand(content.graph)
|
18
|
+
content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FlattenManifest < Process::StepProcessor
|
23
|
+
accepts Content::Graph
|
24
|
+
provides Content::Manifest
|
25
|
+
|
26
|
+
def step(content)
|
27
|
+
Content::Manifest.build(content.graph)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class BuildOutput < Process::StepProcessor
|
32
|
+
accepts Content::Manifest
|
33
|
+
provides Output::Result
|
34
|
+
end
|
2
35
|
|
3
36
|
# Generates documentation from a model.
|
4
|
-
#
|
5
|
-
# Subclasses of Generator need to override the template methods,
|
6
|
-
# to specify a particular file structure to output.
|
7
37
|
class Generator
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@target = target
|
12
|
-
@site_tree = site_tree
|
38
|
+
def initialize(config)
|
39
|
+
@config = config
|
40
|
+
@workflow = Process::Workflow.new(config)
|
13
41
|
end
|
14
|
-
|
15
|
-
def
|
16
|
-
|
17
|
-
|
42
|
+
|
43
|
+
def process(&block)
|
44
|
+
workflow.connect(ScanSource.new)
|
45
|
+
workflow.connect(ExpandCollections.new)
|
46
|
+
workflow.connect(FlattenManifest.new)
|
47
|
+
|
48
|
+
workflow.process do |result|
|
49
|
+
block.call(result)
|
18
50
|
end
|
19
51
|
end
|
20
|
-
|
21
|
-
def build_docs
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
52
|
|
27
|
-
|
53
|
+
private
|
54
|
+
|
55
|
+
attr_reader :config, :workflow
|
56
|
+
end
|
57
|
+
end
|
@@ -27,12 +27,18 @@ module Yarrow
|
|
27
27
|
|
28
28
|
target_path = Pathname.new("#{docroot}#{path}")
|
29
29
|
|
30
|
-
|
30
|
+
ensure_dir_exists!(target_path.dirname)
|
31
31
|
|
32
32
|
File.open(target_path.to_s, WRITE_MODE) do |file|
|
33
33
|
file.puts(content)
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
def ensure_dir_exists!(target)
|
38
|
+
unless File.directory?(target)
|
39
|
+
FileUtils.mkdir_p(target)
|
40
|
+
end
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
data/lib/yarrow/server.rb
CHANGED
@@ -6,9 +6,13 @@ module Yarrow
|
|
6
6
|
class Server
|
7
7
|
attr_reader :config
|
8
8
|
|
9
|
+
def self.default
|
10
|
+
new(Yarrow::Configuration.load_defaults)
|
11
|
+
end
|
12
|
+
|
9
13
|
def initialize(instance_config)
|
10
14
|
if instance_config.server.nil?
|
11
|
-
raise ConfigurationError.
|
15
|
+
raise ConfigurationError.missing_section(:server)
|
12
16
|
end
|
13
17
|
|
14
18
|
@config = instance_config
|
@@ -37,6 +41,38 @@ module Yarrow
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
# Rack Middleware for rewriting extensionless URLs
|
45
|
+
#
|
46
|
+
# See surge.sh rewrite rules, that seems like a good starting point for
|
47
|
+
# generic behaviour that can be put in place without needing large amounts
|
48
|
+
# of config each time.
|
49
|
+
class ResourceRewriter
|
50
|
+
def initialize(app)
|
51
|
+
# No options enabled
|
52
|
+
@app = app
|
53
|
+
end
|
54
|
+
|
55
|
+
def should_try_rewrite(path)
|
56
|
+
!request_path.ends_with(".html") || !request_path.ends_with("/")
|
57
|
+
end
|
58
|
+
|
59
|
+
def call(env)
|
60
|
+
# TODO: document and disambiguate usage of Rack::Request vs env PATH_INFO
|
61
|
+
request_path = env["PATH_INFO"]
|
62
|
+
|
63
|
+
try_response = @app.call(env)
|
64
|
+
|
65
|
+
# TODO: reproduces default Netlify behaviour—should be a 301 instead?
|
66
|
+
if try_response[0] == 404 and should_try_rewrite(request_path)
|
67
|
+
try_response = @app.call(env.merge!({
|
68
|
+
"PATH_INFO" => "#{request_path}.html"
|
69
|
+
}))
|
70
|
+
end
|
71
|
+
|
72
|
+
try_response
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
40
76
|
##
|
41
77
|
# Builds a Rack application to serve files in the output directory.
|
42
78
|
#
|
@@ -54,9 +90,11 @@ module Yarrow
|
|
54
90
|
app.use(middleware)
|
55
91
|
end
|
56
92
|
|
93
|
+
app.use(ResourceRewriter)
|
57
94
|
app.use(DirectoryIndex, root: docroot, index: default_index)
|
58
95
|
|
59
96
|
app_args = [docroot, {}].tap { |args| args.push(default_type) if default_type }
|
97
|
+
|
60
98
|
static_app = Rack::File.new(*app_args)
|
61
99
|
|
62
100
|
if live_reload?
|
@@ -89,7 +127,7 @@ module Yarrow
|
|
89
127
|
|
90
128
|
trap(:INT) do
|
91
129
|
handler.shutdown if handler.respond_to?(:shutdown)
|
92
|
-
reactor.stop
|
130
|
+
reactor.stop if live_reload?
|
93
131
|
end
|
94
132
|
|
95
133
|
handler.run(app, run_options)
|
@@ -97,7 +135,10 @@ module Yarrow
|
|
97
135
|
|
98
136
|
private
|
99
137
|
|
100
|
-
|
138
|
+
# Host directory of the mounted web server.
|
139
|
+
#
|
140
|
+
# Fallback to `config.output_dir`.
|
141
|
+
#
|
101
142
|
# @return [String]
|
102
143
|
def docroot
|
103
144
|
config.output_dir
|
data/lib/yarrow/version.rb
CHANGED
data/lib/yarrow.rb
CHANGED
@@ -9,17 +9,19 @@ require 'yarrow/schema'
|
|
9
9
|
require 'yarrow/config'
|
10
10
|
require 'yarrow/configuration'
|
11
11
|
require 'yarrow/console_runner'
|
12
|
-
require 'yarrow/generator'
|
13
12
|
require 'yarrow/tools/front_matter'
|
14
13
|
require 'yarrow/tools/content_utils'
|
15
14
|
require 'yarrow/content/graph'
|
16
|
-
require 'yarrow/content/
|
17
|
-
require 'yarrow/content/source'
|
15
|
+
require 'yarrow/content/object_type'
|
18
16
|
require 'yarrow/content/source_collector'
|
19
17
|
require 'yarrow/content/collection_expander'
|
18
|
+
require 'yarrow/content/expansion'
|
19
|
+
require 'yarrow/content/tree_expansion'
|
20
|
+
require 'yarrow/content/manifest'
|
20
21
|
require 'yarrow/output/mapper'
|
21
22
|
require 'yarrow/output/generator'
|
22
23
|
require 'yarrow/output/context'
|
24
|
+
require 'yarrow/output/result'
|
23
25
|
require 'yarrow/output/web/indexed_file'
|
24
26
|
require 'yarrow/content_map'
|
25
27
|
require 'yarrow/server'
|
@@ -31,6 +33,8 @@ require 'yarrow/process/expand_content'
|
|
31
33
|
require 'yarrow/process/extract_source'
|
32
34
|
require 'yarrow/process/project_manifest'
|
33
35
|
|
36
|
+
require 'yarrow/generator'
|
37
|
+
|
34
38
|
# Dir[File.dirname(__FILE__) + '/yarrow/generators/*.rb'].each do |generator|
|
35
39
|
# require generator
|
36
40
|
# end
|
data/yarrow.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_runtime_dependency 'em-websocket', '~> 0.5.1'
|
21
21
|
spec.add_runtime_dependency 'strings-inflection', '~> 0.1'
|
22
22
|
spec.add_runtime_dependency 'strings-case', '~> 0.3'
|
23
|
-
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency 'rake', '~> 13.0'
|
25
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.11'
|
26
26
|
spec.add_development_dependency 'coveralls', '~> 0.8.23'
|
27
27
|
spec.add_development_dependency 'rack-test', '~> 0.8'
|
28
28
|
spec.homepage = 'http://rubygemspec.org/gems/yarrow'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yarrow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mementus
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: bundler
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
145
|
+
version: '3.11'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3.
|
152
|
+
version: '3.11'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: coveralls
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,10 +204,13 @@ files:
|
|
204
204
|
- lib/yarrow/configuration.rb
|
205
205
|
- lib/yarrow/console_runner.rb
|
206
206
|
- lib/yarrow/content/collection_expander.rb
|
207
|
-
- lib/yarrow/content/
|
207
|
+
- lib/yarrow/content/expansion.rb
|
208
208
|
- lib/yarrow/content/graph.rb
|
209
|
+
- lib/yarrow/content/manifest.rb
|
210
|
+
- lib/yarrow/content/object_type.rb
|
209
211
|
- lib/yarrow/content/source.rb
|
210
212
|
- lib/yarrow/content/source_collector.rb
|
213
|
+
- lib/yarrow/content/tree_expansion.rb
|
211
214
|
- lib/yarrow/content_map.rb
|
212
215
|
- lib/yarrow/defaults.yml
|
213
216
|
- lib/yarrow/extensions.rb
|
@@ -217,6 +220,7 @@ files:
|
|
217
220
|
- lib/yarrow/output/context.rb
|
218
221
|
- lib/yarrow/output/generator.rb
|
219
222
|
- lib/yarrow/output/mapper.rb
|
223
|
+
- lib/yarrow/output/result.rb
|
220
224
|
- lib/yarrow/output/web/indexed_file.rb
|
221
225
|
- lib/yarrow/process/expand_content.rb
|
222
226
|
- lib/yarrow/process/extract_source.rb
|
@@ -243,7 +247,7 @@ homepage: http://rubygemspec.org/gems/yarrow
|
|
243
247
|
licenses:
|
244
248
|
- MIT
|
245
249
|
metadata: {}
|
246
|
-
post_install_message:
|
250
|
+
post_install_message:
|
247
251
|
rdoc_options: []
|
248
252
|
require_paths:
|
249
253
|
- lib
|
@@ -259,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
263
|
version: '0'
|
260
264
|
requirements: []
|
261
265
|
rubygems_version: 3.1.2
|
262
|
-
signing_key:
|
266
|
+
signing_key:
|
263
267
|
specification_version: 4
|
264
268
|
summary: Documentation generator based on a fluent data model.
|
265
269
|
test_files: []
|