yarrow 0.8.6 → 0.9.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CONTENT.md +228 -0
  4. data/README.md +8 -8
  5. data/lib/extensions/mementus.rb +29 -0
  6. data/lib/yarrow/config.rb +10 -0
  7. data/lib/yarrow/content/expansion/aggregator.rb +88 -0
  8. data/lib/yarrow/content/expansion/basename_merge.rb +44 -0
  9. data/lib/yarrow/content/expansion/directory_map.rb +21 -0
  10. data/lib/yarrow/content/expansion/directory_merge.rb +31 -0
  11. data/lib/yarrow/content/expansion/file_list.rb +15 -0
  12. data/lib/yarrow/content/expansion/filename_map.rb +24 -0
  13. data/lib/yarrow/content/expansion/strategy.rb +47 -0
  14. data/lib/yarrow/content/expansion/traversal.rb +67 -0
  15. data/lib/yarrow/content/expansion/tree.rb +53 -73
  16. data/lib/yarrow/content/model.rb +3 -2
  17. data/lib/yarrow/content/policy.rb +77 -21
  18. data/lib/yarrow/content/source.rb +4 -0
  19. data/lib/yarrow/format/asciidoc.rb +0 -0
  20. data/lib/yarrow/format/html.rb +0 -0
  21. data/lib/yarrow/format/json.rb +0 -0
  22. data/lib/yarrow/format/markdown.rb +67 -0
  23. data/lib/yarrow/format/mediawiki.rb +0 -0
  24. data/lib/yarrow/format/methods/front_matter.rb +58 -0
  25. data/lib/yarrow/format/methods/metadata.rb +22 -0
  26. data/lib/yarrow/format/orgmode.rb +0 -0
  27. data/lib/yarrow/format/text.rb +0 -0
  28. data/lib/yarrow/format/xml.rb +0 -0
  29. data/lib/yarrow/format/yaml.rb +19 -0
  30. data/lib/yarrow/format.rb +71 -0
  31. data/lib/yarrow/schema/types.rb +41 -0
  32. data/lib/yarrow/version.rb +1 -1
  33. data/lib/yarrow/web/manifest.rb +15 -9
  34. data/lib/yarrow.rb +6 -9
  35. data/yarrow.gemspec +1 -0
  36. metadata +22 -3
  37. data/lib/yarrow/tools/content_utils.rb +0 -74
@@ -17,6 +17,10 @@ module Yarrow
17
17
  def self.respond_to_all(t, m)
18
18
  new("#{t} does not implement #{m}")
19
19
  end
20
+
21
+ def self.union_member(t, s)
22
+ new("#{t} is not a member of union")
23
+ end
20
24
  end
21
25
 
22
26
  class TypeClass
@@ -31,6 +35,10 @@ module Yarrow
31
35
  @accepts = {}
32
36
  end
33
37
 
38
+ def |(rhs_opt)
39
+ Union.new(self, rhs_opt)
40
+ end
41
+
34
42
  def accept(type, constructor=:new, options=nil)
35
43
  accepts[type] = if options.nil?
36
44
  [constructor]
@@ -201,6 +209,39 @@ module Yarrow
201
209
  [keys, values].transpose.to_h
202
210
  end
203
211
  end
212
+
213
+ class Union < TypeClass
214
+ def self.of(*unit_opts)
215
+ instances = unit_opts.map { |unit| Instance.of(unit) }
216
+ new(*instances)
217
+ end
218
+
219
+ def initialize(*type_opts)
220
+ @options = type_opts
221
+ super()
222
+ end
223
+
224
+ def |(rhs_opt)
225
+ @options << rhs_opt
226
+ end
227
+
228
+ def check(input)
229
+ failed_checks = []
230
+ @options.each do |opt|
231
+ begin
232
+ opt.check(input)
233
+ rescue CastError => err
234
+ failed_checks << err
235
+ end
236
+ end
237
+
238
+ if failed_checks.size == @options.size
239
+ raise CastError.union_member(input.class, @options.map { |opt| opt.class })
240
+ end
241
+
242
+ input
243
+ end
244
+ end
204
245
  end
205
246
  end
206
247
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = "Yarrow"
4
- VERSION = "0.8.6"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -3,6 +3,7 @@ module Yarrow
3
3
  class Manifest
4
4
  def self.build(graph)
5
5
  manifest = new
6
+ manifest.set_graph(graph)
6
7
 
7
8
  graph.n(:collection).each do |collection|
8
9
  # TODO: raise error if both content_only and index_only are set
@@ -10,12 +11,12 @@ module Yarrow
10
11
 
11
12
  # If the collection is tagged :index_only then skip adding individual documents
12
13
  unless collection.props[:index_only]
13
- collection.out(:item).each do |item|
14
+ collection.out(:entity).each do |entity|
14
15
  #if item[:entity].status.to_sym == :published
15
- if item.props[:resource].name == "index"
16
- index = item
16
+ if entity.props[:resource].name == "index"
17
+ index = entity
17
18
  else
18
- manifest.add_document(item_context(item))
19
+ manifest.add_document(entity_context(entity))
19
20
  end
20
21
  #end
21
22
  end
@@ -34,13 +35,18 @@ module Yarrow
34
35
  manifest
35
36
  end
36
37
 
37
- attr_reader :documents, :assets
38
+ attr_reader :documents, :assets, :graph
38
39
 
39
40
  def initialize
40
41
  @documents = []
41
42
  @assets = []
42
43
  end
43
44
 
45
+ # Used for dot debugging
46
+ def set_graph(graph)
47
+ @graph = graph
48
+ end
49
+
44
50
  def add_document(document)
45
51
  @documents << document
46
52
  end
@@ -53,12 +59,12 @@ module Yarrow
53
59
  IndexDocument.new(collection, nil, true)
54
60
  end
55
61
 
56
- def self.collection_index_context(collection, item)
57
- IndexDocument.new(collection, item, false)
62
+ def self.collection_index_context(collection, entity)
63
+ IndexDocument.new(collection, entity, false)
58
64
  end
59
65
 
60
- def self.item_context(item)
61
- Document.new(item, false)
66
+ def self.entity_context(entity)
67
+ Document.new(entity, false)
62
68
  end
63
69
  end
64
70
  end
data/lib/yarrow.rb CHANGED
@@ -15,14 +15,16 @@ require "yarrow/schema/dictionary"
15
15
  require "yarrow/schema/entity"
16
16
  require "yarrow/schema/value"
17
17
  require "yarrow/schema/registry"
18
- require "yarrow/tools/front_matter"
19
- require "yarrow/tools/content_utils"
18
+ require "yarrow/format"
20
19
  require "yarrow/content/graph"
21
20
  require "yarrow/content/policy"
22
21
  require "yarrow/content/model"
23
22
  require "yarrow/content/source"
24
- require "yarrow/content/expansion/strategy"
25
- require "yarrow/content/expansion/tree"
23
+ require "yarrow/content/expansion/aggregator"
24
+ require "yarrow/content/expansion/basename_merge"
25
+ require "yarrow/content/expansion/filename_map"
26
+ require "yarrow/content/expansion/directory_merge"
27
+ require "yarrow/content/expansion/traversal"
26
28
  require "yarrow/content/resource"
27
29
  require "yarrow/web/manifest"
28
30
  require "yarrow/web/document"
@@ -41,9 +43,4 @@ require "yarrow/process/project_manifest"
41
43
  require "yarrow/config"
42
44
  require "yarrow/configuration"
43
45
  require "yarrow/console_runner"
44
-
45
46
  require "yarrow/generator"
46
-
47
- # Dir[File.dirname(__FILE__) + "/yarrow/generators/*.rb"].each do |generator|
48
- # require generator
49
- # end
data/yarrow.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency 'parallel', '~> 1.22.1'
25
25
  spec.add_runtime_dependency 'strings-inflection', '~> 0.1'
26
26
  spec.add_runtime_dependency 'strings-case', '~> 0.3'
27
+ # https://github.com/joeldrapper/phlex
27
28
  spec.add_runtime_dependency 'kramdown', '~> 2.4.0'
28
29
  spec.add_development_dependency 'rake', '~> 13.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.11'
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.8.6
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -245,6 +245,7 @@ extra_rdoc_files: []
245
245
  files:
246
246
  - ".github/workflows/ruby.yml"
247
247
  - ".gitignore"
248
+ - CONTENT.md
248
249
  - Gemfile
249
250
  - LICENSE
250
251
  - README.md
@@ -260,7 +261,14 @@ files:
260
261
  - lib/yarrow/config.rb
261
262
  - lib/yarrow/configuration.rb
262
263
  - lib/yarrow/console_runner.rb
264
+ - lib/yarrow/content/expansion/aggregator.rb
265
+ - lib/yarrow/content/expansion/basename_merge.rb
266
+ - lib/yarrow/content/expansion/directory_map.rb
267
+ - lib/yarrow/content/expansion/directory_merge.rb
268
+ - lib/yarrow/content/expansion/file_list.rb
269
+ - lib/yarrow/content/expansion/filename_map.rb
263
270
  - lib/yarrow/content/expansion/strategy.rb
271
+ - lib/yarrow/content/expansion/traversal.rb
264
272
  - lib/yarrow/content/expansion/tree.rb
265
273
  - lib/yarrow/content/graph.rb
266
274
  - lib/yarrow/content/model.rb
@@ -269,6 +277,18 @@ files:
269
277
  - lib/yarrow/content/source.rb
270
278
  - lib/yarrow/content_map.rb
271
279
  - lib/yarrow/defaults.yml
280
+ - lib/yarrow/format.rb
281
+ - lib/yarrow/format/asciidoc.rb
282
+ - lib/yarrow/format/html.rb
283
+ - lib/yarrow/format/json.rb
284
+ - lib/yarrow/format/markdown.rb
285
+ - lib/yarrow/format/mediawiki.rb
286
+ - lib/yarrow/format/methods/front_matter.rb
287
+ - lib/yarrow/format/methods/metadata.rb
288
+ - lib/yarrow/format/orgmode.rb
289
+ - lib/yarrow/format/text.rb
290
+ - lib/yarrow/format/xml.rb
291
+ - lib/yarrow/format/yaml.rb
272
292
  - lib/yarrow/generator.rb
273
293
  - lib/yarrow/help.txt
274
294
  - lib/yarrow/logging.rb
@@ -292,7 +312,6 @@ files:
292
312
  - lib/yarrow/server/livereload.rb
293
313
  - lib/yarrow/source/graph.rb
294
314
  - lib/yarrow/symbols.rb
295
- - lib/yarrow/tools/content_utils.rb
296
315
  - lib/yarrow/tools/front_matter.rb
297
316
  - lib/yarrow/version.rb
298
317
  - lib/yarrow/web/document.rb
@@ -1,74 +0,0 @@
1
- module Yarrow
2
- module Tools
3
- # Synchronous utility functions for working with filesystem content tasks.
4
- module ContentUtils
5
- # Pass in a source path and get back a parsed representation of the
6
- # content if it is in a known text format. Mostly used as a fallback if
7
- # a custom parser or processing chain is not configured for a content
8
- # type.
9
- #
10
- # Supported formats:
11
- # - HTML template and document partials
12
- # - Markdown documents
13
- # - YAML documents
14
- # - JSON (untested)
15
- #
16
- # Works around meta and content source in multiple files or a single
17
- # file with front matter.
18
- def read_yfm(name)
19
- path = if name.is_a?(Pathname)
20
- name
21
- else
22
- Pathname.new(name)
23
- end
24
-
25
- text = File.read(path, :encoding => 'utf-8')
26
-
27
- case path.extname
28
- when '.htm', '.md', '.txt', '.yfm'
29
- extract_yfm(text, symbolize_keys: true)
30
- # when '.md'
31
- # body, data = read_split_content(path.to_s, symbolize_keys: true)
32
- # [Kramdown::Document.new(body).to_html, data]
33
- when '.yml'
34
- [nil, YAML.load(File.read(path.to_s), symbolize_names: true)]
35
- when '.json'
36
- [nil, JSON.parse(File.read(path.to_s))]
37
- end
38
- end
39
-
40
- def extract_yfm(text, options={})
41
- pattern = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
42
- if text =~ pattern
43
- content = text.sub(pattern, "")
44
-
45
- begin
46
- if options.key?(:symbolize_keys)
47
- meta = YAML.load($1, symbolize_names: true)
48
- else
49
- meta = YAML.load($1)
50
- end
51
- return [content, meta]
52
- rescue Psych::SyntaxError => error
53
- if defined? ::Logger
54
- # todo: application wide logger
55
- #logger = ::Logger.new(STDOUT)
56
- #logger.error "#{error.message}"
57
- end
58
- return [content, nil]
59
- end
60
- end
61
-
62
- [text, nil]
63
- end
64
-
65
- def write_yfm(name, text, meta)
66
- # Symbolized keys are better to deal with when manipulating data in
67
- # Ruby but are an interop nightmare when serialized so here we do a
68
- # round-trip through JSON encoding to ensure all keys are string
69
- # encoded before dumping them to the front matter format.
70
- File.write(name, [YAML.dump(meta.to_json), "---", text].join("\n"))
71
- end
72
- end
73
- end
74
- end