yarrow 0.8.5 → 0.8.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33fcaf7b1d66e43c0bd0a83967d0cc8b4891b96ec652bbfd28e5e91e7991b7e2
4
- data.tar.gz: ccf4513eee11929864f76386e22adf39224a1898f5b207a3cefb11a30a5ed6e7
3
+ metadata.gz: 89667b38c1ebf2da983a381e20be9d8e0904bdb69137bb86a1bce6ee9507fbf1
4
+ data.tar.gz: 364c196cefad90398b10c387edb925b055490163be854b814f3522a6333234ef
5
5
  SHA512:
6
- metadata.gz: 20272c169c2dd1280c06b80277a981217ae08c77c80892b4c8d07bac0564099ea0cbc248d54ac3160522e7e38c7dbe129aa703e6cb9e9cb848619f2009e15273
7
- data.tar.gz: 143a1bbb91909f1e8921b9b587f611293b2f20de9f50d66b18a7346c00e6ebc2078d98ac0e9abcb88cad258e2f3a2d902f1f2eda811d27abd0348ece8f7cf87e
6
+ metadata.gz: 113ce8dc745ec3e83121d5229beeed755671a7902e1330373ef7b129d7138048d090bbdb1abedd2458f0faca3f86f4433c30a855cc6a53119ba59576699f7002
7
+ data.tar.gz: 6b24b087284b3be6f2d55a8aa3afc25d0e3cc38dbbb2bd80bd9005487b9b95b3bf65d218a47c65b6ac9f4fd54e830a01984292bc1f0c4c8d1455b7af3a5b5049
@@ -10,7 +10,7 @@ jobs:
10
10
  fail-fast: false
11
11
  matrix:
12
12
  os: [ubuntu-latest, macos-latest]
13
- ruby: [2.7, '3.0', 3.1, head]
13
+ ruby: [2.7, 3.1, 3.2]
14
14
  runs-on: ${{ matrix.os }}
15
15
  steps:
16
16
  - uses: actions/checkout@v2
@@ -6,6 +6,22 @@ module Mementus
6
6
  # Monkeypatch extension to ensure each pipeline step supports enumerable
7
7
  # methods. Mostly used for #map. API needs to be fixed in the gem itself.
8
8
  include Enumerable
9
+
10
+ def to
11
+ Step.new(map { |edge| edge.to }, Pipe.new(graph), graph)
12
+ end
13
+
14
+ def props
15
+ Step.new(map { |node| node.props }, Pipe.new(graph), graph)
16
+ end
17
+
18
+ # def props
19
+ # node_props = source.inject([]) do |result, node|
20
+ # result.concat(node.props)
21
+ # end
22
+
23
+ # Step.new(node_props, Pipe.new(graph), graph)
24
+ # end
9
25
  end
10
26
  end
11
27
  module Structure
data/lib/yarrow/config.rb CHANGED
@@ -43,9 +43,19 @@ module Yarrow
43
43
  # Yarrow::Schema.define do
44
44
  # type :config_source_map, Yarrow::Schema::Types::Instance.of(Hash).accept(Symbol)
45
45
  # end
46
+ # class PolicySpec < Yarrow::Schema::Entity[:__config_policy_spec]
47
+ # attribute :module, :string
48
+ # attribute :source_map, :__config_source_map
49
+ # end
50
+
51
+ # Yarrow::Schema::Definitions.register(
52
+ # :__config_source_map,
53
+ # Yarrow::Schema::Types::Map.of(Symbol)
54
+ # )
46
55
 
47
56
  class Content < Yarrow::Schema::Entity[:__config_content]
48
57
  attribute :module, :string
58
+ #attribute :source_map, :__config_source_map
49
59
  attribute :source_map, :hash
50
60
  end
51
61
 
@@ -5,6 +5,7 @@ module Yarrow
5
5
  def expand(policy)
6
6
  #p graph.n(:root).out(:directory).to_a.count
7
7
  #policy.match()
8
+ p policy
8
9
 
9
10
  #p graph.n(:root).out(:directory).first.props[:name]
10
11
  type = policy.container
@@ -2,6 +2,8 @@ module Yarrow
2
2
  module Content
3
3
  class Model
4
4
  def initialize(content_config)
5
+ p content_config
6
+
5
7
  @policies = {}
6
8
  content_config.source_map.each_entry do |policy_label, policy_spec|
7
9
  @policies[policy_label] = Policy.from_spec(
@@ -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.5"
4
+ VERSION = "0.8.7"
5
5
  end
@@ -1,20 +1,15 @@
1
- module Yarrow
1
+ module Yarrow
2
2
  module Web
3
- class Document
4
- # This class is somewhat verbose for simplicity and long-term maintainability
5
- # (having a clear and easy to follow construction, rather than doing anything
6
- # too clever which has burned this lib in the past).
7
- def initialize(item, parent, is_index)
8
- @item = item
9
- @resource = item.props[:resource]
10
- @parent = parent
11
- @is_index = is_index
12
- end
13
-
3
+ class BaseDocument
14
4
  def resource
15
5
  @resource
16
6
  end
17
7
 
8
+ def type
9
+ @type
10
+ end
11
+
12
+ # TODO: confirm this can be deleted
18
13
  def index
19
14
  _index = @item.out_e(:index)
20
15
  unless _index.first.nil?
@@ -24,16 +19,19 @@ module Yarrow
24
19
  end
25
20
  end
26
21
 
22
+ # TODO: confirm this can be deleted
27
23
  def index_body
28
24
  @item.props[:index_body]
29
25
  end
30
26
 
31
27
  # TODO: manage behaviour with and without current item
32
28
  # TODO: link to manifest
29
+ #
30
+ # TODO: replace @item and @collection with @node internally and in class interface
33
31
  def breadcrumbs
34
32
  path = []
35
33
 
36
- current_parent = @item.in(:collection)
34
+ current_parent = @node.in(:collection)
37
35
 
38
36
  while !current_parent.first.nil?
39
37
  path << current_parent.first.props[:resource]
@@ -51,10 +49,6 @@ module Yarrow
51
49
  @resource.title
52
50
  end
53
51
 
54
- def type
55
- @item.props[:type]
56
- end
57
-
58
52
  def body
59
53
  return @resource.body.to_html if @resource.respond_to?(:body)
60
54
  ""
@@ -78,5 +72,54 @@ module Yarrow
78
72
  end
79
73
  end
80
74
  end
75
+
76
+ class IndexDocument < BaseDocument
77
+ # Represents the index document of a collection. This contains
78
+ # a reference to the individual items in the collection as well as
79
+ # any document content itself.
80
+ def initialize(collection, item=nil, is_index=false)
81
+ @collection = collection
82
+ @item = item
83
+ # The parent node of the collection is the first incoming node link
84
+ @parent = collection.in(:collection).first
85
+ @is_index = is_index
86
+
87
+ template_map = collection.out_e(:child).to.all.inject([]) do |result, node|
88
+ result << Document.new(node, false)
89
+ end
90
+
91
+ instance_variable_set("@children", template_map)
92
+ define_singleton_method(:children){ template_map }
93
+
94
+ if @item.nil?
95
+ @resource = collection.props[:resource]
96
+ @type = collection.props[:type]
97
+ @node = collection
98
+ else
99
+ @resource = item.props[:resource]
100
+ @type = item.props[:type]
101
+ @node = item
102
+ end
103
+
104
+ instance_variable_set("@#{@type}", @resource)
105
+ define_singleton_method(@type){ @resource }
106
+ end
107
+ end
108
+
109
+ class Document < BaseDocument
110
+ # This class is somewhat verbose for simplicity and long-term maintainability
111
+ # (having a clear and easy to follow construction, rather than doing anything
112
+ # too clever which has burned this lib in the past).
113
+ def initialize(item, is_index)
114
+ @item = item
115
+ @type = item.props[:type]
116
+ @parent = item.in(:collection).first
117
+ @node = item
118
+ @is_index = is_index
119
+ @resource = item.props[:resource]
120
+ instance_variable_set("@#{item.props[:type]}", @resource)
121
+ define_singleton_method(item.props[:type]){ @resource }
122
+ end
123
+ end
81
124
  end
82
125
  end
@@ -50,15 +50,15 @@ module Yarrow
50
50
  end
51
51
 
52
52
  def self.collection_context(collection)
53
- Document.new(collection, collection.in(:collection).first, true)
53
+ IndexDocument.new(collection, nil, true)
54
54
  end
55
55
 
56
56
  def self.collection_index_context(collection, item)
57
- Document.new(item, collection.in(:collection).first, false)
57
+ IndexDocument.new(collection, item, false)
58
58
  end
59
59
 
60
60
  def self.item_context(item)
61
- Document.new(item, item.in(:collection).first, false)
61
+ Document.new(item, false)
62
62
  end
63
63
  end
64
64
  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.5
4
+ version: 0.8.7
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-05 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable