yarrow 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c362ba73bcbfc325bad91668bf1a1a006dd6355579a36ce96cc60323944804b
4
- data.tar.gz: 51db819b1f52b3b75a9b39287359e22dfb6d52833ce0089636694f4d9feeda15
3
+ metadata.gz: d26941f2b464c551d825b73999b0365637b9e4feec159ee74de51a1abca3416e
4
+ data.tar.gz: 34081172c945cf83e97ab3ee03484436ba380de6c809c2dd87caaa50f1bba315
5
5
  SHA512:
6
- metadata.gz: c7a41bb6ee0a6bcfd27c83d7780cc70f7b41131daaa4decd02e591346f9270318951b1a68d0f390ac81843593e0bf97a8062da51f3f7f1e2be78b6711af132d6
7
- data.tar.gz: 866d6683eb25f9154d9582266b45016b680d622fca57a71c88b55f8c0ee41dc76076e839684026df8759e72ba73cf2597b96cbe05b83d3c877cc5ebcf6252bcf
6
+ metadata.gz: 6300e2c0f83c741862cf6c49acc42118636a3832401706057b483d942c07a947ea1124b2c10e056cc5052e25a28a59f896216d0156911026639d16e0faa5ba73
7
+ data.tar.gz: 0b897183df8712cbc08d0a479ed1e1d129a90305ad76f9bc802ea262707026ff5ffa57890d0d26d49955f55721ffd0887510671c86430e4780564266758ebaed
data/lib/yarrow/config.rb CHANGED
@@ -37,17 +37,22 @@ module Yarrow
37
37
  :port,
38
38
  :host,
39
39
  :handler,
40
- #:docroot,
41
- :middleware,
42
- #:root_dir
40
+ :middleware
43
41
  )
44
42
 
43
+ class Output < Yarrow::Schema::Entity[:output]
44
+ attribute :generator, :string
45
+ attribute :template_dir, :path
46
+ #attribute :scripts, :array
47
+ end
48
+
45
49
  # Top level root config namespace.
46
50
  class Instance < Yarrow::Schema::Entity
47
51
  attribute :source_dir, :path
48
52
  attribute :output_dir, :path
49
53
  attribute :meta, :any
50
54
  attribute :server, :any
55
+ #attribute :output, :output
51
56
  end
52
57
  #
53
58
  # `content_dir` and `output_dir` are placeholders and should be overriden
@@ -8,6 +8,8 @@ module Yarrow
8
8
  :match_path
9
9
  )
10
10
 
11
+ DEFAULT_HOME_NESTING = false
12
+
11
13
  DEFAULT_EXTENSIONS = [".md", ".yml", ".htm"]
12
14
 
13
15
  DEFAULT_MATCH_PATH = "."
@@ -6,11 +6,6 @@ module Yarrow
6
6
  #policy.match()
7
7
 
8
8
  #p graph.n(:root).out(:directory).first.props[:name]
9
-
10
- expand_impl(policy)
11
- end
12
-
13
- def expand_impl(policy)
14
9
  type = policy.container
15
10
 
16
11
  # If match path represents entire content dir, then include the entire
@@ -18,13 +13,14 @@ module Yarrow
18
13
  # the collection.
19
14
  #start_node = if policy.match_path == "."
20
15
  start_node = if true
21
- graph.n(:root)
16
+ # TODO: match against source_dir
17
+ graph.n(:root).out(:directory)
22
18
  else
23
- graph.n(:root).out(name: type.to_s)
19
+ graph.n(:root).out(name: policy.container.to_s)
24
20
  end
25
21
 
26
22
  # Extract metadata from given start node
27
- collection_metadata = extract_metadata(start_node, type)
23
+ collection_metadata = extract_metadata(start_node, policy.container)
28
24
 
29
25
  # Collect all nested collections in the subgraph for this content type
30
26
  subcollections = {}
@@ -37,7 +33,7 @@ module Yarrow
37
33
  # Create a collection node representing a collection of documents
38
34
  index = graph.create_node do |collection_node|
39
35
  collection_node.label = :collection
40
- collection_node.props[:type] = type
36
+ collection_node.props[:type] = policy.container
41
37
  collection_node.props[:name] = node.props[:name]
42
38
 
43
39
  # TODO: title needs to be defined from metadata
@@ -6,10 +6,8 @@ meta:
6
6
  title: Default Project
7
7
  author: Default Name
8
8
  output:
9
- target_dir: public
9
+ generator: web
10
10
  template_dir: templates
11
- object_map:
12
- page: Yarrow::Model::Site.pages
13
11
  assets:
14
12
  input_dir: assets
15
13
  output_dir: public/assets
@@ -4,9 +4,16 @@ module Yarrow
4
4
  DEFINED_TYPES = {
5
5
  string: Types::Instance.of(String),
6
6
  integer: Types::Instance.of(Integer),
7
- symbol: Types::Instance.of(Symbol),
7
+ symbol: Types::Instance.of(Symbol).accept(String, :to_sym),
8
8
  path: Types::Instance.of(Pathname).accept(String),
9
- any: Types::Any.new
9
+ any: Types::Any.new,
10
+ array: Types::List.of(Types::Any),
11
+ hash: Types::Map.of(Symbol => Types::Any)
12
+ }
13
+
14
+ TEMPLATE_TYPES = {
15
+ list: Types::List,
16
+ map: Types::Map
10
17
  }
11
18
 
12
19
  def self.register(identifier, type_class)
@@ -18,13 +25,43 @@ module Yarrow
18
25
  end
19
26
 
20
27
  def resolve_type(identifier)
21
- #return identifier unless identifier.is_a?(Symbol)
28
+ # Type is directly resolvable from the definition table
29
+ return DEFINED_TYPES[identifier] if DEFINED_TYPES.key?(identifier)
22
30
 
23
- unless DEFINED_TYPES.key?(identifier)
24
- raise "#{identifier} is not defined"
25
- end
31
+ if identifier.is_a?(Hash)
32
+ # If type identifier is a compound template extract its key and value mapping
33
+ key_id = identifier.keys.first
34
+ value_id = identifier.values.first
26
35
 
27
- return DEFINED_TYPES[identifier]
36
+ # Check if the given key is defined as a template type
37
+ unless TEMPLATE_TYPES.key?(key_id)
38
+ raise "compound type #{key_id} is not defined"
39
+ end
40
+
41
+ # Get reference to the type class we want to resolve
42
+ template_type = TEMPLATE_TYPES[key_id]
43
+
44
+ # Resolve the type to an instance depending on structure of its template args
45
+ resolved_type = if value_id.is_a?(Hash)
46
+ # Map template with two argument constructor
47
+ template_type.new(
48
+ resolve_type(value_id.keys.first),
49
+ resolve_type(value_id.values.first)
50
+ )
51
+ else
52
+ # Use the single arg constructor with the given unit type
53
+ template_type.of(resolve_type(value_id).unit)
54
+ end
55
+
56
+ # Cache the resolved type for later reference
57
+ DEFINED_TYPES[identifier] = resolved_type
58
+
59
+ # Return the resolve type
60
+ resolved_type
61
+ else
62
+ # Not a compound template so we know it’s missing in the lookup table
63
+ raise "type #{identifier} is not defined"
64
+ end
28
65
  end
29
66
  end
30
67
  end
@@ -13,6 +13,19 @@ module Yarrow
13
13
  def dictionary
14
14
  @dictionary ||= Dictionary.new({})
15
15
  end
16
+
17
+ def [](label)
18
+ @label = label
19
+ self
20
+ end
21
+
22
+ def inherited(class_name)
23
+ if @label
24
+ class_type = Yarrow::Schema::Types::Instance.of(class_name)
25
+ Yarrow::Schema::Definitions.register(@label, class_type)
26
+ @label = nil
27
+ end
28
+ end
16
29
  end
17
30
 
18
31
  def initialize(config)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Yarrow
3
3
  APP_NAME = "Yarrow"
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
5
5
  end
@@ -4,10 +4,10 @@ module Yarrow
4
4
  # This class is somewhat verbose for simplicity and long-term maintainability
5
5
  # (having a clear and easy to follow construction, rather than doing anything
6
6
  # too clever which has burned this lib in the past).
7
- def initialize(item, parent, url_strategy)
7
+ def initialize(item, parent, is_index)
8
8
  @item = item
9
9
  @parent = parent
10
- @url_strategy = url_strategy
10
+ @is_index = is_index
11
11
  end
12
12
 
13
13
  def name
@@ -23,13 +23,18 @@ module Yarrow
23
23
  end
24
24
 
25
25
  def url
26
- case @url_strategy
27
- when :mirror_source
28
- unless @parent.nil?
29
- "/#{@parent.props[:name]}/#{name}"
30
- else
31
- "/#{name}/"
26
+ if @parent.nil?
27
+ "/"
28
+ else
29
+ segments = [@item.props[:name]]
30
+ current = @parent
31
+
32
+ until current.in(:collection).first.nil? do
33
+ segments << current.props[:name]
34
+ current = current.in(:collection).first
32
35
  end
36
+
37
+ "/" + segments.reverse.join("/")
33
38
  end
34
39
  end
35
40
  end
@@ -6,20 +6,29 @@ module Yarrow
6
6
 
7
7
  graph.n(:collection).each do |collection|
8
8
  # TODO: raise error if both content_only and index_only are set
9
-
10
- # If the collection is tagged :content_only then skip top level listing/index
11
- unless collection.props[:content_only]
12
- manifest.add_document(collection_context(collection))
13
- end
9
+ index = nil
14
10
 
15
11
  # If the collection is tagged :index_only then skip adding individual documents
16
12
  unless collection.props[:index_only]
17
13
  collection.out(:item).each do |item|
18
14
  #if item[:entity].status.to_sym == :published
19
- manifest.add_document(item_context(item))
15
+ if item.props[:name] == "index"
16
+ index = item
17
+ else
18
+ manifest.add_document(item_context(item))
19
+ end
20
20
  #end
21
21
  end
22
22
  end
23
+
24
+ # If the collection is tagged :content_only then skip top level listing/index
25
+ unless collection.props[:content_only]
26
+ if index
27
+ manifest.add_document(collection_index_context(collection, index))
28
+ else
29
+ manifest.add_document(collection_context(collection))
30
+ end
31
+ end
23
32
  end
24
33
 
25
34
  manifest
@@ -32,28 +41,6 @@ module Yarrow
32
41
  @assets = []
33
42
  end
34
43
 
35
- def self.collection_context(collection)
36
- # Yarrow::Output::Context.new(
37
- # parent: collection.in(:collection).first,
38
- # name: collection.props[:name],
39
- # #url: collection.props[:url],
40
- # title: collection.props[:title],
41
- # type: collection.props[:type]
42
- # )
43
- Document.new(collection, collection.in(:collection).first, :mirror_source)
44
- end
45
-
46
- def self.item_context(item)
47
- # Yarrow::Output::Context.new(
48
- # parent: item.in(:collection).first,
49
- # name: item.props[:name],
50
- # #url: item.props[:url],
51
- # title: item.props[:title],
52
- # type: item.props[:type]
53
- # )
54
- Document.new(item, item.in(:collection).first, :mirror_source)
55
- end
56
-
57
44
  def add_document(document)
58
45
  @documents << document
59
46
  end
@@ -61,6 +48,18 @@ module Yarrow
61
48
  def add_asset(asset)
62
49
  @assets << asset
63
50
  end
51
+
52
+ def self.collection_context(collection)
53
+ Document.new(collection, collection.in(:collection).first, true)
54
+ end
55
+
56
+ def self.collection_index_context(collection, item)
57
+ Document.new(item, collection.in(:collection).first, false)
58
+ end
59
+
60
+ def self.item_context(item)
61
+ Document.new(item, item.in(:collection).first, false)
62
+ end
64
63
  end
65
64
  end
66
65
  end
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.0
4
+ version: 0.8.1
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-11-01 00:00:00.000000000 Z
11
+ date: 2022-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable